求助大家了 我的单片机汇编程序出了点问题
时间:10-02
整理:3721RD
点击:
MODE EQU 082H ; 8255工作方式
PORTA EQU 08000H ;8255PA端口地址
CTL EQU 08003H ;8255控制端口地址
OUTBIT EQU 09002H ;数码管位控制口
OUTSEG EQU 09004H ;数码管段控制口
IN EQU 09001H ; 键盘输入口
LEDBUF EQU 60H ; 显示缓冲区
ORG 0000H ;复位入口
LJMP START
LEDMAP:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H
DB 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
DELAY: MOV R7,#0 ;延时子程序
DELAYLOOP:
DJNZ R7, DELAYLOOP
DJNZ R6, DELAYLOOP
RET
DISPLAYLED: ;显示子程序
MOV R0,#LEDBUF
MOV R1,#6
MOV R2,#00100000B
LOOP: MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
MOV A, @R0
MOV DPTR, #OUTSEG
MOVX @DPTR, A
MOV DPTR, #OUTBIT
MOV A, R2
MOVX @DPTR, A
MOV R6,#1
CALL DELAY
MOV A, R2
RR A
MOV R2,A
INC R0
DJNZ R1,LOOP
MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
RET
TESTKEY: ;按键子程序
MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
MOV DPTR, #IN
MOVX A,@DPTR
CPL A
ANL A,#0FH
RET
KEYTABLE: ;键值表
DB 16H, 15H, 14H, 0FFH
DB 13H, 12H, 11H, 10H
DB 0DH, 0CH, 0BH, 0AH
DB 0EH, 03H, 06H, 09H
DB 0FH, 02H, 05H, 08H
DB 00H, 01H, 04H, 07H
GETKEY: MOV DPTR, #OUTBIT ; 读键值子程序
MOV P2,DPH
MOV R0,#LOW(IN)
MOV R1,#00100000B
MOV R2,#6
KLOOP: MOV A, R1
CPL A
MOVX @DPTR, A
CPL A
RR A
MOV R1,A
MOVX A, @R0
CPL A
ANL A, #0FH
JNZ GOON1
DJNZ R2, KLOOP
MOV R2, #0FFH
SJMP EXIT
GOON1: MOV R1, A
MOV A, R2
DEC A
RL A
RL A
MOV R2, A ; R2=(R2-1)*4
MOV A, R1
MOV R1, #4
LOOPC: RRC A
JC EXIT
INC R2
DJNZ R1, LOOPC
EXIT: MOV A, R2
MOV DPTR, #KEYTABLE
MOVC A, @A+DPTR
MOV R2, A
WAITRELEASE:
MOV DPTR, #OUTBIT
CLR A
MOVX @DPTR, A
MOV R6, #10
CALL DELAY
CALL TESTKEY
JNZ WAITRELEASE
MOV A, R2
RET
; 模拟温度调节
UP EQU 16H ;NEXT
DOWN EQU 15H ;LAST
LOWLIMIT EQU 10
HIGHLIMIT EQU 30
LOWTEMP EQU -40 ;A/D 0
HIGHTEMP EQU 50 ;A/D 255
ADPORT EQU 0A000H
HEAT EQU 1
COOL EQU 2
SETTEMP EQU 50H
CURTEMP EQU 51H
DISPLAYRESULT:
MOV A, CURTEMP
JNB ACC.7,GE0
MOV LEDBUF, #40H
DEC A
CPL A
JMP GOON
GE0: MOV LEDBUF,#0
GOON: MOV B, #10H
div AB
MOV DPTR, #LEDMAP
MOVC A, @A+DPTR
MOV LEDBUF+1,A
MOV A, B
MOVC A, @A+DPTR
MOV LEDBUF+2,A
MOV LEDBUF+3,#0
MOV A, SETTEMP
MOV B, #10H
div AB
MOVC A, @A+DPTR
MOV LEDBUF+4,A
MOV A, B
MOVC A, @A+DPTR
MOV LEDBUF+5,A
RET
READAD: MOV DPTR,#ADPORT
CLR A
MOVX @DPTR,A ;启动A/D
MOV A,#0
DJNZ ACC, $ ;延时
MOVX A,@DPTR
RET
READTEMP:
MOV R1,#0
MOV R2,#0
MOV R0,#16
RLOOP: CALL READAD
ADD A, R2
MOV R2,A
JNC GN1
INC R1
GN1: DJNZ R0,RLOOP
MOV A, R2
SWAP A
ANL A, #0FH
XCH A, R1
SWAP A
ANL A, #0F0H
ORL A, R1 ;A=R1R2/16
MOV B, #(HIGHTEMP-LOWTEMP)
MUL AB
MOV A, B ;/256
ADD A, #LOWTEMP
MOV CURTEMP, A
RET
START: MOV SP, #70H ;主程序
MOV A, #MODE
MOV DPTR, #CTL
MOVX @DPTR, A;设置8255 PA,PC输出, PB输入
MOV SETTEMP, #20
MLOOP: CALL TESTKEY
JNZ KEYPRESSED
CALL DISPLAYRESULT
CALL DISPLAYLED
CALL READTEMP
MOV A, CURTEMP
JB ACC.7,LE0
CLR C
MOV B, SETTEMP
DEC B
DEC B
SUBB A, B
JNC GN2
LE0: MOV A,#HEAT
MOV DPTR, #PORTA
MOVX @DPTR, A
SJMP GN4
GN2: MOV A, CURTEMP
SETB C
MOV B, SETTEMP
INC B
INC B
SUBB A, B
JC GN3
MOV A, #COOL
MOV DPTR, #PORTA
MOVX @DPTR, A
SJMP GN4
GN3: MOV A,#0
MOV DPTR, #PORTA
MOVX @DPTR, A
GN4: SJMP MLOOP
KEYPRESSED:
CALL GETKEY
MOV B, A
XRL A, #DOWN
JNZ KEY0
MOV A, SETTEMP
XRL A, #LOWLIMIT
JZ KEY1
DEC SETTEMP
SJMP KEY1
KEY0: MOV A, B
XRL A, #UP
JNZ KEY1
MOV A, SETTEMP
XRL A, HIGHLIMIT
JZ KEY1
INC SETTEMP
KEY1: SJMP MLOOP
END
上面加粗红体的程序总是显示语法错误和非法字符 我用的是AT89C51 该怎么修改啊
PORTA EQU 08000H ;8255PA端口地址
CTL EQU 08003H ;8255控制端口地址
OUTBIT EQU 09002H ;数码管位控制口
OUTSEG EQU 09004H ;数码管段控制口
IN EQU 09001H ; 键盘输入口
LEDBUF EQU 60H ; 显示缓冲区
ORG 0000H ;复位入口
LJMP START
LEDMAP:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H
DB 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
DELAY: MOV R7,#0 ;延时子程序
DELAYLOOP:
DJNZ R7, DELAYLOOP
DJNZ R6, DELAYLOOP
RET
DISPLAYLED: ;显示子程序
MOV R0,#LEDBUF
MOV R1,#6
MOV R2,#00100000B
LOOP: MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
MOV A, @R0
MOV DPTR, #OUTSEG
MOVX @DPTR, A
MOV DPTR, #OUTBIT
MOV A, R2
MOVX @DPTR, A
MOV R6,#1
CALL DELAY
MOV A, R2
RR A
MOV R2,A
INC R0
DJNZ R1,LOOP
MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
RET
TESTKEY: ;按键子程序
MOV DPTR,#OUTBIT
MOV A, #0
MOVX @DPTR, A
MOV DPTR, #IN
MOVX A,@DPTR
CPL A
ANL A,#0FH
RET
KEYTABLE: ;键值表
DB 16H, 15H, 14H, 0FFH
DB 13H, 12H, 11H, 10H
DB 0DH, 0CH, 0BH, 0AH
DB 0EH, 03H, 06H, 09H
DB 0FH, 02H, 05H, 08H
DB 00H, 01H, 04H, 07H
GETKEY: MOV DPTR, #OUTBIT ; 读键值子程序
MOV P2,DPH
MOV R0,#LOW(IN)
MOV R1,#00100000B
MOV R2,#6
KLOOP: MOV A, R1
CPL A
MOVX @DPTR, A
CPL A
RR A
MOV R1,A
MOVX A, @R0
CPL A
ANL A, #0FH
JNZ GOON1
DJNZ R2, KLOOP
MOV R2, #0FFH
SJMP EXIT
GOON1: MOV R1, A
MOV A, R2
DEC A
RL A
RL A
MOV R2, A ; R2=(R2-1)*4
MOV A, R1
MOV R1, #4
LOOPC: RRC A
JC EXIT
INC R2
DJNZ R1, LOOPC
EXIT: MOV A, R2
MOV DPTR, #KEYTABLE
MOVC A, @A+DPTR
MOV R2, A
WAITRELEASE:
MOV DPTR, #OUTBIT
CLR A
MOVX @DPTR, A
MOV R6, #10
CALL DELAY
CALL TESTKEY
JNZ WAITRELEASE
MOV A, R2
RET
; 模拟温度调节
UP EQU 16H ;NEXT
DOWN EQU 15H ;LAST
LOWLIMIT EQU 10
HIGHLIMIT EQU 30
LOWTEMP EQU -40 ;A/D 0
HIGHTEMP EQU 50 ;A/D 255
ADPORT EQU 0A000H
HEAT EQU 1
COOL EQU 2
SETTEMP EQU 50H
CURTEMP EQU 51H
DISPLAYRESULT:
MOV A, CURTEMP
JNB ACC.7,GE0
MOV LEDBUF, #40H
DEC A
CPL A
JMP GOON
GE0: MOV LEDBUF,#0
GOON: MOV B, #10H
div AB
MOV DPTR, #LEDMAP
MOVC A, @A+DPTR
MOV LEDBUF+1,A
MOV A, B
MOVC A, @A+DPTR
MOV LEDBUF+2,A
MOV LEDBUF+3,#0
MOV A, SETTEMP
MOV B, #10H
div AB
MOVC A, @A+DPTR
MOV LEDBUF+4,A
MOV A, B
MOVC A, @A+DPTR
MOV LEDBUF+5,A
RET
READAD: MOV DPTR,#ADPORT
CLR A
MOVX @DPTR,A ;启动A/D
MOV A,#0
DJNZ ACC, $ ;延时
MOVX A,@DPTR
RET
READTEMP:
MOV R1,#0
MOV R2,#0
MOV R0,#16
RLOOP: CALL READAD
ADD A, R2
MOV R2,A
JNC GN1
INC R1
GN1: DJNZ R0,RLOOP
MOV A, R2
SWAP A
ANL A, #0FH
XCH A, R1
SWAP A
ANL A, #0F0H
ORL A, R1 ;A=R1R2/16
MOV B, #(HIGHTEMP-LOWTEMP)
MUL AB
MOV A, B ;/256
ADD A, #LOWTEMP
MOV CURTEMP, A
RET
START: MOV SP, #70H ;主程序
MOV A, #MODE
MOV DPTR, #CTL
MOVX @DPTR, A;设置8255 PA,PC输出, PB输入
MOV SETTEMP, #20
MLOOP: CALL TESTKEY
JNZ KEYPRESSED
CALL DISPLAYRESULT
CALL DISPLAYLED
CALL READTEMP
MOV A, CURTEMP
JB ACC.7,LE0
CLR C
MOV B, SETTEMP
DEC B
DEC B
SUBB A, B
JNC GN2
LE0: MOV A,#HEAT
MOV DPTR, #PORTA
MOVX @DPTR, A
SJMP GN4
GN2: MOV A, CURTEMP
SETB C
MOV B, SETTEMP
INC B
INC B
SUBB A, B
JC GN3
MOV A, #COOL
MOV DPTR, #PORTA
MOVX @DPTR, A
SJMP GN4
GN3: MOV A,#0
MOV DPTR, #PORTA
MOVX @DPTR, A
GN4: SJMP MLOOP
KEYPRESSED:
CALL GETKEY
MOV B, A
XRL A, #DOWN
JNZ KEY0
MOV A, SETTEMP
XRL A, #LOWLIMIT
JZ KEY1
DEC SETTEMP
SJMP KEY1
KEY0: MOV A, B
XRL A, #UP
JNZ KEY1
MOV A, SETTEMP
XRL A, HIGHLIMIT
JZ KEY1
INC SETTEMP
KEY1: SJMP MLOOP
END
上面加粗红体的程序总是显示语法错误和非法字符 我用的是AT89C51 该怎么修改啊