hemnath
Advanced Member level 3
I want to increment a count and display in lcd, when pushbutton is pressed. Button connected to PIN C0. It compiles successfully. In the display it shows count, but when i press push button it shows different characters at location 0x86 in the display. Please help...
HTML:
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=4000000) // internal clock
#define RS PIN_A2
#define EN PIN_A1
void lcd_init();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
unsigned char data[] = "count";
unsigned int i = 0;
unsigned int counter = 0;
int16 temp;
void main()
{
lcd_init();
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
while(1)
{
while(data[i]!='\0')
{
lcd_data(data[i]);
i++;
}
lcd_cmd(0x86);
if(input(PIN_C0)==0)
{
delay_ms(200);
temp=counter++;
lcd_data(temp);
}
}
}
void lcd_init()
{
lcd_cmd(0x30); // Configure the LCD in 8-bit mode, 1 line and 5x7 font
lcd_cmd(0x0C); // Display On and Cursor Off
lcd_cmd(0x01); // Clear display screen
lcd_cmd(0x06); // Increment cursor
lcd_cmd(0x80); // Set cursor position to 1st line, 1st column
}
void lcd_cmd(unsigned char c)
{
output_b(c);
output_low(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
void lcd_data(unsigned char z)
{
output_b(z);
output_high(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}