PS/2 keyboard communication PIC18F4550

Discussion in 'Programmer's Corner' started by MarcoRamos, Dec 12, 2013.

  1. MarcoRamos

    Thread Starter New Member

    Dec 12, 2013
    7
    0
    Hi guys,
    Im trying communicate my stand alone number pad keyboard with my PIC and show the keys pressed in LCD. For that, I use a converter USB -> PS/2. (The LCD is not difficult for me and works fine). I already read some articles about this type of communication and I know I must use 4 pins:

    +VCC
    GND
    CLOCK (PIN RB0)
    DATA (PIN RB1)

    My code what it does is, in every falling edge of the clock the external interrupt is activated. Here, the PIN RB1 is read and their value is wrote, 0 or 1, for a vector of 8 positions. When the vector is full, I put the vector to the LCD. I post the code for better understand:

    Code ( (Unknown Language)):
    1.  
    2. #include<18f4550.h>    
    3. #use delay(clock=20000000)                                         
    4.  
    5. #fuses   HS
    6. #fuses   NOWDT                     
    7. #fuses   PUT                       
    8. #fuses   NOPROTECT                 
    9. #fuses   NOBROWNOUT                    
    10. #fuses   NOLVP                           
    11. #fuses   NOCPD
    12. #fuses   MCLR  
    13.                
    14. #use        fast_io(b)     //portb0 clock; portb1 data;                  
    15. #use        fast_io(d)          //port for the LCD 
    16.  
    17. //memory position                  
    18. #byte    portb=0xF81               
    19. #byte    portd=0xF83       
    20.  
    21.            
    22. #int_EXT
    23. int interrupt_ext(void)
    24. {
    25.     if(bit_test(portb,1==1) && t==0) //while no pressed key the data is 1
    26.         return(0);
    27. //when the key is pressed the data value is 0
    28.     if(bit_test(portb,1)==0)
    29.         g[t]=0;
    30.  
    31.     else
    32.         g[t]=1;    
    33.  
    34.     t++;
    35. }
    36.  
    37. void main()
    38. {  
    39.     enable_interrupts(global | int_ext);
    40.     ext_int_edge (h_to_l);
    41.     set_tris_b(0b11111111);
    42.     set_tris_d(0b00000000);
    43.                        
    44.     while(1)   
    45.     {  
    46.         if(t==8)
    47.         {
    48.             PORTD=g[8]; //Port of LCD
    49.             escrever();   //Function for write g[8] to the LCD
    50.             t=0;            
    51.         }
    52.     }
    53. }
    54.  
    In int_EXT function instead of write the vector I put, for experience, PORTD='a'; to ever time I press down a key the letter 'a' appears in LCD, but is not working too. If anyone could help me, I fully thank you.
    Best regards and sorry for my english!
     
    Last edited by a moderator: Dec 12, 2013
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  3. MarcoRamos

    Thread Starter New Member

    Dec 12, 2013
    7
    0
    I've already read that article before but it will need some modifications because I use Mplab and CCS compiler :/
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    That's great, you have a working example to follow and a good direction.
     
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    That means he will have to do work and learn stuff.

    And if he wanted to do work and learn stuff then he would already have a solution. I think what he wants is someone to fix his code for free, or supply him with fully tested and working code for his compiler for free. ;)
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your code lack a setup/configuration section for the LCD display as a starter. If you have not done yet write a simple program what put a "hello world" on a LCD. Before this is done it is no point in going further
    As another hint your PIC will most probably has a serial port onboard. Using this in the correct mode will probably save you a lot of work. I will also recommend this search all hits on the first page may be worth looking into https://www.google.com/search?q=ps+2+keyboard+serial+protocol
    I noted that the site pyroelectro.com are using a 18F chip in the example
     
  7. MarcoRamos

    Thread Starter New Member

    Dec 12, 2013
    7
    0
    t06afre thanks for the help, like I say before LCD is not difficult for me and I use it with no problem. I only wanted just a some help like a opinion for what I was making wrong and not the free code or other rediculous acusations like THE_RB said. My main objective is make a good tutorial for help the who like me need help in similar project. After some more work I fixed the code and now works great. I will post the tutorial but thanks to the help of the THE_RB and their comments will not in this forum. I fully apreciate the help of the others members. Can close the topic.
     
  8. MarcoRamos

    Thread Starter New Member

    Dec 12, 2013
    7
    0
    t06afre thanks for the help, like I say before, the LCD is not difficult for me and I use with no problem. I only wanted just some help like a opinion for what I was making wrong and not the free code or other ridiculous accusations like THE_RB said. My main objective is make a good tutorial for help the people like me, need help in similar projects. After some more work, I fixed the code and now works great. I will post the tutorial but thanks to the help of the THE_RB and their comments will not in this forum. I fully apreciate the help of the others members. Can close the topic.
     
Loading...