CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

lcd bar graph... it goes also to the left?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bgvsan



Joined: 24 Aug 2008
Posts: 5

View user's profile Send private message

lcd bar graph... it goes also to the left?
PostPosted: Sun Aug 24, 2008 5:45 pm     Reply with quote

I need some help to solve a little problem..
I found this code on this forum..
http://www.ccsinfo.com/forum/viewtopic.php?t=22965
this is great and works!

But now i put the beginning of the bar, in the middle, and goes to the left for ADC value from 0 to 255 and to the right from 256 to 512.

The problem is to put the bar to the left... here is "my" code.
Code:

long value;
int A;
void main() {
   setup_adc_ports(RA0_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   lcd_init();
   delay_us(20);
   init_user_chars();    // loads special characters into LCD CGRAM for bargraph
   set_adc_channel(0);
   delay_us(10);

   while(1)
   {
      value=read_adc(); //read the ADC
      delay_us(50);     //pause so we don't blur the LCD display     
      A=(value/17)*2;       //calculate the full scale for our bar//raddoppiato per tensioni di 5 volts
      lcd_putc('\f');   //clear the LCD
     
      printf(lcd_putc, "value = %lu \n",value); //Print top line with ADC value
     
      if (value<=255){
         lcd_putc(A);
         bargraph_back(A);      //print line 2 with the bargraph output.
      }
      else
         
       
         bargraph(A);  //print line 2 with the bargraph output.
   }
}

How should i create the bargraph_back? Rolling Eyes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 25, 2008 10:11 am     Reply with quote

I think you want to overwrite the area defined for bar with spaces.
This will clear the bar graph.
Then redraw with new value.
bgvsan



Joined: 24 Aug 2008
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 2:03 am     Reply with quote

i've found the solution... at 3.00 A.M. Twisted Evil



Code:
void bargraph_back(BYTE percent) {

//**************** Variabili****************//


   int Bars;               // Numero di barre intere.
   int Balance;            // Numero di barre ancora da scrivere non intere.
   int i, ind;           

   Bars = percent/3;       // Quante sono le barre intere da 3?
   Balance = percent%3;    // Conta se ha bisogno di porzioni di barre
   lcd_gotoxy(20,2);       // sposta il puntatore in posizione 20 II spam(meta negativa lcd)
   
   ind=19;                 //inizia dalla posizione 19
 
  for (i=0; i<Bars;i++)
   
   {  output_high(PIN_A1);
      delay_us(100);
      output_low(PIN_A1);
      lcd_putc(0x02);      //Utilizzo putc per evitare l'<umento in posizione.
      lcd_gotoxy(ind,2);
      ind=ind-1;}          //Riporto l'indirizzo Ram 1 posto indietro.
     
     
     
  switch (Balance) {       //Mostra le barre restanti
      case 0: break;
      case 1: lcd_putc(0x03);break;
      case 2: lcd_putc(0x04);break;
      }
     
}


this is the function for any one who wants your bar goes like this


* ||||||||||||||||||||* forward

*||||||||||||||||| *back




But now i need an extra Help---

I need to show to display a variable float----
example: G= 2,007896

* |||||||||||||||||||G2,00*

only 2 char after the comma.
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 5:04 am     Reply with quote

When I have some time I would like to give your code a try as I have a battery level indication application where this will work nicely!

In your code add a call to the lcd_gotoxy() and set the co-ordinates to be just behind/before the end/start of the bar depending on your application. Then use printf("G%2.2f", your_float). This will give you two decimals before and after the "." and will start printing at the co-ordinates you specified.
bgvsan



Joined: 24 Aug 2008
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 5:45 am     Reply with quote

compiler send back an error

STDOUT not defined (may be missing #rs232)

the error is on the float variable (is declared as global)

any other solution?
bgvsan



Joined: 24 Aug 2008
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 4:17 pm     Reply with quote

i found


Code:
 printf(lcd_putc, "\g%1.2f", G);   //Visualizza il valore dell'ADC.



from lcd.h
Code:
case '\g'   : lcd_gotoxy(37,2);       break;







[URL=http://g.imageshack.us/g.php?h=299&i=lcd2ca4.jpg][IMG]http:
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group