View previous topic :: View next topic |
Author |
Message |
pratik
Joined: 13 Oct 2005 Posts: 55
|
Posted: Sat Feb 25, 2006 9:22 pm Post subject: AT keyboard need help |
|
|
hi,
i using getatkbd command for reading AT keyboard and its working fine
but need a help for toggle Num Lock, Caps Lock, and Scroll Lock LED
can any one help me with sample program or how to send a data to
AT keyboard & code for Num Lock, Caps Lock, and Scroll Lock LED |
|
Back to top |
|
|
hwcintra
Joined: 30 Jan 2006 Posts: 2
|
Posted: Tue Mar 21, 2006 12:57 am Post subject: |
|
|
Hi ,
You are not the only one ! I'm looking for this too ! To command LEDs you need to send codes to the keyboard . You can find the codes at http://www.beyondlogic.org/keyboard/keybrd.htm . Until now my code is not operenting well , but any news IŽll post here. _________________ Harald |
|
Back to top |
|
|
dswinscoe
Joined: 09 Feb 2005 Posts: 17 Location: London, UK
|
Posted: Sat Apr 08, 2006 10:21 am Post subject: |
|
|
Last year I wrote a short piece of code to recognise a keyboard or mouse and if it was a mouse set the mouse to reporting.
The subroutine for writedata is probably what you want. The data you want to send is in the variable D with the parity bit as D.8 so to send FA you make D=$1FA as parity is odd. To send F2 make D=$0F2 so that there are an odd number of 1s in binary.
portb.0 is clock and portb.1 is data.
Code: | Writedata:
Portb.0 = 0
Ddrb.0 = 1
Waitus 200 'hold clock low for at least 100us
Portb.1 = 0
Ddrb.1 = 1
Waitus 5 'send start bit
Ddrb.0 = 0
Portb.0 = 1
Waitus 5 'release clock line
While Pinb.0 = 1
Wend 'wait for clock to go low again
For I = 1 To 9
Portb.1 = D.0 'shift out data
Shift D , Right , 1
While Pinb.0 = 0
Wend
While Pinb.0 = 1
Wend
Next I
Portb.1 = 1
Ddrb.1 = 0
Portb.1 = 1 'send stop bit
While Pinb.0 = 0
Wend
While Pinb.0 = 1
Wend
While Pinb.0 = 0
Wend
Return |
I hope this is what you need. I did turn LEDs on and off on the keyboard when I was testing the code and hardware but I did not keep this code. If you need all of my code let me know. _________________ Regards,
David Swinscoe
http://www.davidswinscoe.com |
|
Back to top |
|
|
dswinscoe
Joined: 09 Feb 2005 Posts: 17 Location: London, UK
|
Posted: Wed Apr 12, 2006 9:16 pm Post subject: |
|
|
I have now made the code tidier using functions and put in the commands for making the keyboard LEDs light up. For further commands see http://www.computer-engineering.org
Code: | Dim X As Byte
Dim J As Long
Dim Device As Byte
'set up pins for keyboard data and clock connections
Clockin Alias Pind.0
Clockout Alias Portd.0
Clockdir Alias Ddrd.0
Datain Alias Pind.1
Dataout Alias Portd.1
Datadir Alias Ddrd.1
Clockdir = 0
Datadir = 0
Clockout = 1
Dataout = 1
Device = "U"
Declare Function Readat() As Byte
Declare Function Writeat(byval D As Byte) As Byte
Const Report = $f4
'Make port B output for LEDs to display bytes read from keyboard/mouse
Ddrb = $ff
Portb = $ff
X = Readat()
'X should be equal to AAH if ok, otherwise FCH if error
Portb = X
Gosub Readdatat
'if a mouse then X should be 00H otherwise it should time out for keyboard
Waitus 200
'If a mouse is connected turn on reporting movements and button presses
If Device = "M" Then
X = Writeat(report)
Portb = X
'X should be equal to FAH if ok, otherwise FCH if error
End If
'If a keyboard is connected turn on each keyboard LED in turn 5 times
If Device = "K" Then
For J = 1 To 5
X = Writeat($ed)
X = Writeat($01)
Portb = X
Wait 1
X = Writeat($ed)
X = Writeat($02)
Portb = X
Wait 1
X = Writeat($ed)
X = Writeat($04)
Portb = X
Wait 1
Next J
X = Writeat($ed)
X = Writeat($00)
Portb = X
End If
Do
'Display output of mouse/keyboard to LEDs on port B
X = Readat()
Portb = X
Loop
Readdatat:
J = 0
Do
J = J + 1
If J > 200000 Then 'time out if no clock pulses received
Device = "K" 'and indicate keyboard
Exit Do
End If
Loop Until Datain = 0
If Datain = 0 Then
Device = "M"
X = Readat()
End If
Return
Function Readat() As Byte
Local I As Byte
Do
Loop Until Clockin = 0
While Clockin = 0 'wait for first clock pulse
Wend
Readat = 0
For I = 1 To 8
While Clockin = 1
Wend
Shift Readat , Right , 1
If Datain = 1 Then Readat = Readat + 128 'shift in data
While Clockin = 0 'and wait for clock rising edge
Wend
Next I
For I = 1 To 2
While Clockin = 1
Wend
While Clockin = 0 'wait for parity and stop bits
Wend
Next I
End Function
Function Writeat(byval D As Byte) As Byte
Local I As Byte
Local P As Byte
Clockout = 0
Clockdir = 1
Waitus 200 'hold clock low for at least 100us
Dataout = 0
Datadir = 1
Waitus 5 'send start bit
Clockdir = 0
Clockout = 1
Waitus 5 'release clock line
While Clockin = 1
Wend 'wait for clock to go low again
P = 1
For I = 1 To 8
Dataout = D.0 'shift out data
P = P.0 Xor D.0
Shift D , Right , 1
While Clockin = 0
Wend
While Clockin = 1
Wend
Next I
Dataout = P.0 'shift out parity bit
While Clockin = 0
Wend
While Clockin = 1
Wend
Dataout = 1
Datadir = 0
Dataout = 1 'send stop bit
While Clockin = 0
Wend
While Clockin = 1
Wend
While Clockin = 0
Wend
Writeat = Readat()
End Function |
_________________ Regards,
David Swinscoe
http://www.davidswinscoe.com |
|
Back to top |
|
|
|