I am trying to interface a normal keypad and LCD .where for example if i press '1' in keypad it will show 'one' in the display . if i press '=' it will show 'EQUAL' in Display . i developed below code . but after simulating , the LCD is showing Random text like picture below. i cant figure out what happened here.
#include <mega32.h>
#include <alcd.h>
#include <delay.h>
#define keypad_ddr DDRC
#define keypad_port PORTC
#define keypad_input PINC
void main(void)
{
keypad_ddr=0xF0;
lcd_init(16);
while(1)
{
lcd_clear();
keypad_port=0b11100000;
lcd_gotoxy(0,0);
if(keypad_input.0==0)
lcd_putsf("Seven");
if(keypad_input.1==0)
lcd_putsf("Four");
if(keypad_input.2==0)
lcd_putsf("One");
if(keypad_input.3==0)
lcd_putsf("ON/C");
keypad_port=0b11010000;
lcd_gotoxy(0,0);
if(keypad_input.0==0)
lcd_putsf("Eight");
if(keypad_input.1==0)
lcd_putsf("Five");
if(keypad_input.2==0)
lcd_putsf("Two");
if(keypad_input.3==0)
lcd_putsf("Zero");
keypad_port=0b10110000;
lcd_gotoxy(0,0);
if(keypad_input.0==0)
lcd_putsf("Nine");
if(keypad_input.1==0)
lcd_putsf("Six");
if(keypad_input.2==0)
lcd_putsf("Three");
if(keypad_input.3==0)
lcd_putsf("Equal");
keypad_port=0b01110000;
lcd_gotoxy(0,0);
if(keypad_input.0==0)
lcd_putsf("Division");
if(keypad_input.1==0)
lcd_putsf("Multiplication");
if(keypad_input.2==0)
lcd_putsf("Minus");
if(keypad_input.3==0)
lcd_putsf("Plus");
delay_ms(1000);
}
}
Simulation : (Look at the LCD)