Friday, June 7, 2013

Microcontroller with Keypad & LCD

Now, we will interface the microcontroller with a keypad and a LCD. The schematic is so simple and the code is so clear

  
Code:
char keypadPort at PORTD ;

sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

void main() {

     unsigned char m ;
     const unsigned char keys[] = {'y','/','9','8','7','x','6','5','4','-','3','2','1','+','=','0','y'} ;
    
     Keypad_Init() ;
     Lcd_Init() ;
     Lcd_Cmd(_LCD_CURSOR_OFF) ;
     Lcd_Cmd(_LCD_CLEAR) ;
    
     while(1)
     {
          ReadAgain :
          m = Keypad_Key_Click() ;
          if(m == 0) goto ReadAgain ;
          Lcd_Chr_Cp(keys[m]) ;
     }
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...