Hi guys,
I was wondering if someone can help me out here on a simple task.
I've been learning a lot by reading about sending data to a keyboard's PS/2 port, but I am unable to send a simple letter and have it show up in notepad.exe on the host computer.
I know the following: data sent must have Start Bit = 0, Scancode (LSB First), Odd Parity, Stop Bit = 1.
Now, I don't care about keyboard initialization, because I will be booting up the PC with a normal keyboard attached, then swapping out the keyboard with my device.
All I want to do is send the letter 'q' ($15).
I am doing so by sending q (0+$51+0+1), then the release code (0+$0F+1+1), then q again (0+$51+0+1).
However, I am not getting anything on the host side of things.
Here is my code:
Any advice appreciated.Code:; PS2SendCode ; ; PIC16F648A ; _________________ _______________ ; 1|RA2/AN2/VREF RA1/AN1|18 ; 2|RA3/AN3/CMP1 RA0/AN0|17 ; 3|RA4/TOCKI/CMP2 RA7/OSC1/CLKIN|16 ; VPP ---> 4|RA5/MCLR/VPP RA6/OSC2/CLKOUT|15 ; Gnd 5|Vss Vdd|14 +5 ; 6|RB0/INT RB7/T1OSI/PGD|13 <--- PGD ; 7|RB1/RX/DT RB6/T1OSO/T1CKI/PGC|12 <--- PGC ; 8|RB2/TX/CK RB5|11 <--> PS2DATA ; PUSH BUTTON ---> 9|RB3/CCP1 RB4/PGM|10 <--- PS2CLK _|¯|_|¯|_|¯|_|¯|_ ; ---------------------------------- ; ;=============================================================================== ; Keyboard to Host Protocol ; ___ _ _ _ _ _ _ _ _ _ _ _ _ ___ ; CLOCK |__| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| ; ; DATA | S | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | P | E | ; ; S = start bit = 0 P = odd parity E = stop bit = 1 ; data valid on falling edge of clock ;=============================================================================== @ errorlevel -223,-207,-306 ; Suppress useless messages @ LIST P=PIC16F648A @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_OFF & _LVP_OFF ;Using 4MHz oscillator define OSC 4 ;DEFINE SHIFT_PAUSEUS 43 PortB = 0 'Clear Port B INTCON = 0 'Interrupts Off CMCON = %00000111 'Disable Comparators OPTION_REG.7 = 0 'Enable Port B Weak Pull-Ups BitCnt VAR BYTE KBTimeout VAR BYTE ScanCode VAR Word Parity Var BYTE StartButton Var PortB.3 PS2Clk var PortB.4 '0 PS2Dat var PortB.5 '0 TRISB = %11111111 'Set PORTB pins direction to input Start: pause 500 if startbutton = 0 then: goSUB StartSend goto start StartSend: 'SEND Q ($15 LSB FIRST) Parity = 1 'Odd parity scancode.0 = 0 Gosub sendbit 'send START BIT scancode = %00010101 'send 'q' For bitcnt = 1 To 8 'set for 8 data bits Gosub sendbit 'send DATA BIT If scancode.0 = 1 Then: parity = parity + 1 scancode = scancode >> 1 'shift out next bit Next bitcnt scancode.0 = parity.0 Gosub sendbit 'send PARITY BIT scancode.0 = 1 Gosub sendbit 'send STOP BIT 'SEND RELEASE ($F0 LSB FIRST) Parity = 1 'Odd parity scancode.0 = 0 Gosub sendbit 'send START BIT scancode = %11110000 'send '$F0' For bitcnt = 1 To 8 'set for 8 data bits Gosub sendbit 'send DATA BIT If scancode.0 = 1 Then: parity = parity + 1 scancode = scancode >> 1 'shift out next bit Next bitcnt scancode.0 = parity.0 Gosub sendbit 'send PARITY BIT scancode.0 = 1 Gosub sendbit 'send STOP BIT 'SEND Q ($15 LSB FIRST) Parity = 1 'Odd parity scancode.0 = 0 Gosub sendbit 'send START BIT scancode = %00010101 'send 'q' For bitcnt = 1 To 8 'set for 8 data bits Gosub sendbit 'send DATA BIT If scancode.0 = 1 Then: parity = parity + 1 scancode = scancode >> 1 'shift out next bit Next bitcnt scancode.0 = parity.0 Gosub sendbit 'send PARITY BIT scancode.0 = 1 Gosub sendbit 'send STOP BIT Return SendBit: 'Looking for keyboard clock and data line to go high, then send data bit to it! ;If NOT(PS2Clk = 1 AND PS2Dat = 1) Then sendbit 'loop until clock line goes low PS2Dat = scancode.0 'send data bit return
Take a look at post #6 at
http://www.picbasic.co.uk/forum/showthread.php?t=7962
Also, I am not sure about the way you control the Clock line in your code.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Yeah, your code seems to indicate that you are waiting for the clock line to do something?
Your device must generate the clock in this case.
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Ok, I misunderstood.
I now realized that you are SENDING data TO KB;
Not reading from it.
Sorry about that.
------------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
rookie11, I don't think this code will ever work. Where are the ENDIF commands to terminate the IF statements?
Dave Purola,
N8NTA
One line If/Then statements....don't need an ENDIF....
If this=0 then gosub dothis : that=1 : goto something
...valid statement
If this is zero, then gosub dothis, set that to 1, then goto something.
But that colon following the THEN in the code a few posts back looks a bit strange to me...
And I know colons!![]()
Bookmarks