设计一个带有控制功能的脉冲发生器/计数器系统,脉冲发生器发出周期为2秒的方波(提示:可由P3.0口输出,用发光二极管显示);被计数脉冲由T0口输入,所记录的脉冲数以十进制形式在数码管显示(至少应可记录256个脉冲);设两个按键,一个启动脉冲发生器,一个启动记数,(按一次启动,再按一次停止),不启动时,发光管灭,数码管显示学号。数码管为共阴极;KEY/LED_CS与CS0连线,则段地址为:8004H,位地址为:8002H
ORG 0000HAJMP MAINORG 0003HAJMP INT0ORG 0013HAJMP INT1ORG 001BHAJMP T1 ORG 0030HMAIN:MOV TMOD,#16H ;T0计数,T1计时 MOV TH0,#00H MOV TL0,#00H MOV TH1,#0EFH MOV TL1,#0CH SETB EA SETB EX0 SETB EX1 SETB ET0 SETB ET1 SETB IT0 SETB IT1 CLR TR0 SETB TR1 ;SETB PX0 CLR P3.1 MOV R7,#100 SJMP $ ORG 0100HINT0:JB P3.1,AA ;脉冲开关 MOV TH1,#0EFH MOV TL1,#0CH MOV R7,#100 SETB P3.1 ;用3.1口作为判断标志 ;SETB TR1 RETI AA:CLR P3.1 RETI ORG 0150HINT1:JB TR0,BB ;计数开关 MOV TH0,#00H ;开始计数 MOV TL0,#00H MOV TH1,#0EFH MOV TL1,#0CH SETB TR0 RETI BB:CLR TR0 ;关闭计数器显示学号 MOV TH0,#00H MOV TL0,#00H T1:MOV TH1,#0EFH MOV TL1,#0CH JX:JNB TR0,XH1 DY:ACALL H_BCD ACALL JISHU ACALL DISP DJNZ R7,GORET1 MOV R7,#100 JNB P3.1,DY CPL P3.0 ;用3.0作为脉冲发生器 GORET1:RETI H_BCD:MOV A,TL0 MOV B,#100 DIV AB MOV 32H,A MOV A,#10 XCH A,B DIV AB MOV 31H,A MOV 30H,B RET JISHU:MOV R2,#3 ;R2计数,让后三个数码管都显示 MOV R0,#30HFT:MOV A,@R0 ;将所计数转换成数码管显示形式 MOV DPTR,#TAB MOVC A,@A+DPTR MOV @R0,A INC R0 DJNZ R2,FT RET DISP:MOV DPTR,#8002H MOV A,#01H MOVX @DPTR,A MOV DPTR,#8004H MOV A,30H MOVX @DPTR,A ACALL DLAY MOV DPTR,#8002H MOV A,#02H MOVX @DPTR,A MOV DPTR,#8004H MOV A,31H MOVX @DPTR,A ACALL DLAY MOV DPTR,#8002H MOV A,#04H MOVX @DPTR,A MOV DPTR,#8004H MOV A,32H MOVX @DPTR,A ACALL DLAY RET XH1:MOV DPTR,#8002H MOV A,#01H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#06H MOVX @DPTR,A ACALL DLAY XH2:MOV DPTR,#8002H MOV A,#02H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#66H MOVX @DPTR,A ACALL DLAY XH3:MOV DPTR,#8002H MOV A,#04H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#5BH MOVX @DPTR,A ACALL DLAY XH4:MOV DPTR,#8002H MOV A,#08H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#5BH MOVX @DPTR,A ACALL DLAY XH5:MOV DPTR,#8002H MOV A,#10H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#6FH MOVX @DPTR,A ACALL DLAY XH6:MOV DPTR,#8002H MOV A,#20H MOVX @DPTR,A MOV DPTR,#8004H MOV A,#3FH MOVX @DPTR,A ACALL DLAY DJNZ R7,GORET2 MOV R7,#100 JNB P3.1,XH1 CPL P3.0 ;用3.0作为脉冲发生器 GORET2:RETI RETI DLAY:MOV R6,#1000;延时子程序 DJNZ R6,$ RET