Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/18/03 03:51
Read: times


 
#43678 - Got it to work
Responding to: ???'s previous message
it semas the it was missing one setb KEYB_DATA!
So, if anyona likes, here is my code that worked:

------------ kb.asm --------------
.flag KEYB_DATA, P1.5
.flag KEYB_CLOCK, P3.2

;---------------------
; Keyboard Routines:
;---------------------
;*************************************
; CheckACK: c=1 if ACK OK
;*************************************
CheckACK:
mov a, KB_DATA
cjne a, #0xFA, CheckACK2
setb c
ret
CheckACK2:
clr c
ret
;*************************************
; InitKeyb:
;*************************************
InitKeyb:
mov KB_OK, #0
mov r1, #0xFF
acall Write_Keyb
acall Check_Keyb
acall CheckACK
jnc InitKeyb

mov r1, #0xF4 ; Enable
acall Write_Keyb
acall Check_Keyb
acall CheckACK
jnc KeybErr

mov r1, #0xF3 ; Set Typematic
acall Write_Keyb
acall Check_Keyb
acall CheckACK
jnc KeybErr
mov r1, #0x00 ; Typematic = 250 ms / 30 cps
acall Write_Keyb
acall Check_Keyb
acall CheckACK
jnc KeybErr

mov KB_OK, #1
KeybErr:
ret

;*************************************
; Zero2One: Wait for 0 to 1 on kb
; clock line, read the kb data line
; and shift right the bit to acc.7
;*************************************
Zero2One:
jnb KEYB_CLOCK, *
jb KEYB_CLOCK, *
mov c, KEYB_DATA
rrc a
ret

;*************************************
; Check_Keyb:
;*************************************
Check_Keyb:
setb KEYB_DATA
setb KEYB_CLOCK ; CLOCK & DATA high = Idle Pos
mov r0, #50
CheckAgain:
jnb KEYB_CLOCK, KeyHit
djnz r0, CheckAgain ; check r0 times
sjmp KeyEnd
KeyHit:
jnb KEYB_DATA, KeyHit2 ; Start bit must be 0
KeyEnd:
clr KEYB_CLOCK ; disable keyb
clr c ; c=0 = no keypress
ret
KeyHit2:
mov r0, #8 ; 8 bits
clr a
KeyHit3:
acall Zero2One
djnz r0, KeyHit3
mov r1, a

clr a
acall Zero2One ; Parity bit
acall Zero2One ; Stop bit
; acc.7 = stop, acc.6 = parity

clr KEYB_CLOCK
mov KB_DATA, r1
setb c
ret


Zero2One2:
jnb KEYB_CLOCK, *
jb KEYB_CLOCK, *
ret
;*************************************
; Write_Keyb: Send r1 to the kb
;*************************************
Write_Keyb:
mov r0, #8 ; 8 bits to receive
clr KEYB_CLOCK ; break the Keyboard
acall DelayMS ; (safety reasons)
clr KEYB_DATA ; request to send
setb KEYB_CLOCK ; enable the Keyboard
acall Zero2One2 ; Start Bit
mov a, r1 ; Data Bits
TxData:
rrc a
mov KEYB_DATA, c
acall Zero2One2
djnz r0, TxData

mov a, r1 ; calculate parity bit
mov c, psw.0 ; this is Even parity
cpl c ; and Keyboard needs Odd parity
mov KEYB_DATA, c ; send parity bit
acall Zero2One2

setb KEYB_DATA ; send stop bit
acall Zero2One2

acall Zero2One2
mov c, KEYB_DATA ; get ACK bit
clr KEYB_CLOCK ; stop the keyboard
ret

List of 4 messages in thread
TopicAuthorDate
AT keyboard again            01/01/70 00:00      
   Got it to work            01/01/70 00:00      
      RE: Got it to work            01/01/70 00:00      
         RE: Got it to work            01/01/70 00:00      

Back to Subject List