发表于:2005/5/30 22:05:00
#0楼
ORG 0000H
AJMP INITIAL
ORG 0030H
;LED INITIAL 0 ******************************
GENCLK: SETB P0.0
NOP
CPL P0.0
RET
INITIAL:
BEGIN1 EQU 06AH
BEGIN2 EQU 0A6H
RIGHT1 EQU 0ABH
RIGHT2 EQU 68H
RIGHT3 EQU 0AEH
WRONG1 EQU 0ABH
WRONG2 EQU 37H
WRONG3 EQU 0AEH
MAIN: MOV R7,#09H
CPL P0.0
MOV P1,#10H
MOV P2,#0C0H
ACALL GENCLK
MOV R0,#20H
PP: MOV P1,R0
ACALL GENCLK
INC R0
DJNZ R7,PP
;RECEIVE DATA*********************************
MOV TMOD,#20H ;T1工作于方式2
MOV TL1,#0F3H ;设置时间常数初值
MOV TH1,#0F3H
SETB TR1 ;启动T1
MOV SCON,#50H ;设置串行口工作在方式1接收
WAIT: ACALL IN
CJNE A,#BEGIN1,WRONG ;校验数据是否出错
ACALL IN
CJNE A,#BEGIN2,WRONG ;校验数据是否出错
MOV R0,#20H
MOV R7,#08H ;增加数据校验和
LOOP: ACALL IN
MOV @R0,A ;将A中的数据存入数据寄存器
INC R0 ;数据入口地址加1
DJNZ R7,LOOP ;R7不等于0时继续执行LOOP
AJMP VERIFY ;跳转到VERIFY
IN: JNB RI,$ ;等待一帧接收完毕
CLR RI ;RI清零
MOV A,SBUF ;接收到的数据送A
RET
;VERIFY DATA*************************************
VERIFY: MOV R0,#20H
MOV A,@R0 ;A存放数据第一字节20H数据
INC R0
ADD A,@R0 ;A存放数据一,二字节和
INC R0
ADD A,@R0 ;A存放数据前三个字节和
INC R0
ADD A,@R0
INC R0
ADD A,@R0
INC R0
ADD A,@R0
INC R0
ADD A,@R0
MOV 50H,A
INC R0
MOV A,@R0
CJNE A,50H,WRONG ;校验前7个数据和与第八个数据是否相等
RIGHT: MOV A,#RIGHT1 ;若接收正确,发回ABH,68H,AEH
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#RIGHT2
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#RIGHT3
MOV SBUF,A
JNB TI,$
CLR TI
AJMP DISPLAY
WRONG: MOV A,#WRONG1 ;若接收错误,发回ABH,37H,AEH
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#WRONG2
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#WRONG3
MOV SBUF,A
JNB TI,$
CLR TI
AJMP WAIT
;DISPLAY DATA************************************
DISPLAY: MOV R0,#20H
MOV A, @R0
MOV B,#0AH
DIV AB ;将A除以10
MOV 32H,B ;将余数存入32H
MOV B,#0AH ;将10赋给累加器B
DIV AB ;将A除以10
MOV 31H,B ;将余数存入31H
MOV 30H,A ;将除得的商存入30H
INC R0 ;RO加1
MOV A,@R0
MOV B,#0AH
DIV AB
MOV 35H,B
MOV B,#0AH
DIV AB
MOV 34H,B
MOV 33H,A; 重复上面的过程
INC R0
MOV 36H,@R0 ;将22H内的数据赋给36H
INC R0
MOV A,@R0 ;将23H内的数据赋给累加器A
MOV B,#0AH
DIV AB ;A除以10
MOV 38H,B ;将余数赋给38H
MOV 37H,A ;将商赋给37H
INC R0
MOV 39H,@R0 ;将24H内的数据赋给39H
INC R0
MOV 3AH,@R0 ;将25H内的数据赋给3AH
INC R0
MOV 3BH,@R0 ;将26H内的数据赋给3BH
MOV A,30H ;将30H内的数据赋给累加器A ;LED DISPLAY CODE**
MOV DPTR,#WCODE ;
MOVC A,@A+DPTR
MOV P1,#10H
MOV P2,A
ACALL GENCLK
MOV R7,#09H
MOV R0,#31H
MOV R1,#20H
XX: MOV A,@R0
MOVC A,@A+DPTR
MOV P1,R1
MOV P2,A
ACALL GENCLK
INC R0
INC R1
DJNZ R7,XX
MOV P1,#2EH ;WAVE CODE**
MOV R0,3AH
MOV A,R0
ANL A,#10000000B
RR A
MOV B,A
MOV A,R0
ANL A,#01000000B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000001B
RL A
RL A
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000010B
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000100B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00001000B
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00010000B
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00100000B
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A ;位颠倒
CPL A
MOV P2,A
ACALL GENCLK
MOV P1,#2FH ;CONTROL CODE**
MOV R0,3BH
MOV A,R0
ANL A,#00000001B
RL A
RL A
RL A
RL A
RL A
RL A
RL A
MOV B,A
MOV A,R0
ANL A,#00000010B
RL A
RL A
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000100B
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00001000B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00010000B
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00100000B
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#01000000B
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#10000000B
RR A
RR A
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A ;位颠倒
CPL A
MOV P2,A
ACALL GENCLK ;改动:数码管取反显示
;再改动:数据高低位颠倒显示
;DIFFERENTIAL OUTPUT***************************************
MOV P1,#29H ;本振
MOV P2,20H
ACALL GENCLK
MOV P1,#2AH ;STC
MOV P2,21H
ACALL GENCLK
MOV A,23H
ANL A,#3FH ;屏蔽高2位
MOV B,A
MOV A,25H
ANL A,#00000011B
RL A
RL A
RL A
RL A
RL A
RL A
ADD A,B ;构成8位
MOV P1,#2BH
MOV P2,A
ACALL GENCLK
MOV A,25H
ANL A,#00111100B
RR A
RR A
MOV B,A
MOV A,26H
ANL A,#00001111B
RL A
RL A
RL A
RL A
ADD A,B ;构成8位
MOV P1,#2CH
MOV P2,A
ACALL GENCLK
MOV A, 25H
ANL A,#11000000B
RR A
RR A
MOV B,A
MOV A,26H
ANL A,#11110000B
RR A
RR A
RR A
RR A
ADD A,B ;构成8位
MOV P1,#2DH
MOV P2,A
ACALL GENCLK
AJMP WAIT
WCODE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
谁知道这是干什么用的?
AJMP INITIAL
ORG 0030H
;LED INITIAL 0 ******************************
GENCLK: SETB P0.0
NOP
CPL P0.0
RET
INITIAL:
BEGIN1 EQU 06AH
BEGIN2 EQU 0A6H
RIGHT1 EQU 0ABH
RIGHT2 EQU 68H
RIGHT3 EQU 0AEH
WRONG1 EQU 0ABH
WRONG2 EQU 37H
WRONG3 EQU 0AEH
MAIN: MOV R7,#09H
CPL P0.0
MOV P1,#10H
MOV P2,#0C0H
ACALL GENCLK
MOV R0,#20H
PP: MOV P1,R0
ACALL GENCLK
INC R0
DJNZ R7,PP
;RECEIVE DATA*********************************
MOV TMOD,#20H ;T1工作于方式2
MOV TL1,#0F3H ;设置时间常数初值
MOV TH1,#0F3H
SETB TR1 ;启动T1
MOV SCON,#50H ;设置串行口工作在方式1接收
WAIT: ACALL IN
CJNE A,#BEGIN1,WRONG ;校验数据是否出错
ACALL IN
CJNE A,#BEGIN2,WRONG ;校验数据是否出错
MOV R0,#20H
MOV R7,#08H ;增加数据校验和
LOOP: ACALL IN
MOV @R0,A ;将A中的数据存入数据寄存器
INC R0 ;数据入口地址加1
DJNZ R7,LOOP ;R7不等于0时继续执行LOOP
AJMP VERIFY ;跳转到VERIFY
IN: JNB RI,$ ;等待一帧接收完毕
CLR RI ;RI清零
MOV A,SBUF ;接收到的数据送A
RET
;VERIFY DATA*************************************
VERIFY: MOV R0,#20H
MOV A,@R0 ;A存放数据第一字节20H数据
INC R0
ADD A,@R0 ;A存放数据一,二字节和
INC R0
ADD A,@R0 ;A存放数据前三个字节和
INC R0
ADD A,@R0
INC R0
ADD A,@R0
INC R0
ADD A,@R0
INC R0
ADD A,@R0
MOV 50H,A
INC R0
MOV A,@R0
CJNE A,50H,WRONG ;校验前7个数据和与第八个数据是否相等
RIGHT: MOV A,#RIGHT1 ;若接收正确,发回ABH,68H,AEH
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#RIGHT2
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#RIGHT3
MOV SBUF,A
JNB TI,$
CLR TI
AJMP DISPLAY
WRONG: MOV A,#WRONG1 ;若接收错误,发回ABH,37H,AEH
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#WRONG2
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,#WRONG3
MOV SBUF,A
JNB TI,$
CLR TI
AJMP WAIT
;DISPLAY DATA************************************
DISPLAY: MOV R0,#20H
MOV A, @R0
MOV B,#0AH
DIV AB ;将A除以10
MOV 32H,B ;将余数存入32H
MOV B,#0AH ;将10赋给累加器B
DIV AB ;将A除以10
MOV 31H,B ;将余数存入31H
MOV 30H,A ;将除得的商存入30H
INC R0 ;RO加1
MOV A,@R0
MOV B,#0AH
DIV AB
MOV 35H,B
MOV B,#0AH
DIV AB
MOV 34H,B
MOV 33H,A; 重复上面的过程
INC R0
MOV 36H,@R0 ;将22H内的数据赋给36H
INC R0
MOV A,@R0 ;将23H内的数据赋给累加器A
MOV B,#0AH
DIV AB ;A除以10
MOV 38H,B ;将余数赋给38H
MOV 37H,A ;将商赋给37H
INC R0
MOV 39H,@R0 ;将24H内的数据赋给39H
INC R0
MOV 3AH,@R0 ;将25H内的数据赋给3AH
INC R0
MOV 3BH,@R0 ;将26H内的数据赋给3BH
MOV A,30H ;将30H内的数据赋给累加器A ;LED DISPLAY CODE**
MOV DPTR,#WCODE ;
MOVC A,@A+DPTR
MOV P1,#10H
MOV P2,A
ACALL GENCLK
MOV R7,#09H
MOV R0,#31H
MOV R1,#20H
XX: MOV A,@R0
MOVC A,@A+DPTR
MOV P1,R1
MOV P2,A
ACALL GENCLK
INC R0
INC R1
DJNZ R7,XX
MOV P1,#2EH ;WAVE CODE**
MOV R0,3AH
MOV A,R0
ANL A,#10000000B
RR A
MOV B,A
MOV A,R0
ANL A,#01000000B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000001B
RL A
RL A
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000010B
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000100B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00001000B
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00010000B
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00100000B
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A ;位颠倒
CPL A
MOV P2,A
ACALL GENCLK
MOV P1,#2FH ;CONTROL CODE**
MOV R0,3BH
MOV A,R0
ANL A,#00000001B
RL A
RL A
RL A
RL A
RL A
RL A
RL A
MOV B,A
MOV A,R0
ANL A,#00000010B
RL A
RL A
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00000100B
RL A
RL A
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00001000B
RL A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00010000B
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#00100000B
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#01000000B
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A
MOV A,R0
ANL A,#10000000B
RR A
RR A
RR A
RR A
RR A
RR A
RR A
ADD A,B
MOV B,A ;位颠倒
CPL A
MOV P2,A
ACALL GENCLK ;改动:数码管取反显示
;再改动:数据高低位颠倒显示
;DIFFERENTIAL OUTPUT***************************************
MOV P1,#29H ;本振
MOV P2,20H
ACALL GENCLK
MOV P1,#2AH ;STC
MOV P2,21H
ACALL GENCLK
MOV A,23H
ANL A,#3FH ;屏蔽高2位
MOV B,A
MOV A,25H
ANL A,#00000011B
RL A
RL A
RL A
RL A
RL A
RL A
ADD A,B ;构成8位
MOV P1,#2BH
MOV P2,A
ACALL GENCLK
MOV A,25H
ANL A,#00111100B
RR A
RR A
MOV B,A
MOV A,26H
ANL A,#00001111B
RL A
RL A
RL A
RL A
ADD A,B ;构成8位
MOV P1,#2CH
MOV P2,A
ACALL GENCLK
MOV A, 25H
ANL A,#11000000B
RR A
RR A
MOV B,A
MOV A,26H
ANL A,#11110000B
RR A
RR A
RR A
RR A
ADD A,B ;构成8位
MOV P1,#2DH
MOV P2,A
ACALL GENCLK
AJMP WAIT
WCODE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
谁知道这是干什么用的?