+ Post New Thread
Results 1 to 17 of 17
  1. #1
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    How to interface 89c52 microcontroller to ps2 keyboard? and what is the source code f

    How to interface 89c52 microcontroller to ps2 keyboard? and what is the source code for it?

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 2
    Points: 5,806, Level: 18
    Achievements:
    7 years registered

    Join Date
    Feb 2009
    Location
    some where left alone
    Posts
    669
    Helped
    136 / 136
    Points
    5,806
    Level
    18

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co




  3. #3
    Advanced Member level 5
    Points: 33,613, Level: 44
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2158 / 2158
    Points
    33,613
    Level
    44
    Blog Entries
    1

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    check this
    Interfacing the PC's Keyboard.

    ps2 mouse source code
    sending code for ps/2 to protocol it means it will work for ps/2 keyboard as well as ps/2 mouse

    this program will trasnfer data (send by ps/2 device)on com port at 9600 baudrate

    Code:
    #include <p89v51rx2.h>
    #define HIGH 1
    #define LOW 0
    
    sbit data_bit=P3^3;
    sbit clk=P3^2;
    
    void MSDelay(unsigned char delay)
    {
    unsigned char i;
    for(i=0;i<delay;i++)
    {
    }
    }
    
    void ps2_write(unsigned char command)
    {
    unsigned char i;
    unsigned char parity = 1;
    data_bit=HIGH;
    
    clk=HIGH;
    MSDelay(100);
    
    clk=LOW;
    MSDelay(100);
    
    data_bit=LOW;
    MSDelay(10);
    clk=HIGH;
    /* wait for device to take control of clock */
    while (clk==HIGH); // this loop intentionally left blank
    for (i=0; i < 8; i++)
    {
    if (command & 0x01)
    {
    data_bit=HIGH;
    }else
    {
    data_bit=LOW;
    }
    // wait for clock
    while (clk== LOW);
    while (clk== HIGH);
    parity = parity ^ (command & 0x01);
    command = command >> 1;
    }
    // parity bit
    if (parity)
    {
    data_bit=HIGH;
    }else
    {
    data_bit=LOW;
    }
    //clock cycle - like ack.
    while(clk==LOW);
    while(clk==HIGH);
    data_bit=HIGH;
    MSDelay(10);
    while (clk==HIGH);
    // mode switch
    while ((clk==LOW)||(data_bit== LOW));
    // hold up incoming data
    clk=LOW;
    }
    unsigned char ps2_read()
    {
    unsigned char data1 = 0x00;
    unsigned char i;
    unsigned char bit1 = 0x01;
    
    // start clock
    clk=HIGH;
    data_bit=HIGH;
    MSDelay(10);
    while (clk == HIGH);
    while (clk==LOW);//eat start bit
    for (i=0; i < 8; i++)
    {
    while (clk==HIGH);
    if(data_bit==HIGH)
    {
    data1 = data1 | bit1;
    }
    while (clk == LOW);
    bit1= bit1<< 1;
    }
    // eat parity bit, ignore it.
    while (clk==HIGH);
    while (clk==LOW);
    // eat stop bit
    while (clk==HIGH);
    while (clk==LOW);
    clk=LOW; // hold incoming data
    return data1;
    }
    void serial_init()
    {
    FCF=1;
    SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */
    TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */
    TH1 = 253; /* reload value for 2400 baud */
    ET0 = 0; /* we don't want this timer to make interrupts */
    TR1 = 1; /* start the timer */
    ES = 0; /* allow serial interrupts */
    EA = 0; /* enable interrupts */
    }
    
    void main()
    {
    unsigned char count=0;
    serial_init();
    P2=0x00;
    ps2_write(0xff);
    while(count!=3)
    {
    SBUF=ps2_read();
    while(TI==0);
    TI=0;
    count++;
    }
    ps2_write(0xf4);
    while(1)
    {
    ps2_read();
    while(TI==0);
    TI=0;
    count++;
    }
    
    
    }
    " It is so simple to be happy,
    but it is so difficult to be simple"


    4 members found this post helpful.

  4. #4
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    thank u for reply..



  5. #5
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    I read that links.. but i Have problem that I m interfacing one end of 89c52 with Rs-232 cable and other end to keyboard i.e. clk,data,gnd,vcc is going to keyboard of controller...but I want to design that my 89c52 mcu is work like keyboard controller..
    plz help me..



  6. #6
    Advanced Member level 2
    Points: 5,806, Level: 18
    Achievements:
    7 years registered

    Join Date
    Feb 2009
    Location
    some where left alone
    Posts
    669
    Helped
    136 / 136
    Points
    5,806
    Level
    18

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    so you want to make keyboard ?



  7. #7
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    yes I want to make pc keyboard..

    ---------- Post added at 10:35 ---------- Previous post was at 10:30 ----------

    Any one knows How to find which key is press from keyboard on hyper terminal?? Like When I check my program on hyper terminal its shows the output only A B C D keys only what abt other keys?plz help me...
    thank u..



    •   AltAdvertisement

        
       

  8. #8
    Advanced Member level 2
    Points: 5,806, Level: 18
    Achievements:
    7 years registered

    Join Date
    Feb 2009
    Location
    some where left alone
    Posts
    669
    Helped
    136 / 136
    Points
    5,806
    Level
    18

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    go to this thread first https://www.edaboard.com/thread186240.html

    ---------- Post added at 13:05 ---------- Previous post was at 13:02 ----------

    then you have good idea about port expansion then you can increase your key pad up to more than 100 buttons connecting to 89c52 with serial port interface



    •   AltAdvertisement

        
       

  9. #9
    Advanced Member level 5
    Points: 33,613, Level: 44
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2158 / 2158
    Points
    33,613
    Level
    44
    Blog Entries
    1

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    the typed characters from the keyboard is detected as ASCII characters so passing the same to hyper terminal should print the same value pressed.. nothing much involved in that..
    " It is so simple to be happy,
    but it is so difficult to be simple"



  10. #10
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    when I press single key it dosent show any ascii char but when I press single key continuously then it shows ascii value also when I press 2 or more keys shows value also for diff keys press it shows same output...So what is the problem??



  11. #11
    Advanced Member level 5
    Points: 33,613, Level: 44
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2158 / 2158
    Points
    33,613
    Level
    44
    Blog Entries
    1

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    post your code and hardware circuit .. there is some problem in either of them......
    " It is so simple to be happy,
    but it is so difficult to be simple"



  12. #12
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    ckt diagram and asm code is I sent plz check it...



  13. #13
    Newbie level 1
    Points: 578, Level: 5

    Join Date
    May 2011
    Posts
    1
    Helped
    0 / 0
    Points
    578
    Level
    5

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    Key strokes from a keyboard are sent as scan codes. Each key on a keyboard has a unique scan code, one code is sent when the key is pressed and another when a key is released. It is up to the keyboard driver to interpret this as a particular ascii character.



    •   AltAdvertisement

        
       

  14. #14
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    Yes I know that 4 each key it has its own scan code.. but when I actual check it on terminal output is not come..?
    Regards..
    Swati



  15. #15
    Advanced Member level 5
    Points: 33,613, Level: 44
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2158 / 2158
    Points
    33,613
    Level
    44
    Blog Entries
    1

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    try to use a serial port analyzer to see what data comes to port and where it is going wrong...........
    " It is so simple to be happy,
    but it is so difficult to be simple"



  16. #16
    Newbie level 6
    Points: 349, Level: 3
    swatip's Avatar
    Join Date
    May 2011
    Posts
    13
    Helped
    0 / 0
    Points
    349
    Level
    3

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co

    What is serial port analyzer? How can I check porgram on it? I dont know.. what it is? Plz give more details abt it?
    Regards..
    Swati



  17. #17
    Administrator
    Points: 69,512, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2358 / 2358
    Points
    69,512
    Level
    64
    Blog Entries
    4

    Re: How to interface 89c52 microcontroller to ps2 keyboard? and what is the source co


    yes I want to make pc keyboard.
    Here's a complete PS/2 and USB PC Keyboard Emulator Project using AVRs:

    This article features small utility used to emulate keyboard input during application testing. It's based on software USB implementation for AVR microcontrollers.

    Yet Another Keyboard Emulator


    Any one knows How to find which key is press from keyboard on hyper terminal?? Like When I check my program on hyper terminal its shows the output only A B C D keys only what abt other keys?plz help me...

    Here is the original IBM Keyboard Technical Documention covers all scan codes and other interesting tidbits:

    IBM Keyboards (101 and 102 Keys)

    Another interesting PS/2 Keyboard related site:

    Interfacing the AT keyboard

    Hope these links help in your endeavors.



--[[ ]]--