PS/2 keyboard communication PIC18F4550

Thread Starter

MarcoRamos

Joined Dec 12, 2013
7
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:

Rich (BB code):
#include<18f4550.h>    
#use delay(clock=20000000)											

#fuses   HS
#fuses   NOWDT         				
#fuses   PUT           				
#fuses   NOPROTECT     				
#fuses   NOBROWNOUT						
#fuses   NOLVP							 
#fuses   NOCPD
#fuses   MCLR	
				
#use 	    fast_io(b)	   //portb0 clock; portb1 data;					 
#use 	    fast_io(d)          //port for the LCD	

//memory position    				
#byte    portb=0xF81 				
#byte    portd=0xF83 		

			
#int_EXT
int interrupt_ext(void)
{
	if(bit_test(portb,1==1) && t==0) //while no pressed key the data is 1
		return(0);
//when the key is pressed the data value is 0
	if(bit_test(portb,1)==0)
		g[t]=0;	

	else
		g[t]=1;		

	t++;
}

void main()
{  
	enable_interrupts(global | int_ext);
	ext_int_edge (h_to_l);
	set_tris_b(0b11111111);
	set_tris_d(0b00000000);
						
   	while(1)	
   	{	
		if(t==8)
		{
			PORTD=g[8]; //Port of LCD
			escrever();   //Function for write g[8] to the LCD
			t=0;            
		}
	}
}
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:

THE_RB

Joined Feb 11, 2008
5,438
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. ;)
 

t06afre

Joined May 11, 2009
5,934
I've already read that article before but it will need some modifications because I use Mplab and CCS compiler :/
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
 

Thread Starter

MarcoRamos

Joined Dec 12, 2013
7
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.
 

Thread Starter

MarcoRamos

Joined Dec 12, 2013
7
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.
 
Top