Need help on programming a LCD to display a counter

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Need help on programming a LCD to display a counter

跳至解决方案
2,309 次查看
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,293 次查看
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,294 次查看
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,293 次查看
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