单片机源程序如下:
- TEMP EQU 20H
- NUMB EQU 25H
- ORG 0000H
- LJMP MAIN
- ORG 0003H
- LJMP INTX0 ;外部中断0
- ORG 0030H
- ;======================================
- ;主程序
- MAIN:
- MOV R0,#30H
- SETB PT0 ;设置定时器0为高优先级
- SETB IT0 ;INT0为下降沿触发
- SETB EA ;开系统中断
- SETB EX0 ;开外部中断0
-
- MOV DPTR,#7FF8H ;DPTR指向0808通道0
- MOV A,#00H
- MOVX @DPTR,A ;端口地址送DPTR,P2.7=0,锁定通道0并启动转换
- WAIT:
- SJMP [ DISCUZ_CODE_3 ]nbsp; ;等待中断
-
- INTX0:
- MOV DPTR,#7FF8H
- MOVX A,@DPTR ;读取A/D转换结果
- MOV NUMB,A ;将结果送到30H
- LCALL CONVERT
- LCALL DISP
- MOV A,#00H
- MOVX @DPTR,A ;重启ADC0808对INT0的转换
- RETI
- DISP:
- MOV R0,#TEMP
- MOV R2,#00H
- DISP1:
- MOV A,R2
- MOV DPTR,#TAB1
- MOVC A,@A+DPTR
- MOV P2,A
- MOV A,@R0
- MOV DPTR,#TAB
- MOVC A,@A+DPTR
- MOV P0,A
- MOV R5,#5
- LCALL DELAY
- INC R0
- INC R2
- CJNE R2,#3,DISP1
- MOV P0,#00H
- RET
-
- CONVERT:
- MOV A,NUMB
- MOV B,#10
- DIV AB
- MOV TEMP+2,B
- MOV B,#10
- DIV AB
- MOV TEMP+1,B
- MOV TEMP,A
- RET
- //延时子程序
- DELAY:
- MOV R6,#1
- DELAY0:
- MOV R7,#100
- DJNZ R7,$
- DJNZ R6,DELAY0
- DJNZ R5,DELAY
- RET
- TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,0BFH,86H,0DBH,0CFH,0E6H,0EDH,0FDH,87H,0FFH,0EFH
- TAB1: DB 0FDH,0FBH,0F7H ;位选信号,后三个数目管
- END
复制代码
|