Reading_4x4_Keypad_with_18f4550

Read keypad and display pressed and time on LCD.
Show RESET and key_count reset to 0 whenever key_count equal to 10.

remark: Lcd_Out() seems working unproperly.It starts showing at             Lcd 2,12 although the Lcd_Out(2,7,  ) is used.


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;

// End LCD module connections

char keypadport at PORTD;
char txt1[] = "KEY_PRESS:";
char txt2[]="TIME:";
char TEN[]="TEN";
char cntxt[8];


 unsigned char Key=0;
 unsigned char Old_State=0;
 unsigned int cnt=0;


void main()

     {
      OSCCON=0xff;
      TRISB=0;
      TRISD=0;
      LATD=0;
      ADCON1 = 0xfF;
      CMCON = 0x07;


      Lcd_Init();
      Lcd_Cmd(_LCD_CLEAR);
      Lcd_Out(1,1,txt1);
      Lcd_Out(2,1,txt2);
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Keypad_Init();
     

      while(1)

      {

       Key=0;

      do
      Key=Keypad_Key_Click();
      while(!Key);


      switch(Key)
      {
       case 1:Key=49;break;
       case 2:Key=50;break;
       case 3:Key=51;break;
       case 4:Key=65;break;
       case 5:Key=52;break;
       case 6:Key=53;break;
       case 7:Key=54;break;
       case 8:Key=66;break;
       case 9:Key=55;break;
       case 10:Key=56;break;
       case 11:Key=57;break;
       case 12:Key=67;break;
       case 13:Key=42;break;
       case 14:Key=48;break;
       case 15:Key=35;break;
       case 16:Key=68;break;
     
       }
           

      if(Key!=Old_State)
      {
      Cnt=1;
      Old_State=Key;
      }
      else
      {
       Cnt++;
      }
     if(cnt==10)
      {
      Lcd_Out(2,8,"RESET");
       delay_ms(500);
       cnt=0;
       }

      IntToStr(cnt,cntxt);

      Lcd_Chr(1,12, Key);
      Lcd_Out(2,7, cntxt);

     

      }

     }



Comments

Popular posts from this blog

Inductance caculator

Pointer to object array