Need help on programming a LCD to display a counter

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Need help on programming a LCD to display a counter

ソリューションへジャンプ
2,307件の閲覧回数
admin
Specialist II

Hi. Below is a code to display a string on a LCD. Please take note of the portion highlighted in red, as that is the part to display a string. I would like to know how to display a counter. For example, after a process has taken place, the LCD will countup from 0 to 1, and then from 1 to 2 for subsequent processes, and so on. An example on displaying a string is shown below the code. Thx

 

void lcd_string(byte line,byte *buffer)
  {
     byte i;
     __RESET_WATCHDOG();
      if(line==1)
      {
        lcd_write_cmd(0x40);
        Check_LCD_Busy();
        lcd_write_cmd(0x80);
        Check_LCD_Busy();
      }
      else
      {
        lcd_write_cmd(60);
        Check_LCD_Busy();
 
        lcd_write_cmd(0xc0);
        Check_LCD_Busy();
      }       
     for(i=0;i<16;i++)
     {
      if(buffer[i]!=0)
      {
        lcd_write_data(buffer[i]);
        Check_LCD_Busy();
      } else break;
  
     }   
  }

 

lcd_string(1, "Welcome to" );
lcd_string(2, "Dispenser System" );

Message Edited by Cryptical on 2009-03-03 01:42 AM
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,291件の閲覧回数
admin
Specialist II

bigmac, thx for replying and providing a sample code too :smileyhappy: 

I've tried it and now I'm able to display numbers on all 16 spaces of a line. Here's the code I added:

 

void lcd_test(void)
 {
     int buffer=0x30;
     byte array1[17], i;
     for (i = 0; i < 16; i++)
      {
       array1[i] = buffer;
       buffer+=1; 
      }
     array1[16] = 0;
     lcd_string(2, array1); 
 }

 

This lets me display "0123456789:;<=>?" on a single line. Cheers to you for helping me start out ^^

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,292件の閲覧回数
admin
Specialist II

bigmac, thx for replying and providing a sample code too :smileyhappy: 

I've tried it and now I'm able to display numbers on all 16 spaces of a line. Here's the code I added:

 

void lcd_test(void)
 {
     int buffer=0x30;
     byte array1[17], i;
     for (i = 0; i < 16; i++)
      {
       array1[i] = buffer;
       buffer+=1; 
      }
     array1[16] = 0;
     lcd_string(2, array1); 
 }

 

This lets me display "0123456789:;<=>?" on a single line. Cheers to you for helping me start out ^^

0 件の賞賛
返信
1,291件の閲覧回数
bigmac
Specialist III

Hello,

 

To display a dynamic count value on the LCD, you will need to firstly setup the contents of a char array variable to contain the ASCII characters representing the digits associated with the count. This will require that you convert the current binary counter value to an ASCII representation, and write each character to the required location within the array.

 

Since the display function commences at the start of each line, you may need to pad the array with spaces, or other characters, and then finally "null terminate" the array. You will also need to decide whether to suppress leading zeros for the count, i.e. replace leading zeros with spaces.

 

You can then display the array as you would a constant string.

 

byte array1[17], i;

 

// Fill array with spaces

for (i = 0; i < 16; i++)

   array1[i] = ' ';

array1[16] = 0;  // Null termination

 

// Convert counter value here and load digits to array1

...

 

lcd_string( 2, array1);

 

Regards,

Mac

Message Edited by bigmac on 2009-03-03 03:40 PM