|
- FREL EQU 20H ;频率地位缓存
- FREM EQU 21H ;频率中位缓存
- FREH EQU 22H ;频率高位缓存
- DISPBUF EQU 4FH ;显示缓冲区首地址,地址高低等于显示位高低顺序。
- TEMP EQU 47H
- FRETMP EQU 46H ;频率高位计数器
- BCDH EQU 43H ;压缩BCD码缓存入口,H\M1\M0\L分别对应由高到低4位压缩BCD码
- BCDM1 EQU 42H
- BCDM0 EQU 41H
- BCDL EQU 40H
- ;===========================主程序开始
- ORG 00H
- LJMP START
- ORG 0BH
- LJMP INT_T0
- ORG 1BH
- LJMP INT_T1
- START: MOV SP,#60H
- MOV DPTR,#TAB
- MOV FREL,#0
- MOV FREM,#0
- MOV FREH,#12
- MOV TEMP,#16
- MOV TMOD,#01010001B ;定时器1:计数器模式1,定时器0:定时器,模式1
- MOV TH0,#0
- MOV TL0,#0
- SETB TR0
- setb tr1
- SETB ET0
- setb et1
- SETB EA
- setb PT0
- clr PT1
- LOOP: ACALL BCD
- ACALL SEARCHTAB
- ACALL DISP
- SJMP LOOP
- ;*********************************
- INT_T0: CPL P3.0 ;P3.0端口发送脉冲方波,供自检
- DJNZ TEMP,INTDONE ;tmep减1
- mov TL0,#191 ;共循环16次,第一次送10000000us的尾数,该数可以根据时钟偏差以us为单位调整,尾数这次中断会对整个1秒定时产生误差也可以在这里调整,
- MOV TH0,#0BDH ;尾数计算公式:65536-(1000000-65536X15)= 48576=BDCOH
- MOV TEMP,#16 ;重置temp
- MOV FREL,TL1 ;保存频率数据低位
- MOV FREM,TH1 ;保存频率数据中位
- MOV FREH,FRETMP ;保存频率数据高位
- MOV TL1,#0 ;清除计数器1,重新开始
- MOV TH1,#0
- MOV FRETMP,#0
- INTDONE:RETI
- ;*********************************
- INT_T1: INC FRETMP ;溢出,则给频率高位计数器+1
- RETI
- ;*********************************
- SEARCHTAB:mov r0,#BCDH ;压缩BCD码拆位查表送缓冲区
- MOV R1,#DISPBUF
- mov R7,#4
- AAA: MOV A,@R0
- SWAP A
- ANL A,#00001111B
- MOVC A,@A+DPTR
- MOV @R1,A
- DEC R1
- MOV A,@R0
- ANL A,#00001111B
- MOVC A,@A+DPTR
- MOV @R1,A
- DEC R1
- DEC R0
- DJNZ R7,AAA
- RET ;到这里,显示缓冲区已经是7段码了
- ;*********************************
- ;输出显示子程序
- DISP: MOV R0,#DISPBUF
- MOV R1,#8
- MOV A,#01111111B
- DISP1: MOV P2,#0FFH ;关闭位选
- MOV P1,@R0
- MOV P2,A
- DEC R0
- RR A
- ACALL DELY1MS
- DJNZ R1,DISP1
- RET
- ;*********************************
- DELY1MS:MOV R6,#10
- D1: MOV R7,#49
- DJNZ R7,$
- DJNZ R6,D1
- RET
- ;**********************************
- ;2位半16进制转4位压缩BCD码,用的是非标准方式,线性执行未用任何转移指令,感兴趣的自行分析,本程序效率可以比经典BCD转码程序提高65%
- BCD:
- CLR A
- MOV BCDH,A
- MOV BCDM1,A
- MOV BCDM0,A
- MOV BCDL,A
- MOV C,FREH.3
- ADDC A,ACC
- MOV C,FREH.2
- ADDC A,ACC
- MOV C,FREH.1
- ADDC A,ACC
- MOV C,FREH.0
- ADDC A,ACC
- DA A
- MOV C,FREM.7
- ADDC A,ACC
- DA A
- MOV C,FREM.6
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- XCH A,BCDL
- MOV C,FREM.5
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- XCH A,BCDL
- MOV C,FREM.4
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- XCH A,BCDL
- MOV C,FREM.3
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDL
- MOV C,FREM.2
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- RLC A
- XCH A,BCDL
- MOV C,FREM.1
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDL
- RLC A
- XCH A,BCDM0
- MOV C,FREM.0
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- RLC A
- ;***********************
- XCH A,BCDL
- MOV C,FREL.7
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- MOV C,FREL.6
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- MOV C,FREL.5
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- MOV C,FREL.4
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- MOV C,FREL.3
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- MOV C,FREL.2
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- MOV C,FREL.1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- MOV C,FREL.0
- ADDC A,ACC
- DA A
- XCH A,BCDM0
- ADDC A,ACC
- DA A
- XCH A,BCDM1
- ADDC A,ACC
- DA A
- XCH A,BCDL
- ADDC A,ACC
- DA A
- MOV BCDH,A
- MOV A,BCDL
- XCH A,BCDM1
- XCH A,BCDM0
- MOV BCDL,A
- RET ;嘿嘿调试通过
- ;======================================
- TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
- END
复制代码 |
|