ORG 0000H
AJMP PLAY
ORG 001BH
AJMP JONG
PLAY: MOV P1, #0FFH: 程序初始化
MOV P2, #00H
MOV 70H, #00H
MOV 71H, #00H
MOV 72H, #00H
MOV 73H, #00H
MOV 74H, #00H
MOV 75H, #00H
MOV 76H, #00H
MOV 77H, #00H
MOV R1, #00H
MOV R2, #00H
MOV TMOD, #50H
MOV TL1, #0FFH
MOV TH1, #0FFH
SETB TR1
SETB ET1
SETB EA
;////////////////////////////////////////////////////////////////////////
MAIN: MOV SP, #80H;
ACALL S0; 调用运行子程序
ACALL S1; 调用停止子程序
ACALL S2; 调用个位数按键子程序
ACALL S3; 调用十位数按键子程序
ACALL S4; 调用百位数按键子程序
ACALL S5; 调用千位数按键子程序
ACALL ESJJ;调用显示延时子程序
AJMP MAIN; 返回主程序
;////////////////////////////////////////////////////////////////////////
S0: JB P1.0, S01; 运行按键子程序
SETB P2.0;如果按键1.0为0,则置位2.0
S01: RET
;///////////////////////////////////////////////////////////////////////
S1: JB P1.1, S11;停止按键子程序
CLR P2.0;如果按键1.1为0,则置位2.0
S11: RET
;//////////////////////////////////////////////////////////////////////
S2: JB P1.2, S23;个位数按键子程序
MOV A, 60H;
CJNE A, #09H, S21;个位数是否小于9,小于加1
MOV 60H, #00H;大于清0
AJMP S210;
S21: INC 60H;
S210: JB P1.6, S211;判断此数为长度数还是数量数
MOV 70H, 60H;数量数送到70H单元
AJMP S22;
S211: MOV 74H, 60H;
ACALL K11;长度数送到74H单元
S22: ACALL DL调用按键延时子程序
S23: RET
;/////////////////////////////////////////////////////////////////////
S3: JB P1.3, S33;十位按键子程序
MOV A, 61H;
CJNE A, #09H, S31;
MOV 61H, #00H;
AJMP S310;
S31: INC 61H;
S310: JB P1.6, S311;
MOV 71H, 61H;
AJMP S32;
S311: MOV 75H, 61H;
ACALL K11;
S32: ACALL DL
S33: RET
;////////////////////////////////////////////////////////////////////
S4: JB P1.4, S43;百位按键子程序
MOV A, 62H;
CJNE A, #09H, S41;
MOV 62H, #00H;
AJMP S410;
S41: INC 62H;
S410: JB P1.6, S411;
MOV 72H, 62H;
AJMP S42;
S411: MOV 76H, 62H;
ACALL K11;
S42: ACALL DL;
S43: RET
;////////////////////////////////////////////////////////////////////
S5: JB P1.5, S53;千位按键子程序
MOV A, 63H;
CJNE A, #09H, S51;
MOV 63H, #00H;
AJMP S510;
S51: INC 63H;
S510: JB P1.6, S511;
MOV 73H, 63H;
AJMP S52;
S511: MOV 77H, 63H;
ACALL K11;
S52: ACALL DL;
S53: RET
;////////////////////////////////////////////////////////////////////
长度数BCD转二进制码子程序
;转换数为77H(千位)76H(百位)75H(十位)74H(个位)
;结果存于67H(H)66H(L)
K11: MOV A, #38H;千位数转
MOV B, 77H;
MUL AB
MOV 67H, B;
MOV 66H, A;
MOV A, #03H;
MOV B, 77H;
MUL AB
ADD A, 67H;
MOV 67H, A;
;------------------------------
MOV A, #64H;百位数转
MOV B, 76H;
MUL AB
ADD A, 66H
MOV 66H, A;
MOV A, B;
MOV B, 77H;
ADDC A, 67H;
MOV 67H, A;
;------------------------------
MOV A, #0AH;十位数转
MOV B, 75H;
MUL AB
ADD A, 66H;
MOV 66H, A;
MOV A, B;
ADDC A, 67H;
MOV 67H, A;
;------------------------------
MOV A, 74H;个位数转
ADD A, 66H;
MOV 66H, A;
MOV A, #00H;
ADDC A, 67H;
MOV 67H, A;
RET
;////////////////////////////////////////////////////////////////////////////////////////////
;中断子程序
JONG: CLR P2.0;启动剪线开关
ACALL DL;
ACALL DL;
SETB P2.1;
;--------------------
MOV A, #0FFH;长度数送到计数子程序
CLR C;
SUBB A, 66H;
MOV TL1, A;
MOV A, #0FFH;
SUBB A, 67H;
MOV TH1, A;
;--------------------
ACALL DL;延时
ACALL DL;
ACALL DL;
ACALL DL;
CLR P2.1;关闭剪线开关
ACALL DL;
ACALL BCD0;数量减一子程序
RETI;
;////////////////////////////////////////////////////////////////////////////////////////////
;数量数减一子程序
;被减数为73H(千位)72H(百位)71H(十位)70H(个位)
BCD0: MOV A, 70H;
JZ BCD1;
DEC 70H;
AJMP BCD5;
;-------------------------------
BCD1: MOV A, 71H;
JZ BCD2;
DEC 71H;
MOV 70H, #09H;
AJMP BCD5;
;-------------------------------
BCD2: MOV A, 72H;
JZ BCD3;
DEC 72H;
MOV 71H, #09H;
MOV 70H, #09H;
AJMP BCD5;
;-------------------------------
BCD3: MOV A, 73H;
JZ BCD4;
DEC 73H;
MOV 72H, #09H;
MOV 71H, #09H;
MOV 70H, #09H;
AJMP BCD5;
;-------------------------------
BCD4: CLR P2.0
AJMP BCDQ;
;-------------------------------
BCD5: SETB P2.0
BCDQ: RET
;////////////////////////////////////////////////////////////////////////////////////////////
DL: MOV 68H, #20;按键延时子程序
DL1: ACALL ESJJ;
DEC 68H;
MOV A, 68H;
CJNE A, #00H, DL1;
RET
;////////////////////////////////////////////////////////////////////////////////////////////
ESJJ: JB P1.6, ESJJ1;显示子程序
MOV 60H, 70H;
MOV 61H, 71H;
MOV 62H, 72H;
MOV 63H, 73H;
AJMP ESJJ2
ESJJ1: MOV 60H, 74H;
MOV 61H, 75H;
MOV 62H, 76H;
MOV 63H, 77H;
ESJJ2: MOV A, 60H;
ADD A, #30H;
MOVC A, @A+PC;
CLR P2.3
MOV P0, A;
SETB P2.6;
ACALL DDY;
MOV A, 61H;
ADD A, #23H
MOVC A, @A+PC;
CLR P2.6;
MOV P0, A;
SETB P2.5;
ACALL DDY;
MOV A, 62H;
ADD A, #16H;
MOVC A, @A+PC;
CLR P2.5;
MOV P0, A;
SETB P2.4;
ACALL DDY;
MOV A, 63H;
ADD A, #09H;
MOVC A, @A+PC;
CLR P2.4;
MOV P0, A;
SETB P2.3;
ACALL DDY;
RET
BS: DB 01H;
DB 0E7H;
DB 0C8H;
DB 0C2H;
DB 0A6H;
DB 92H;
DB 90H;
DB 87H;
DB 80H;
DB 82H;
DDY: MOV R1, #20
DDY1: MOV R2, #80
DDY2: DJNZ R2, DDY2;
DJNZ R1, DDY1;
RET
END