代码里的这部分的意思我不太清除,想请大佬指教一下,谢了
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
----------------------------------------------------------------------------
NAME MABIAO ;定义1602相关管脚
COUNT_IN EQU P3.2 ; 计数脉冲输入端P3.2
en EQU P2.6 ;使能端P2.6
rs EQU P2.7
delayMABIAO SEGMENT CODE ;段名
initMABIAO SEGMENT CODE ;中断初始化
write_1602comMABIAO SEGMENT CODE
write_1602datMABIAO SEGMENT CODE ;液晶写入数据函数
lcd_initMABIAO SEGMENT CODE ;液晶初始化
displayMABIAO SEGMENT CODE ;LCD显示速度函数
mainMABIAO SEGMENT CODE
EXINT0MABIAO SEGMENT CODE
PRtime0MABIAO SEGMENT CODE
DTtime0MABIAO SEGMENT DATA OVERLAYABLE
COMABIAO SEGMENT CODE
BIMABIAO SEGMENT BIT
DTMABIAO SEGMENT DATA
EXTRN CODE (?C?ULDIV) ;无符号长型除法程序 ;
EXTRN CODE (?C?ULCMP) ;无符号长型比较程序
EXTRN CODE (?C_STARTUP)
EXTRN CODE (?C?LMUL) ;长型乘法程序
EXTRN CODE (?C?UIDIV) ;无符号整型除法程序
PUBLIC Velocity
PUBLIC Mileage
PUBLIC count
PUBLIC flag
PUBLIC tab2
PUBLIC tab1
PUBLIC time0
PUBLIC EXINT0
PUBLIC main
PUBLIC display
PUBLIC lcd_init
PUBLIC _write_1602dat
PUBLIC _write_1602com
PUBLIC init
PUBLIC _delay
RSEG DTtime0MABIAO
?time0?BYTE:
L0: DS 1 ;段地址
RSEG BIMABIAO
flag: DBIT 1 ;为flag预留1 BIT的空间
RSEG DTMABIAO ;count定义2 byte存储空间
count: DS 2 ;Mileage定义4 Byte存储空间
Mileage: DS 4 ;Velocity定义4 Byte存储空间
Velocity: DS 4
RSEG delayMABIAO
L?0036:
USING 0
MOV P0,R7
MOV R7,#01H
MOV R6,#00H
LCALL _delay
SETB en
_delay: ;延时函数
USING 0
CLR A
MOV R5,A
MOV R4,A
?C0001:
CLR C
MOV A,R5
SUBB A,R7
MOV A,R4
SUBB A,R6
JNC ?C0007
CLR A
MOV R3,A
MOV R2,A
?C0004:
INC R3
CJNE R3,#00H,?C0029
INC R2
?C0029:
MOV A,R3
XRL A,#06EH
ORL A,R2
JNZ ?C0004
?C0003:
INC R5
CJNE R5,#00H,?C0030
INC R4
?C0030:
SJMP ?C0001
?C0007:
RET
RSEG initMABIAO
init: ;中断初始化程序
SETB IT0 ;INT0负跳变触发
MOV TMOD,#01H ;定时器工作于方式1
MOV TH0,#03CH ;50ms定时初值
MOV TL0,#0B0H ;
SETB EA ;CPU开中断总允许
SETB ET0 ;开定时中断
SETB EX0 ;开外部INTO中断
SETB TR0 ;启动定时
RET
RSEG write_1602comMABIAO
_write_1602com: ;液晶写入指令函数与写入数据模块
USING 0
CLR rs;数据/指令选择置为指令
LCALL L?0036;送入数据
CLR en ;en由高变低,产生下降沿,液晶执行命令
RET
RSEG write_1602datMABIAO
L?0034:
USING 0
CLR A
MOV R1,A
MOV R0,A
L?0035:
LCALL ?C?ULDIV ;无符号长型除法程序;
MOV A,R7
ADD A,#030H
MOV R7,A
_write_1602dat: ;液晶写入数据函数
USING 0
SETB rs
LCALL L?0036
CLR en
RET
RSEG lcd_initMABIAO
lcd_init: ;液晶初始化函数
USING 0
MOV R7,#038H ;设置液晶工作模式,意思:16*2行显示,5*7点阵,8位数据
LCALL _write_1602com
MOV R7,#0CH ;开显示不显示光标
LCALL _write_1602com
MOV R7,#06H ;整屏不移动,光标自动右移
LCALL _write_1602com
MOV R7,#01H ;清显示
LCALL _write_1602com
MOV R7,#080H ;显示固定符号从第一行第1个位置之后开始显示
LCALL _write_1602com
CLR A
MOV R1,A
?C0011:
MOV A,R1
MOV DPTR,#tab1 ;向液晶屏写固定符号部分
MOVC A,@A+DPTR
MOV R7,A
LCALL _write_1602dat
INC R1
CJNE R1,#010H,?C0011
?C0012:
MOV R7,#0C0H
LCALL _write_1602com
CLR A
MOV R1,A
?C0014:
MOV A,R1 ;显示固定符号写入位置,从第2个位置后开始显示
MOV DPTR,#tab2
MOVC A,@A+DPTR
MOV R7,A
LCALL _write_1602dat
INC R1
CJNE R1,#010H,?C0014
?C0017:
RET
RSEG displayMABIAO
display: ;LCD显示速度函数
// 1km/h=100m/0.1h 360s
// 10km/h=100m/0.01h 36s
// 100km/h=100m/0.001h 3.6s
USING 0
MOV R7,#089H
LCALL _write_1602com
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV ;无符号长型除法程序
CLR A
MOV R3,A
MOV R2,A
MOV R1,A
MOV R0,A
CLR C
LCALL ?C?ULCMP ; 无符号长型比较程序
JNZ ?C0018
MOV R7,#020H
SJMP ?C0032
?C0018:
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV
MOV A,R7
ADD A,#030H
MOV R7,A
?C0032:
LCALL _write_1602dat ;调用液晶写入数据函数
?C0019:
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
CLR A
MOV R3,#0AH
MOV R2,A
MOV R1,A
MOV R0,A
LCALL ?C?ULDIV
PUSH AR4
PUSH AR5
PUSH AR6
PUSH AR7
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV
POP AR3
POP AR2
POP AR1
POP AR0
MOV A,R7
ADD A,R3
MOV R7,A
MOV A,R6
ADDC A,R2
MOV R6,A
MOV A,R5
ADDC A,R1
MOV R5,A
MOV A,R4
ADDC A,R0
MOV R4,A
CLR A
MOV R3,A
MOV R2,A
MOV R1,A
MOV R0,A
CLR C
LCALL ?C?ULCMP
JNZ ?C0020
MOV R7,#020H
SJMP ?C0033
?C0020:
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
CLR A
MOV R3,#0AH
MOV R2,A
MOV R1,A
MOV R0,A
LCALL ?C?ULDIV
MOV A,R7
ADD A,#030H ;数字+30得到该数字的LCD1602显示码
MOV R7,A
?C0033:
LCALL _write_1602dat
?C0021:
CLR A
MOV R3,#0AH
MOV R2,A
MOV R1,A
MOV R0,A
MOV R7,Velocity+03H
MOV R6,Velocity+02H
MOV R5,Velocity+01H
MOV R4,Velocity
LCALL ?C?ULDIV
MOV A,R3
ADD A,#030H
MOV R7,A
LCALL _write_1602dat
MOV R7,#0C8H
LCALL _write_1602com
MOV R3,#040H
MOV R2,#042H
MOV R1,#0FH
MOV R0,#00H
MOV R7,Mileage+03H
MOV R6,Mileage+02H
MOV R5,Mileage+01H
MOV R4,Mileage
LCALL L?0035
MOV R3,#040H
MOV R2,#042H
MOV R1,#0FH
MOV R0,#00H
MOV R7,Mileage+03H
MOV R6,Mileage+02H
MOV R5,Mileage+01H
MOV R4,Mileage
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
MOV R3,#0A0H
MOV R2,#086H
MOV R1,#01H
MOV R0,#00H
LCALL L?0035
MOV R7,#0CBH
LCALL _write_1602com
MOV R3,#0A0H
MOV R2,#086H
MOV R1,#01H
MOV R0,#00H
MOV R7,Mileage+03H
MOV R6,Mileage+02H
MOV R5,Mileage+01H
MOV R4,Mileage
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
MOV R3,#010H
MOV R2,#027H
LCALL L?0034
CLR A
MOV R3,#010H
MOV R2,#027H
MOV R1,A
MOV R0,A
MOV R7,Mileage+03H
MOV R6,Mileage+02H
MOV R5,Mileage+01H
MOV R4,Mileage
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
MOV R3,#0E8H
MOV R2,#03H
LCALL L?0034
CLR A
MOV R3,#0E8H
MOV R2,#03H
MOV R1,A
MOV R0,A
MOV R7,Mileage+03H
MOV R6,Mileage+02H
MOV R5,Mileage+01H
MOV R4,Mileage
LCALL ?C?ULDIV
MOV R4,AR0
MOV R5,AR1
MOV R6,AR2
MOV R7,AR3
CLR A
MOV R3,#064H
MOV R2,A
MOV R1,A
MOV R0,A
LCALL ?C?ULDIV
MOV A,R7
ADD A,#030H
MOV R7,A
LJMP _write_1602dat
RSEG mainMABIAO
main: ;主函数
USING 0
LCALL init
LCALL lcd_init ;调用液晶初始化函数
?C0023:
LCALL display
SJMP ?C0023
CSEG AT 00003H ;外部中断0入口地址
LJMP EXINT0
RSEG EXINT0MABIAO
USING 0
EXINT0: ;外部中断函数
PUSH ACC
INC count+01H
MOV A,count+01H
JNZ ?C0031
INC count ;计数脉冲值+1
?C0031:
POP ACC ;出栈
RETI ;外部中断0返回
CSEG AT 0000BH
LJMP time0
RSEG PRtime0MABIAO
USING 0
time0: ;定时器中断函数
PUSH ACC
PUSH B ;入栈保护
PUSH DPH
PUSH DPL
PUSH PSW
MOV PSW,#00H
PUSH AR0
PUSH AR1
PUSH AR2
PUSH AR3
PUSH AR4
PUSH AR5
PUSH AR6
PUSH AR7
USING 0
MOV TH0,#03CH ;重装50ms定时初值
MOV TL0,#0B0H
INC L0 ;每中断一次(L0)+1
MOV A,L0 ; (L0)->A
CLR C
SUBB A,#0AH ;寄存器A中内容与10比较
JC ?C0028 ;不相等则转移至?C0028
MOV L0,#00H ;相等则清零
CLR A ;//Mileage=Mileage+Velocity*500/36;里程m=速度km/h*1000*5/3.6
MOV R7,#0F4H
MOV R6,#01H
MOV R5,A
MOV R4,A
MOV R3,Velocity+03H
MOV R2,Velocity+02H
MOV R1,Velocity+01H
MOV R0,Velocity
LCALL ?C?LMUL
CLR A
MOV R3,#024H
MOV R2,A
MOV R1,A
MOV R0,A
LCALL ?C?ULDIV
MOV A,Mileage+03H
ADD A,R7
MOV Mileage+03H,A
MOV A,Mileage+02H
ADDC A,R6
MOV Mileage+02H,A
MOV A,Mileage+01H
ADDC A,R5
MOV Mileage+01H,A
MOV A,Mileage
ADDC A,R4
MOV Mileage,A
MOV R6,count ; Velocity=count/5;//将100ms内的脉冲数/5
MOV R7,count+01H
MOV R4,#00H
MOV R5,#05H
LCALL ?C?UIDIV ;除法子程序
CLR A
MOV Velocity+03H,R7
MOV Velocity+02H,R6
MOV Velocity+01H,A
MOV Velocity,A
MOV count,A
MOV count+01H,A
?C0028: ;出栈
POP AR7
POP AR6
POP AR5
POP AR4
POP AR3
POP AR2
POP AR1
POP AR0
POP PSW
POP DPL
POP DPH
POP B
POP ACC
RETI ;T0中断返回
RSEG COMABIAO
tab1: ;定义字符串
DB ' ' ,' ' ,'S' ,'p' ,'e' ,'e' ,'d' ,':' ,' ' ,' '
DB ' ' ,' ' ,' ' ,' ' ,'k' ,'m' ,'/' ,'h' ,000H
tab2:
DB 'M' ,'i' ,'l' ,'e' ,'a' ,'g' ,'e' ,':' ,' ' ,' '
DB '.' ,' ' ,' ' ,' ' ,'k' ,'m' ,000H
END
|