|
|
View previous topic :: View next topic |
Author |
Message |
DiegoGarcia
Joined: 01 Mar 2008 Posts: 48
|
Litle help to send correct chars using the PS2 keyboard itfc |
Posted: Mon Mar 17, 2008 4:10 pm |
|
|
Hi guys its me again ;)
I've done a lot of searchs and after read some documents about ps/2 interface I've made my own and its almost everything working nice.
I've founded the make and break codes so when I send the make code for numbers 1,3,4,7,8,9,0 the pc receives fine but the numbers 2,5 and 6 make the pc beep.
here is my scancodes table
Code: |
const long int PS2Keys[] =
{
0x45, // 0
0x16, // 1
0x1E, // 2 The pc beeps
0x26, // 3
0x25, // 4
0x2E, // 5 Here beeps to
0x36, // 6 and here to.
0x3D, // 7
0x3E, // 8
0x46 // 9
}; |
the code to send the data using the pic is :
Code: | void SendChar(byte Data)
{
int1 stopbit = 1;
int1 startbit = 0;
int1 parity = 0;
int i;
SendBit(startbit);
for (i=0; i<=7; i++)
{
SendBit(bit_test(Data,i));
//SendBit(shift_right(&Data,1,0));
}
SendBit(parity);
SendBit(stopbit);
}
void SendBit(int1 Data)
{
const byte dattime = 10;
const byte clktime = 50;
KeyClk = 1;
delay_us(dattime);
KeyData = Data;
delay_us(dattime);
KeyClk = 0;
delay_us(clktime);
}
void Main()
{
const long int PS2Keys[] =
{
0x45, // 0
0x16, // 1
0x1E, // 2
0x26, // 3
0x25, // 4
0x2E, // 5
0x36, // 6
0x3D, // 7
0x3E, // 8
0x46 // 9
};
int i = 0;
set_tris_a(0b10000000);
porta = 0x00;
portb = 0x00;
delay_ms(100);
while (TRUE)
{
Led = !Led;
set_tris_b(0b00000000);
SendChar(PS2Keys[i]);
delay_ms(30);
SendChar(0xF0);
delay_ms(30);
SendChar(PS2Keys[i]);
delay_ms(30);
set_tris_b(0x00000011);
if (i == 9)
i = 0; else
i++;
delay_ms(100);
}
} |
Any tips why just these numbers are not working ?
Thanks a lot,
Regards,
Diego Garcia |
|
|
SimpleAsPossible
Joined: 19 Jun 2004 Posts: 21
|
Oscilloscope? |
Posted: Mon Mar 17, 2008 9:41 pm |
|
|
Have you looked at your signals with a scope? The scan codes look right, according to the information I have. Maybe the clock gets skewed slightly? I had a nice theory going about strings of 1s, but 7 and 8 don't fit the theory. Sorry. Do any of the keys get misinterpreted occasionally?
I'd like to know that you got this working, since I may do something similar soon. |
|
|
DiegoGarcia
Joined: 01 Mar 2008 Posts: 48
|
|
Posted: Tue Mar 18, 2008 4:45 am |
|
|
I've found what is the problem, its the parity bit it should be calculated, the way that I've done is not checking the parity bit so I've to do it !
I will acomplish this task now and after I get the right results I post it here ;)
Regards,
Diego Garcia |
|
|
DiegoGarcia
Joined: 01 Mar 2008 Posts: 48
|
|
Posted: Tue Mar 18, 2008 5:37 am |
|
|
Here is the correct sendChar function
void SendChar(byte Data)
{
int1 stopbit = 1;
int1 startbit = 0;
int1 parity = 1;
int1 databit;
int i;
SendBit(startbit);
for (i=0; i<=7; i++)
{
databit = bit_test(Data,i);
if (databit == 1)
parity += 1;
SendBit(databit);
//SendBit(shift_right(&Data,1,0));
}
SendBit(parity);
SendBit(stopbit);
}
Now it works like a charm ;)
Regards,
Diego Garcia |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|