jack1998
Junior Member level 2
I have connected the 8051 microcontrollers to the 16x2 LCD. I have connected the button so that I can increment every digit. When I pressed the button, it increments for single digits when I use it this way.
But when I use it as below it does not get incremented. I want to increment more than one digits in the LCD and tried the below way so that I can increment that. How can I do that? Any other way? Or below where I am wrong?
Code:
unsigned char number[2] = "3";
int temp = 0;
void display1(void) {
write_string(1, 0, number);
delay_msec(100);
}
int write_string(uint_fast8_t row, uint_fast8_t col, unsigned const char *str) {
if (row)
{
col |= 0x40;
}
col |= 0x80;
lcd_cout(col);
while (*str)
temp = lcd_dout(*str++);
return temp;
}
void incrementbutton(void) {
if (button == 1) {
temp = temp + 1;
button = 0;
}
}
Code:
int write_string(uint_fast8_t row, uint_fast8_t col, unsigned const char *str) {
if (row)
{
col |= 0x40;
}
col |= 0x80;
lcd_cout(col);
while (*str)
lcd_dout(*str++);
}
void display1(void) {
temp = write_string(1, 0, number);
delay_msec(100);
}
void incrementbutton(void) {
if (button == 1) { //button is pressed
temp = temp + 1;
button = 0;
}
}