0
\$\begingroup\$

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)

\$\endgroup\$
1
  • \$\begingroup\$ please indent your code properly \$\endgroup\$
    – vicatcu
    Commented Jul 29, 2021 at 2:54

1 Answer 1

2
\$\begingroup\$

You show no pullup resistors in your schematic, so this isn't going to work unless you enable the internal pullups of the MEGA32. To do this, you need to write ones to the input bits. In other words, whenever you change the column selector, the low-order bits should be 1111, not 0000.

For example:

  keypad_port = 0b11101111;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.