ADC0809输入电压转成LED灯显示程序
;将输入电压转化成LED灯显示.
;///////////////////////////////////////////
;//定义ADC的连接端口
ad_cs equ P3.6
ad_wr equ P3.2
ad_rd equ P3.7
ad_input_port equ p1
org 0000h
ajmp main
org 0030h
main:
lcall adc_demo
ajmp main
;//==========================================
;// 启动AD转换
;//==========================================
Adc_Start:
clr ad_cs
nop
clr ad_wr
nop
setb ad_wr
nop
setb ad_cs
nop
ret
;//==========================================
;// 读AD转换
;//==========================================
Adc_Read:
MOV ad_input_port,#0ffh
clr ad_cs
nop
clr ad_rd
nop
nop
MOV a,AD_INPUT_PORT
nop
setb ad_rd
nop
setb ad_cs
ret
;//==========================================
;// AD转换读取延时程序,显示读到的数值
;//==========================================
Adc_Demo:
lcall Adc_Start
lcall delay1ms
lcall adc_read
call l1
MOV r1,#100
disp1:
call disp
djnz r1,disp1
ret
l1:
MOV b,#10
mul ab
MOV r7,b
MOV r6,a
MOV r5,#00h
MOV r4,#51
lcall chu
MOV a,r6
MOV b,#10
div ab
MOV 31h,a
MOV 30h,b
ret
disp:
MOV p2,#0fdh
MOV dptr,#tab
MOV a,31h
MOV c a,@a+dptr
anl a,#7fh
MOV p0,a
call delay
MOV p2,#0ffh
MOV a,30h
MOV c a,@a+dptr
MOV p2,#0feh
MOV p0,a
call delay
ret
delay:
MOV r6,#10
d1:
MOV r7,#248
djnz r7,$
djnz r6,d1
ret
chu:
MOV a,r5
jnz begin
MOV a,r4
jz over
begin:
clr a
MOV r3,a
MOV r2,a
MOV r1,#10h
div0:
acall rlc4
MOV a,r2
subb a,r4
MOV r0,a
MOV a,r3
subb a,r5
jc next
inc r6
MOV r3,a
MOV a,r0
MOV r2,a
next:
djnz r1,div0
MOV a,r3
rlc a
jc round
MOV a,r2
rlc a
MOV r2,a
MOV a,r3
rlc a
subb a,r5
jc done
jnz round
MOV a,r2
subb a,r4
jc done
round:
acall add1
done:
clr a
ret
over:
MOV a,#0ffh
ret
rlc4:
clr c
MOV a,r6
rlc a
MOV r6,a
MOV a,r7
rlc a
MOV r7,a
MOV a,r2
rlc a
MOV r2,a
MOV a,r3
rlc a
MOV r3,a
ret
add1:
MOV a,r6
add a,#1
MOV r6,a
MOV a,r7
addc a,#0
MOV r7,a
ret
tab:db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h
delay1ms:
MOV r7,#10
tta:
MOV r6,#50
djnz r6,$ ;2us
djnz r7,tta
ret
end