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:
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!
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;
}
}
}
Best regards and sorry for my english!
Last edited by a moderator: