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" );
解決済! 解決策の投稿を見る。
bigmac, thx for replying and providing a sample code too
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 ^^
bigmac, thx for replying and providing a sample code too
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 ^^
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