急求c51单片机汇编语言程序错误更改,用的keil软件不能生成hex文件,不能导入proteus

2024-11-22 06:19:39
推荐回答(5个)
回答1:

K1 BIT P1.0
K2 BIT P1.1
K3 BIT P1.2
K4 BIT P1.3
K5 BIT P1.4
K6 BIT P1.5
K7 BIT P1.6
K8 BIT P1.7
MIN EQU 30H
SEC EQU 31H
SEC100 EQU 32H
DIS_BUF EQU 33H
BUF_MIN_H EQU DIS_BUF
BUF_MIN_L EQU DIS_BUF+1
BUF_SEC_H EQU DIS_BUF+2
BUF_SEC_L EQU DIS_BUF+3
K_OLD EQU 41H
K_NEW EQU 42H
DIS_DIGIT EQU 43H
DIS_INDEX EQU 44H
K_OLD1 EQU 45H
K_NEW1 EQU 46H
FLAG EQU 47H
CONVERT EQU 48H

ORG 0000H
JMP MAIN
ORG 0003H
LJMP INT_0
ORG 0000BH
LJMP TIMER0
ORG 0001BH
LJMP TIMER1

ORG 0030H
MAIN:
MOV SP,#60H
MOV P0,#0FFH
MOV P2,#0FFH
MOV TMOD,#011H
MOV TH0,#0FCH
MOV TL0,#017H
MOV TH1,#0DCH
CLR A
MOV TL1,A
MOV CONVERT,#00H
MOV CONVERT+1 ,#00H
MOV CONVERT+2,#00H
MOV CONVERT+3 ,#00H
CLR A
MOV MIN,#20
MOV SEC,A
MOV SEC100,A
MOV BUF_MIN_H,#0A4H
MOV BUF_MIN_L,#0C0H
MOV BUF_SEC_H,#0C0H
MOV BUF_SEC_L,#0C0H
MOV DIS_BUF+4,#0C0H
MOV DIS_BUF+5,#0C0H
MOV DIS_BUF+6,#0C0H
MOV DIS_BUF+7,#0C0H
MOV FLAG ,#00H
MOV K_OLD,#00H
BEEP_BL00: MOV R3,#10
MOV R2,#200
MAIN1100:
CPL p3.7
LCALL DELAY500
LCALL DELAY500
DJNZ R2,MAIN1100
CPL p3.6
LCALL DELAY500
LCALL DELAY500
LCALL DELAY500
MOV R2,#200
MAIN2100:
CPL p3.7
LCALL DELAY500
DJNZ R2,MAIN2100
DJNZ R3,MAIN1100
LJMP START
DELAY500:
MOV R7,#230
LOOP1:
DJNZ R7,LOOP1
RET
START: MOV DIS_DIGIT,#0FEH
CLR A
MOV DIS_INDEX,A
SETB EA
SETB ET0
SETB TR0
SETB IT0
SETB EX0
SETB PT0
MAIN_LP:
CALL KEY_PROG
SJMP MAIN_LP
KEY_PROG:
CALL K_SCAN
MOV A,K_NEW
CJNE A,K_OLD,KEY_P1
JMP END_PROC_KEY
KEY_P1:
MOV R4,#15
KEY_P2:
MOV R7,#10
CALL DELAYMS
DJNZ R4,KEY_P2
CALL K_SCAN
MOV A,K_NEW
CJNE A,K_OLD,KEY_P3
JMP END_PROC_KEY
KEY_P3:
JB ACC.0,PROC_K1
JB ACC.1,PROC_K2
JB ACC.2,PROC_K3
JB ACC.3,PROC_K4
LJMP END_PROC_KEY
PROC_K1:LCALL BEEP_BL001
INC MIN
MOV A,MIN ;
CJNE A, #100,UPDATE_MIN21
MOV MIN,#00H
UPDATE_MIN21:
MOV A,MIN
MOV B,#10
DIV AB ; A = MIN / 10
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV BUF_MIN_H,A
MOV A,MIN
MOV B,#10
DIV AB
MOV A,B
MOVC A,@A+DPTR
MOV BUF_MIN_L,A
SJMP END_PROC_KEY
PROC_K2:LCALL BEEP_BL001
DEC MIN
MOV A,MIN
CJNE A, #255, UPDATE_MIN1
MOV MIN,#99
UPDATE_MIN1:
MOV A,MIN
MOV B,#10
DIV AB
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV BUF_MIN_H,A
MOV A,MIN
MOV B,#10
DIV AB
MOV A,B
MOVC A,@A+DPTR
MOV BUF_MIN_L,A
SJMP END_PROC_KEY
PROC_K3: LCALL BEEP_BL001
PUSH PSW
INC FLAG
MOV A ,FLAG
RRC A
JNC STOP
CLR P3.6
SETB ET1
SETB TR1
POP PSW
SJMP END_PROC_KEY
STOP:SETB P3.6
CLR ET1
CLR TR1
POP PSW
SJMP END_PROC_KEY
PROC_K4: LCALL BEEP_BL001
MOV R3,CONVERT+1
MOV CONVERT+1,CONVERT+3
MOV CONVERT+3,R3

MOV R3,CONVERT
MOV CONVERT,CONVERT+2
MOV CONVERT+2,R3
LCALL CONVETER
END_PROC_KEY:
RET

; 键扫描子程序
K_SCAN:
MOV P1,#0FFH
MOV K_NEW,#00H
MOV A,P1
CPL A
ANL A,#0F0H
SWAP A
MOV K_NEW,A
RET

USING 0
TIMER0:
; 定时器0中断服程序, 用于数码管的动态扫描
PUSH ACC
PUSH PSW
PUSH AR0
MOV TH0,#0FCH
MOV TL0,#017H
MOV P2,#0FFH
MOV A,#DIS_BUF
ADD A,DIS_INDEX
MOV R0,A
MOV A,@R0
MOV P0,A
MOV P2,DIS_DIGIT
MOV A,DIS_DIGIT
RL A
MOV DIS_DIGIT,A
INC DIS_INDEX
MOV R5 , DIS_INDEX
CJNE R5,#08H,TT
MOV DIS_INDEX ,#00H
MOV DIS_DIGIT,#0FEH

TT: POP AR0
POP PSW
POP ACC
RETI

TIMER1:
; 定时器1中断服务程序, 产生时基信号10ms
PUSH PSW
PUSH ACC
PUSH B
PUSH DPH
PUSH DPL
MOV TH1,#0DCH
MOV TL1,#00H
INC SEC100
MOV A,SEC100
CJNE A, #100, END_TIMER1
MOV SEC100,#00H
LCALL DEC_SEC
END_TIMER1:
POP DPL
POP DPH
POP B
POP ACC
POP PSW
RETI ;

DEC_SEC:
DEC SEC
MOV A ,MIN
JNZ OBTAIN
CPL P3.6
MOV A ,SEC
JNZ OBTAIN
MOV BUF_SEC_L,#0C0H
CLR TR1
CLR ET1
BEEP_BL: MOV R3,#10
MOV R2,#200
MAIN11:
CPL p3.7
LCALL DELAY500
LCALL DELAY500
DJNZ R2,MAIN11

CPL p3.6
LCALL DELAY500
LCALL DELAY500
LCALL DELAY500
MOV R2,#200
MAIN21:
CPL p3.7
LCALL DELAY500
DJNZ R2,MAIN21
DJNZ R3,MAIN11
LJMP OBTAIN
OBTAIN:
MOV A,SEC
CJNE A, #255,UPDATE_SEC

MOV SEC,#59
LCALL DEC_MIN
UPDATE_SEC:
MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV BUF_SEC_H,A
MOV A,SEC
MOV B,#10
DIV AB
MOV A,B
MOVC A,@A+DPTR
MOV BUF_SEC_L,A
RET
DEC_MIN:
DEC MIN
MOV A,MIN
CJNE A, #255, UPDATE_MIN
MOV MIN,#00H
UPDATE_MIN:
MOV A,MIN
MOV B,#10
DIV AB ; A = MIN / 10
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV BUF_MIN_H,A

MOV A,MIN
MOV B,#10
DIV AB
MOV A,B
MOVC A,@A+DPTR
MOV BUF_MIN_L,A
RET
RET

; 中断INT0服务程序
INT_0:
PUSH PSW
PUSH ACC
PUSH B
PUSH DPH
PUSH DPL
JB k1,RKEY1
MOV R7,#30
LCALL DELAYMS
JB k1,RKEY1
LJMP KP1
RKEY1 :JB k2,RKEY2
MOV R7,#30
LCALL DELAYMS
JB k2,RKEY2
LJMP KP2
RKEY2 :JB k3,RKEY3
MOV R7,#30
LCALL DELAYMS
JB k3,RKEY3
LJMP KP3
RKEY3 : JB k4,RKEY4
MOV R7,#30
LCALL DELAYMS
JB k4,RKEY4
LJMP KP4
RKEY4: LJMP KP5
KP1: LCALL BEEP_BL001
INC CONVERT
MOV A,CONVERT
CJNE A,#0AH,KP5
MOV CONVERT ,#00H
INC CONVERT+1
MOV A,CONVERT+1
CJNE A,#0AH,KP5
MOV CONVERT+1,#00H
LJMP KP5
KP2: LCALL BEEP_BL001
DEC CONVERT
MOV A,CONVERT
CJNE A,#255,KP5
MOV CONVERT,#09H
DEC CONVERT+1
MOV A,CONVERT+1
CJNE A,#255,KP5
MOV CONVERT+1,#09H
LJMP KP5
KP3: LCALL BEEP_BL001
INC CONVERT+2
MOV A,CONVERT+2
CJNE A,#0AH,KP5
MOV CONVERT+2 ,#00H
INC CONVERT+3
MOV A,CONVERT+3
CJNE A,#0AH,KP5
MOV CONVERT+3,#00H
LJMP KP5
KP4: LCALL BEEP_BL001
DEC CONVERT+2
MOV A,CONVERT+2
CJNE A,#255,KP5
MOV CONVERT+2 ,#09H
DEC CONVERT+3
MOV A,CONVERT+3
CJNE A,#255,KP5
MOV CONVERT+3,#09H
LJMP KP5
KP5:LCALL CONVETER
POP DPL
POP DPH
POP B
POP ACC
POP PSW
RETI

DELAYMS:
; 延时子程序

DLY_LP1:
MOV R6,#185
DLY_LP2:
NOP
NOP
NOP
DJNZ R6,DLY_LP2
DJNZ R7,DLY_LP1
END_DLYMS:
RET
;蜂鸣器响一声子程序
BEEP_BL001: MOV R3,#1
PUTOFF: ;
MOV R2,#30
MAIN11001:
CPL p3.7
LCALL DELAY500
LCALL DELAY500
DJNZ R2,MAIN11001
DJNZ R3,PUTOFF
RET
;显示缓冲区代码转码子程序
CONVETER:
MOV A,CONVERT
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV DIS_BUF+7,A
MOV A,CONVERT+1
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV DIS_BUF+6,A
MOV A,CONVERT+2
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV DIS_BUF+5,A
MOV A,CONVERT+3
MOV DPTR,#DIS_CODE
MOVC A,@A+DPTR
MOV DIS_BUF+4,A
RET

;查表指令
DIS_CODE:
DB 0C0H
DB 0F9H
DB 0A4H
DB 0B0H
DB 099H
DB 092H
DB 082H
DB 0F8H
DB 080H
DB 090H
DB 0FFH
END

回答2:

C语言本身允许内联汇编,直接写C语言程序就可以。
C语言和汇编本身结合的比较紧,多看看C语言编译器手册,上面一般都有怎么和汇编混合。
写内联汇编要注意C编译器需要的寄存器需要保护。

梦想之所以被称为梦想,就是在于它是要不断追逐的。

回答3:

自己改吧 第151行 MOV A,MIN L 改为 MOV A, MIN ; L 就可以了
还有 最后面 ; 查表指令 前面加 ;

回答4:

第132行 MOV A,MIN L 改为 MOV A, MIN

回答5:

Keil默认是不生成HEX文件的,需要勾选