lengoanhcat
Junior Member level 2
This is an interface code that I take from the 8051 micro-controller - Iscott MacKenzie. I has modified some to satisfy my requirement, but I got stuck in some syntax errors and I don't how to solve it. Please help me !!!
Cat Le
Thanks for kind hearts
Following is the .LST file
[/quote][/code]
Cat Le
Thanks for kind hearts
Code:
;FILE: KEYPAD.SRC
;************************************************************************
;Predefined bit and byte addresses *
;************************************************************************
P1 DATA 090H ;PORT 1
P2 DATA 0A0H ;PORT 2
ACC DATA 0E0H ;ACCUMULATOR
RS0 BIT 0D3H ;select bits for registers
RS1 BIT 0D4H ;
;************************************************************************
; KEYPAD INTERFACE EXAMPLE *
; *
;This program reads hexadecimal characters from a keypad attached *
;to Port 1 and control the electronic lock. *
;************************************************************************
ORG 0000H
;MAIN:
CLR RS0 ;RS0 = 0
CLR RS1 ;RS1 = 0
INPUT: SETB P2.0 ;activate input indicator led
CLR P2.1 ;deactivate verify indicator led
I1: CALL IN_HEX ;get code from keypad
MOV R0,A ;I1 ---> R0
CJNE R0, #0FH, I2 ;cancel ? no---> I2
SJMP INPUT ; yes---> INPUT again
I2: CALL IN_HEX ;get code from keypad
MOV R1,A ;I1 ---> R1
CJNE R1, #0FH, I3 ;cancel ? no---> I3
SJMP INPUT ; yes---> INPUT again
I3: CALL IN_HEX ;get code from keypad
MOV R2,A ;I1 ---> R2
CJNE R2, #0FH, I4 ;cancel ? no---> I4
SJMP INPUT ; yes---> INPUT again
I4: CALL IN_HEX ;get code from keypad
MOV R3,A ;I1 ---> R3
CJNE R3, #0FH, VERIFY;cancel ? no---> VERIFY
SJMP INPUT ; yes---> INPUT again
VERIFY: SETB P2.1 ;activate verify indicator led
CLR P2.0 ;deactivate input indicator led
V1: CALL IN_HEX ;get code from keypad
;CJNE A,R0H,V1 ;match ? --> no begin verifying process again
CJNE A,00H,V2 ;match ? --> no begin verifying process again
SJMP V2 ; --> yes jump to V2
V2: CALL IN_HEX ;get code from keypad
;CJNE A,R1,V3 ;match ? --> no begin verifying process again
CJNE A,01H,V1 ;match ? --> no begin verifying process again
SJMP V3 ; --> yes jump to V3
V3: CALL IN_HEX ;get code from keypad
;CJNE A,R2,V4 ;match ? --> no begin verifying process again
CJNE A,02H,V1 ;match ? --> no begin verifying process again
SJMP V4 ; --> yes jump to V4
V4: CALL IN_HEX ;get code from keypad
;CJNE A,R3,V1 ;match ? --> no begin verifying process again
CJNE A,03H,V1 ;match ? --> no begin verifying process again
SETB P2.2 ;
CLR P2.2 ;
SJMP INPUT ; --> yes jump to V2
;************************************************************************
;IN_HEX - input hex code from keypad with debouncing for keypress *
;and key release (50 repeat operations for each) *
;************************************************************************
IN_HEX: MOV R3, #50D;debounce count
BACK: CALL GET_KEY ;key pressed?
JNC IN_HEX ;no: check again
DJNZ R3,BACK ;yes: repeat 50 times
PUSH ACC ;save hex code
BACK2: MOV R3, #50D;wait for key up
BACK3: CALL GET_KEY ;key pressed?
JC BACK2 ;yes: keep checking
DJNZ R3,BACK3;no: repeat 50 times
POP ACC ;recover hex code and
RET ;return
;************************************************************************
;GET_KEY - get keypad status *
; - return with C=0 if no keypressed *
; - return with C=1 and hex code in ACC if a key is pressed *
;************************************************************************
GET_KEY:MOV A,#0FEH ;start with column 0
MOV R6,#4 ;use R6 as counter
TEST: MOV P1,A ;activate column line
MOV R7,A ;save ACC
MOV A,P1 ;read back Port 0
ANL A,#0F0H ;isolate row lines
CJNE A,#0F0H,KEY_HIT ;row line active
MOV A,R7 ;no: move to nex
RL A ; column line
DJNZ R6,TEST
CLR C
SJMP EXIT ;no key pressed
KEY_HIT:MOV R7,A ;save in R6
MOV A,#04 ;prepare to caculate
CLR C ;column weighting
SUBB A,R6 ;4-R6 = weighting
MOV R6,A ;save in R6
MOV A,R7 ;restore scan code
SWAP A ;put in low nibble
MOV R5,#4 ;use R5 as counter
AGAIN: RRC A
JNC DONE ;done when C=0
INC R6 ;add 4 until active
INC R6 ;row found
INC R6
INC R6
DJNZ R5,AGAIN
DONE: SETB C ;C = 1 (key pressed)
MOV A,R6 ;code in A
EXIT: RET
END
Following is the .LST file
Code:
HEXPAD^1 PAGE 1
1 ;FILE: KEYPAD.SRC
2 ;************************************************************************
3 ;Predefined bit and byte addresses *
4 ;************************************************************************
5
0090 6 P1 DATA 090H ;PORT 1
00A0 7 P2 DATA 0A0H ;PORT 2
00E0 8 ACC DATA 0E0H ;ACCUMULATOR
00D3 9 RS0 BIT 0D3H ;select bits for registers
00D4 10 RS1 BIT 0D4H ;
11
12 ;************************************************************************
13 ; KEYPAD INTERFACE EXAMPLE *
14 ; *
15 ;This program reads hexadecimal characters from a keypad attached *
16 ;to Port 1 and control the electronic lock. *
17 ;************************************************************************
0000 18 ORG 0000H
19 ;MAIN:
0000 C2D3 20 CLR RS0 ;RS0 = 0
0002 C2D4 21 CLR RS1 ;RS1 = 0
0004 D2A0 22 INPUT: SETB P2.0 ;activate input indicator led
0006 C2A1 23 CLR P2.1 ;deactivate verify indicator led
24
0008 120054 25 I1: CALL IN_HEX ;get code from keypad
000B F8 26 MOV R0,A ;I1 ---> R0
000C B80002 27 CJNE R0, #0FH, I2 ;cancel ? no---> I2
****----------------------------------------------------^
****ERROR #1: Illegal character
000F 80F3 28 SJMP INPUT ; yes---> INPUT again
29
0011 120054 30 I2: CALL IN_HEX ;get code from keypad
0014 F9 31 MOV R1,A ;I1 ---> R1
0015 B90002 32 CJNE R1, #0FH, I3 ;cancel ? no---> I3
****----------------------------------------------------^
****ERROR #1: Illegal character
0018 80EA 33 SJMP INPUT ; yes---> INPUT again
34
001A 120054 35 I3: CALL IN_HEX ;get code from keypad
001D FA 36 MOV R2,A ;I1 ---> R2
001E BA0002 37 CJNE R2, #0FH, I4 ;cancel ? no---> I4
****----------------------------------------------------^
****ERROR #1: Illegal character
0021 80E1 38 SJMP INPUT ; yes---> INPUT again
39
0023 120054 40 I4: CALL IN_HEX ;get code from keypad
0026 FB 41 MOV R3,A ;I1 ---> R3
0027 BB0002 42 CJNE R3, #0FH, VERIFY;cancel ? no---> VERIFY
****----------------------------------------------------^
****ERROR #1: Illegal character
002A 80D8 43 SJMP INPUT ; yes---> INPUT again
44
002C D2A1 45 VERIFY: SETB P2.1 ;activate verify indicator led
002E C2A0 46 CLR P2.0 ;deactivate input indicator led
47
0030 120054 48 V1: CALL IN_HEX ;get code from keypad
49 ;CJNE A,R0H,V1 ;match ? --> no begin verifying process agai
n
HEXPAD^1 PAGE 2
0033 B50002 50 CJNE A,00H,V2 ;match ? --> no begin verifying process agai
n
0036 8000 51 SJMP V2 ; --> yes jump to V2
52
0038 120054 53 V2: CALL IN_HEX ;get code from keypad
54 ;CJNE A,R1,V3 ;match ? --> no begin verifying process again
003B B501F2 55 CJNE A,01H,V1 ;match ? --> no begin verifying process agai
n
003E 8000 56 SJMP V3 ; --> yes jump to V3
57
0040 120054 58 V3: CALL IN_HEX ;get code from keypad
59 ;CJNE A,R2,V4 ;match ? --> no begin verifying process again
0043 B502EA 60 CJNE A,02H,V1 ;match ? --> no begin verifying process agai
n
0046 8000 61 SJMP V4 ; --> yes jump to V4
62
0048 120054 63 V4: CALL IN_HEX ;get code from keypad
64 ;CJNE A,R3,V1 ;match ? --> no begin verifying process again
004B B503E2 65 CJNE A,03H,V1 ;match ? --> no begin verifying process agai
n
004E D2A2 66 SETB P2.2 ;
0050 C2A2 67 CLR P2.2 ;
0052 80B0 68 SJMP INPUT ; --> yes jump to V2
69
70
71
72 ;************************************************************************
73 ;IN_HEX - input hex code from keypad with debouncing for keypress *
74 ;and key release (50 repeat operations for each) *
75 ;************************************************************************
76
0054 FB 77 IN_HEX: MOV R3, #50D;debounce count
****--------------------------------------------^
****ERROR #1: Illegal character
0055 120069 78 BACK: CALL GET_KEY ;key pressed?
0058 50FA 79 JNC IN_HEX ;no: check again
005A DBF9 80 DJNZ R3,BACK ;yes: repeat 50 times
005C C0E0 81 PUSH ACC ;save hex code
005E FB 82 BACK2: MOV R3, #50D;wait for key up
****--------------------------------------------^
****ERROR #1: Illegal character
005F 120069 83 BACK3: CALL GET_KEY ;key pressed?
0062 40FA 84 JC BACK2 ;yes: keep checking
0064 DBF9 85 DJNZ R3,BACK3;no: repeat 50 times
0066 D0E0 86 POP ACC ;recover hex code and
0068 22 87 RET ;return
88
89 ;************************************************************************
90 ;GET_KEY - get keypad status *
91 ; - return with C=0 if no keypressed *
92 ; - return with C=1 and hex code in ACC if a key is pressed *
93 ;************************************************************************
0069 E8 94 GET_KEY:MOV A,#0FEH ;start with column 0
****------------------------------------------^
****ERROR #1: Illegal character
006A FE 95 MOV R6,#4 ;use R6 as counter
****-------------------------------------------^
****ERROR #1: Illegal character
HEXPAD^1 PAGE 3
006B F590 96 TEST: MOV P1,A ;activate column line
006D FF 97 MOV R7,A ;save ACC
006E E590 98 MOV A,P1 ;read back Port 0
0070 58 99 ANL A,#0F0H ;isolate row lines
****------------------------------------------^
****ERROR #1: Illegal character
0071 B40007 100 CJNE A,#0F0H,KEY_HIT ;row line active
****------------------------------------------^
****ERROR #1: Illegal character
0074 EF 101 MOV A,R7 ;no: move to nex
0075 23 102 RL A ; column line
0076 DEF3 103 DJNZ R6,TEST
0078 C3 104 CLR C
0079 8013 105 SJMP EXIT ;no key pressed
007B FF 106 KEY_HIT:MOV R7,A ;save in R6
007C E8 107 MOV A,#04 ;prepare to caculate
****------------------------------------------^
****ERROR #1: Illegal character
007D C3 108 CLR C ;column weighting
007E 9E 109 SUBB A,R6 ;4-R6 = weighting
007F FE 110 MOV R6,A ;save in R6
0080 EF 111 MOV A,R7 ;restore scan code
0081 C4 112 SWAP A ;put in low nibble
0082 FD 113 MOV R5,#4 ;use R5 as counter
****-------------------------------------------^
****ERROR #1: Illegal character
0083 13 114 AGAIN: RRC A
0084 5006 115 JNC DONE ;done when C=0
0086 0E 116 INC R6 ;add 4 until active
0087 0E 117 INC R6 ;row found
0088 0E 118 INC R6
0089 0E 119 INC R6
008A DDF7 120 DJNZ R5,AGAIN
008C D3 121 DONE: SETB C ;C = 1 (key pressed)
008D EE 122 MOV A,R6 ;code in A
008E 22 123 EXIT: RET
124 END
125
126
127
VERSION 1.2k ASSEMBLY COMPLETE, 12 ERRORS FOUND
ERROR SUMMARY:
Line #27, ERROR #1: Illegal character
Line #32, ERROR #1: Illegal character
Line #37, ERROR #1: Illegal character
Line #42, ERROR #1: Illegal character
Line #77, ERROR #1: Illegal character
Line #82, ERROR #1: Illegal character
Line #94, ERROR #1: Illegal character
Line #95, ERROR #1: Illegal character
Line #99, ERROR #1: Illegal character
Line #100, ERROR #1: Illegal character
Line #107, ERROR #1: Illegal character
Line #113, ERROR #1: Illegal character
HEXPAD^1 PAGE 4
ACC. . . . . . . . . . . . . . . D ADDR 00E0H
AGAIN. . . . . . . . . . . . . . C ADDR 0083H
BACK . . . . . . . . . . . . . . C ADDR 0055H
BACK2. . . . . . . . . . . . . . C ADDR 005EH
BACK3. . . . . . . . . . . . . . C ADDR 005FH
DONE . . . . . . . . . . . . . . C ADDR 008CH
EXIT . . . . . . . . . . . . . . C ADDR 008EH
GET_KEY. . . . . . . . . . . . . C ADDR 0069H
I1 . . . . . . . . . . . . . . . C ADDR 0008H NOT USED
I2 . . . . . . . . . . . . . . . C ADDR 0011H
I3 . . . . . . . . . . . . . . . C ADDR 001AH
I4 . . . . . . . . . . . . . . . C ADDR 0023H
INPUT. . . . . . . . . . . . . . C ADDR 0004H
IN_HEX . . . . . . . . . . . . . C ADDR 0054H
KEY_HIT. . . . . . . . . . . . . C ADDR 007BH
P1 . . . . . . . . . . . . . . . D ADDR 0090H
P2 . . . . . . . . . . . . . . . D ADDR 00A0H
RS0. . . . . . . . . . . . . . . B ADDR 00D3H
RS1. . . . . . . . . . . . . . . B ADDR 00D4H
TEST . . . . . . . . . . . . . . C ADDR 006BH
V1 . . . . . . . . . . . . . . . C ADDR 0030H
V2 . . . . . . . . . . . . . . . C ADDR 0038H
V3 . . . . . . . . . . . . . . . C ADDR 0040H
V4 . . . . . . . . . . . . . . . C ADDR 0048H
VERIFY . . . . . . . . . . . . . C ADDR 002CH