Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pc keyboard interfacing problem

Status
Not open for further replies.

econsyst

New Member
Hello
I am an engineeering student, and have interest in 8051 microcontroller
and am presently trying to write a pc at keyboard interfacing program in 8051
assembly. here i am reading the keyboard and converting it to its
relevant ascii code and sending it to the uart
its almost 10 days and i am not getting results

i have made the circuit in the following way ...
PORT 1 (P1.0) - connected to kbd clock line
PORT 1 (P1.1) - connected to kbd data line

PORT 1 (P3.0/RXD) - connected to Rxd of MAX232
PORT 1 (P3.1/TXD) - connected to Txd of MAX232

and while execution i am supposed to get the relevant ascii code
for the pressed key , sent by the micro, for this i am running HYPER TERMINAL
program, but the micro is not at all sending anythig

i am including all the code to , could anyone tell me what could
be the possible problem.

;#######################################################################
;
; KBD kbdata - uC PORT P3.1 (PIN 11)
; KBD kbclock - uC PORT P3.2 (PIN 12)
; KBD Xfer Check BIT - uC PORT P3.3 (PIN 13)
; KBD Download LED - uC PORT P3.6 (PIN 16)
;
;*********************** KEYBOARD EQUATES ************************************

shiftf bit 18h ; shift flag 0=no shift key is pressed,1=shift key is pressed

kbdata equ p1.0 ; 8051 pin for KBD data line
kbclock equ p1.1 ; 8051 pin for KBD clock line
dnldled equ p1.5 ; led pin to denote a KBD transfer is in progress
; kbchk equ p3.3 ; KBD check bit, 0 indicates Display, 1 indicates KBDProg

lastkey equ 60h ; last pressed KBD key
curkey equ 61h ; current pressed KBD key


org 0000h
sjmp main ; jump to main program

main:
;******************** POWER SUPPLY SETTLING LOOP *****************************

mov r0,#0ffh ;wait for power resetling time
mov r1,#0ffh ;at the time of powering up
mov r2,#0fh
ploop:
djnz r0,ploop
djnz r1,ploop
djnz r2,ploop

CLR TR1
MOV SCON,#01011010B ;TI set indicates transmitter ready.
; mode 1,REN
MOV TMOD,#00100001B ;Timer 1 is set to 8 bit auto reload mode
orl pcon,#10000000B ; Set to double rate.
mov th1,#0fah ; Set reload value (4800 baud after smod set)
setb tr1 ; start timer.

;************************ KEYBOARD INITIALIZTION *****************************
setb dnldled
clr kbclock ; clr kbclock to make it not to send any data
clr kbdata ; clr kbdata to make not to check any key press
clr shiftf ; clear shift flag to tell shift key is not pressed
mov lastkey,#00h ; initialize the value of the last pressed key
mov curkey,#00h ; initialize the value of the current pressed key

; JNB RI,$ ;Wait until character received.
; MOV A,SBUF ;Read input character.
; CLR RI ;Clear reception flag.
;
; CLR TI ;Clear interrupt flag.
; MOV SBUF,A ;Write out character.
; JNB TI,$ ;Wait until transmission completed.

kbdprog:
clr dnldled ; make p3.6 low to make the download led ON
mov r7,#8 ; take data bit count in r7
mov curkey,#0 ; initialize curkey location to store the data from the kbd
setb kbdata ; make kbd data line high (IDLE)
setb kbclock ; make kbd clock line high (IDLE)
chksbit:
mov c,kbclock ; read clock line bit in carry flag
jc chksbit ; chk if it is high than keep checking clock line till it goes low
mov c,kbdata ; once it is low read the data line for a start bit
jc chksbit ; if the start bit is high it is an invalid start
; bit so repeat theprocess to get the start bit again
chkdbit:
mov c,kbclock ; once a valid start bit is detected chk clock low for next data bit
jc chkdbit ; keep checking till the clock line goes low
mov c,kbdata ; once the clock goes low read the data bit
mov a,curkey ; take the current key value in a
rr a ; rotate it to right with carry so that
mov acc.7,c
mov curkey,a ; the LSB of key data will get into curkey
djnz r7,chkdbit ; chk if 8 data bits have been read, if not then get next data bit
chkpbit:
mov c,kbclock ; read clock line for the last but one bit which
jc chkpbit ; is the parity bit
nop ; no parity checking
chklbit:
mov c,kbclock ; read clock line for the last bit which
jc chklbit ; is the stop bit
; mov c,kbdata ; stop bit data
; jc vlddata ; if stop is a logic high than it is a valid key and data is valid
; sjmp krepeat ; if stop bit is low invalid stop bit so leave the key data
vlddata:
mov a,lastkey ; check if last scan code sent was an E0 than
; cjne a,#0e0h,chkcurk ; simply make the current scan code as the
; mov a,curkey ; get current key in acc
; mov lastkey,a ; store it in lastkey
; sjmp krepeat
;chkcurk:
; mov a,curkey ; check if the current scan code is an E0
; cjne a,#0e0h,chkshift ; than make it as the last scan code
; mov lastkey,a
; sjmp krepeat
;chkshift:
cjne a,#12h,noshift ; check if current scan code is a shift key
mov a,lastkey
cjne a,#0f0h,makesft ; yes than chk if the lastkey was an f0(break key)
clr shiftf ; yes than its a shift key break so clear shift flag
mov lastkey,#12h ; and make shift key as the lastkey
sjmp kbdprog
makesft:
setb shiftf ; if lastkey is not F0 when curkey is shift key set shift flag
mov lastkey,#12h ; store shift key as lastkey
sjmp kbdprog
noshift:
cjne a,#0f0h,nobreak ; if current key is not shift key chk if it is a Break key(F0)
mov lastkey,a ; yes than store it as the last key
sjmp kbdprog
nobreak:
mov a,lastkey ; if non of the above key means may be a valid data key
cjne a,#0f0h,no_f0 ; chk if last key was a break key
mov lastkey,#0 ; yes than make 0 as the lastkey
sjmp kbdprog
no_f0:
setb dnldled
mov a,curkey ; if lastkey is not a break key than
mov lastkey,a ; make the curkey as the lastkey
jnb shiftf,loadunsft ; if shift key is not set load the unshifted data
mov dptr,#shift ; if shift key is set load the shifted data
sjmp getkeyval
loadunsft:
mov dptr,#unshift
getkeyval: ; get the key value
movc a,@a+dptr
cjne a,#0,dataval ; if key value is 1Fh, not a valid data
sjmp kbdprog

;**************************** STORE DATA TO I2C MEMORY ******************************

dataval:
; send this data to the console
CLR TI ;Clear interrupt flag.
MOV SBUF,A ;Write out character.
JNB TI,$ ;Wait until transmission completed.
ajmp kbdprog


;sendpc:
; CLR TI ;Clear interrupt flag.
; MOV SBUF,A ;Write out character.
; JNB TI,$ ;Wait until transmission completed.
; ret


;recvpc:
; JNB RI,$ ;Wait until character received.
; MOV A,SBUF ;Read input character.
; CLR RI ;Clear reception flag.
; ret

;s_init:

; ret



;***********************************************************************
; UNSHIFTED KEY CODES - Begin
;***********************************************************************
unshift:
db 0 ;0
db 0 ;1-F9
db 0 ;2
db 0 ;3-F5
db 0 ;4-F3 - denotes animation 3
db 0 ;5-F1 - denotes animation 1
db 0 ;6-F2 - denotes animation 2
db 0 ;7-F12
db 0 ;8-
db 0 ;9-F10
db 0 ;A-F8
db 0 ;B-F6
db 0 ;C-F4
db 09h ;D-TAB
db '`' ;E-`~
db 0 ;F-
db 0 ;10-
db 0 ;11-ALT(Left)
db 0 ;12-SHIFT(Left)
db 0 ;13-
db 0 ;14-CTRL(Left)
db 'q' ;15-Q
db '1' ;16-1!
db 0 ;17-
db 0 ;18-
db 0 ;19-
db 'z' ;1A-Z
db 's' ;1B-S
db 'a' ;1C-A
db 'w' ;1D-W
db '2' ;1E-2@
db 0 ;1F-
db 0 ;20-
db 'c' ;21-C
db 'x' ;22-X
db 'd' ;23-D
db 'e' ;24-E
db '4' ;25-4$
db '3' ;26-3#
db 0 ;27-
db 0 ;28-
db ' ' ;29-SPACE
db 'v' ;2A-V
db 'f' ;2B-F
db 't' ;2C-T
db 'r' ;2D-R
db '5' ;2E-5%
db 0 ;2F-
db 0 ;30-
db 'n' ;31-N
db 'b' ;32-B
db 'h' ;33-H
db 'g' ;34-G
db 'y' ;35-Y
db '6' ;36-6^
db 0 ;37-
db 0 ;38-
db 0 ;39-
db 'm' ;3A-M
db 'j' ;3B-J
db 'u' ;3C-U
db '7' ;3D-7&
db '8' ;3E-8*
db 0 ;3F-
db 0 ;40-
db ',' ;41-,<
db 'k' ;42-K
db 'i' ;43-I
db 'o' ;44-O
db '0' ;45-0)
db '9' ;46-9(
db 0 ;47-
db 0 ;48-
db '.' ;49->.
db '/' ;4A-/?
db 'l' ;4B-L
db ';' ;4C-;:
db 'p' ;4D-P
db '-' ;4E-_-
db 0 ;4F-
db 0 ;50-
db ',' ;51-
db 0 ;52-'"
db 0 ;53-
db '[' ;54-[{
db '=' ;55-+=
db 0 ;56-
db 0 ;57-
db 0 ;58-CAPS
db 0 ;59-SHIFT(Right)
db 13 ;5A-ENTER
db ']' ;5B-]}
db 0 ;5C-
db 92 ;5D-\|
db 0 ;5E-
db 0 ;5F-
db 0 ;60-
db 0 ;61-
db 0 ;62-
db 0 ;63-
db 0 ;64-
db 0 ;65-
db 8 ;66-BACKSPACE
db 0 ;67-
db 0 ;68-
db 0 ;69-1(Numeric)
db 0 ;6A-
db 0 ;6B-4(Numeric)
db 0 ;6C-7(Numeric)
db 0 ;6D-
db 0 ;6E-
db 0 ;6F-
db 0 ;70-0(Numeric)
db 127 ;71-.(Numeric)
db 0 ;72-2(Numeric)
db 0 ;73-5(Numeric)
db 0 ;74-6(Numeric)
db 27 ;75-8(Numeric)
db 0 ;76-ESC
db 0 ;77-NUM KEY
db 0 ;78-F11
db '+' ;79-+(Numeric)
db 0 ;7A-3(Numeric)
db '-' ;7B--(Numeric)
db '*' ;7C-*(Numeric)
db 0 ;7D-9(Numeric)
db 0 ;7E-
db 0 ;7F-
;
;***********************************************************************
; UNSHIFTED KEY CODES - End
;***********************************************************************
;***********************************************************************
; SHIFTED KEY CODES - Begin
;***********************************************************************
shift:
db 0 ;0
db 0 ;1-F9
db 0 ;2
db 0 ;3-F5
db 0 ;4-F3 - denotes animation 3
db 0 ;5-F1 - denotes animation 1
db 0 ;6-F2 - denotes animation 2
db 0 ;7-F12
db 0 ;8-
db 0 ;9-F10
db 0 ;A-F8
db 0 ;B-F6
db 0 ;C-F4
db 0 ;D-TAB
db '~' ;E-`~
db 0 ;F-
db 0 ;10-
db 0 ;11-ALT(Left)
db 0 ;12-SHIFT(Left)
db 0 ;13-
db 0 ;14-CTRL(Left)
db 'Q' ;15-Q
db '!' ;16-1!
db 0 ;17-
db 0 ;18-
db 0 ;19-
db 'Z' ;1A-Z
db 'S' ;1B-S
db 'A' ;1C-A
db 'W' ;1D-W
db '@' ;1E-2@
db 0 ;1F-
db 0 ;20-
db 'C' ;21-C
db 'X' ;22-X
db 'D' ;23-D
db 'E' ;24-E
db '$' ;25-4$
db '#' ;26-3#
db 0 ;27-
db 0 ;28-
db ' ' ;29-SPACE
db 'V' ;2A-V
db 'F' ;2B-F
db 'T' ;2C-T
db 'R' ;2D-R
db '%' ;2E-5%
db 0 ;2F-
db 0 ;30-
db 'N' ;31-N
db 'B' ;32-B
db 'H' ;33-H
db 'G' ;34-G
db 'Y' ;35-Y
db '^' ;36-6^
db 0 ;37-
db 0 ;38-
db 0 ;39-
db 'M' ;3A-M
db 'J' ;3B-J
db 'U' ;3C-U
db '&' ;3D-7&
db '*' ;3E-8*
db 0 ;3F-
db 0 ;40-
db '<' ;41-,<
db 'K' ;42-K
db 'I' ;43-I
db 'O' ;44-O
db ')' ;45-0)
db '(' ;46-9(
db 0 ;47-
db 0 ;48-
db '>' ;49->.
db '?' ;4A-/?
db 'L' ;4B-L
db ':' ;4C-;:
db 'P' ;4D-P
db '_' ;4E-_-
db 0 ;4F-
db 0 ;50-
db 0 ;51-
db '"' ;52-'"
db 0 ;53-
db '{' ;54-[{
db '+' ;55-+=
db 0 ;56-
db 0 ;57-
db 0 ;58-CAPS
db 0 ;59-SHIFT(Right)
db 13 ;5A-ENTER
db '}' ;5B-]}
db 0 ;5C-
db '|' ;5D-\|
db 0 ;5E-
db 0 ;5F-
db 0 ;60-
db 0 ;61-
db 0 ;62-
db 0 ;63-
db 0 ;64-
db 0 ;65-
db 8 ;66-BACKSPACE
db 0 ;67-
db 0 ;68-
db '1' ;69-1(Numeric)
db 0 ;6A-
db '4' ;6B-4(Numeric)
db '7' ;6C-7(Numeric)
db 0 ;6D-
db 0 ;6E-
db 0 ;6F-
db '0' ;70-0(Numeric)
db '.' ;71-.(Numeric)
db '2' ;72-2(Numeric)
db '5' ;73-5(Numeric)
db '6' ;74-6(Numeric)
db '8' ;75-8(Numeric)
db 27 ;76-ESC
db 0 ;77-NUM KEY
db 0 ;78-F11
db '+' ;79-+(Numeric)
db '3' ;7A-3(Numeric)
db '-' ;7B--(Numeric)
db '*' ;7C-*(Numeric)
db '9' ;7D-9(Numeric)
db 0 ;7E-
db 0 ;7F-
;
;***********************************************************************
; SHIFTED KEY CODES - End
;***********************************************************************



END



regards
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top