PS2 keyboard and LCD connect to 8051

Discussion in 'Embedded Systems and Microcontrollers' started by vuckoliki, Dec 19, 2011.

  1. vuckoliki

    Thread Starter New Member

    Dec 19, 2011
    1
    0
    Hi,
    below is a simple code for Atmel 8051 connected with PS2 keyboard and LCD display. I want to take ASCII value from keyboard and displey it on LCD but i have problem with cnt1.

    Keyboard clk is connected on extern interrupt 1, port P3.3. And data value is taken from port P3.4.

    By looking picture http://www.google.rs/imgres?q=wavef...0&tbnw=187&start=0&ndsp=21&ved=1t:429,r:0,s:0

    my conclusion is that cnt1 must be reset on cnt1=11 but i am not sure in that.

    If anyone have more experience and can see error , please write something....thx!

    Code ( (Unknown Language)):
    1.  
    2. #define uchar unsigned char
    3. #define uint unsigned int
    4.  
    5. uchar cnt1=0; //
    6. bit write=0;
    7. sbit kbd_data=P3^4;
    8. unsigned char array1=0;
    9. uchar bafer=0;
    10.  
    11. void init (void)
    12. {
    13.    LCD16xx_init();
    14. }
    15.  
    16. void TimerXXX (void) interrupt 2
    17. {
    18.    bafer=kbd_data;
    19.  
    20.    if ((cnt1>0) && (cnt1<9))
    21.    {
    22.        bafer=bafer<<(cnt1-1);
    23.    }
    24.  
    25. array1^=bafer;
    26. cnt1++;
    27.  
    28. if(cnt1==33) //????????
    29.  {
    30.     cnt1=0;
    31.     write=1;
    32.     EX1 = 0;
    33.  }
    34. }
    35.  
    36. void main(void)
    37. {
    38.    uchar cnt2=0;
    39.    EA=1;
    40.    EX1=1;
    41.    init();
    42.  
    43. while(1)
    44.  {
    45.    if (write==1)
    46.     {
    47.        LCD16xx_write_charPos(cnt2,0, 0, array1 ); //(cnt2=cursor position,0=line number...)
    48.        cnt2++;
    49.        array1=0;
    50.        write=0;
    51.        EX1 = 1;
    52.      }
    53.  }
    54. }
    55.  
     
    Last edited by a moderator: Dec 19, 2011
Loading...