…………………………….LCD1602+ADC0832数字电压表(已调试经过)……………………………
rs bit P2.4
rw bit P2.5
e bit P2.6
clk bit P1.3
do bit P1.4
di bit P1.5
cs bit P1.6
com data 60h
dat data 61h
adcb data 62h
adcs data 63h
adcg data 64h
adc data 65h
chx data 66h
org 0000h
sjmp main
org 0030h
main:mov sp,#30h
clr f0
lcall init
s1:lcall adcx
lcall hdc
lcall top
lcall bot
ljmp s1
init:mov com,#00111000b
lcall write_com
mov com,#00001110b
lcall write_com
mov com,#00000110b
lcall write_com
mov com,#00000001b
lcall write_com
ret
adcx: clr a
setb cs
clr clk
clr cs
setb di
setb clk;榜首个脉冲
clr clk
setb clk;第二个脉冲
clr clk
jb p3.0,a1
cpl f0
jnb p3.0,$
a1:mov c,f0
mov di,c
setb clk;第三个脉冲
clr clk
setb clk
setb do
mov r1,#08h
a2:clr clk
nop
mov c,do
rlc a
setb clk
nop
djnz r1,a2
mov adc,a
setb cs
ret
hdc: mov a,adc
mov b,#51
div ab
mov adcb,a
mov a,b
clr c
subb a,#26
mov 00h,c
mov a,b
mov b,#10
mul ab
mov b,#51
div ab
jb 00h,h1
add a,#5
h1:mov adcs,a
mov a,b
clr c
subb a,#26
mov 00h,c
mov a,b
mov b,#10
mul ab
mov b,#51
div ab
jb 00h,h2
add a,#5
h2:mov adcg,a
ret
write_com:clr rs
clr rw
mov p0,com
lcall delay
clr e
setb e
clr e
ret
write_dat:setb rs
clr rw
mov p0,dat
lcall delay
clr e
setb e
clr e
ret
top: mov com,#80h
lcall write_com
mov dptr,#tab1
mov r0,#14
t4:clr a
movc a,@a+dptr
mov dat,a
lcall write_dat
inc dptr
djnz r0,t4
mov dptr,#tab4
mov com,#8eh
lcall write_com
jb f0,t2
mov chx,#00h
sjmp t3
t2:mov chx,#01h
t3:mov a,chx
movc a,@a+dptr
mov dat,a
lcall write_dat
ret
bot: mov com,#0c0h
lcall write_com
mov dptr,#tab2
mov r0,#10
b1:clr a
movc a,@a+dptr
mov dat,a
lcall write_dat
inc dptr
djnz r0,b1
mov com,#0cah
lcall write_com
mov dptr,#tab4
mov a,adcb
movc a,@a+dptr
mov dat,a
lcall write_dat
mov a,#10
movc a,@a+dptr
mov dat,a
lcall write_dat
mov a,adcs
movc a,@a+dptr
mov dat,a
lcall write_dat
mov a,adcg
movc a,@a+dptr
mov dat,a
lcall write_dat
ret
tab1: db “INPUT CHANNEL “
tab2: db ” VOLTAGE: “
tab4: db “0123456789.”
DELAY: ;差错 0us
MOV R6,#13H
DL0:
MOV R5,#82H
DJNZ R5,$
DJNZ R6,DL0
RET
end
……………………………..LCD1602+ADC0832数字电压表(已调试经过)……………………………
#include
#include
#define uchar unsigned char
#define uint unsigned int;
sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6; //LCD1602操控端
sbit cs=P1^6;
sbit di=P1^5;
sbit dox=P1^4;
sbit clk=P1^3;//ADC0832操控端
sbit key=P3^0;//丈量通道挑选按键
uchar code table1[]=”INPUT CHANNEL “; //显现数据表
uchar code table2[]=” VOLTAGE: “;
uchar code table3[]=”0123456789.”;
uchar ge,shi,bai; //显现值存储变量
uchar adc_data; //A/D转化值存储变量
void delay() //差错 0us 5ms延时
{
uchar a,b;
for(b=19;b>0;b–)
for(a=130;a>0;a–);
}
void write_dat(uchar dat) //LCD1602写数据
{
rs=1;
rw=0;
P0=dat;
delay();//待数据安稳,待LCD1602呼应结束,不然LCD不显现.
e=0;
e=1;
e=0;
}
void write_com(uchar com)//LCD1602写指令
{
rs=0;
rw=0;
P0=com;
delay();
e=0;
e=1;
e=0;
}
void top()//LCD1602显现榜首行
{
uchar i;
write_com(0x80);
for(i=0;i<14;i++)
{
write_dat(table1[i]);
}
write_dat(table3[(uchar)(F0)]);
}
void bot()//LCD1602显现第二行
{
uchar i;
write_com(0xc0);
for(i=0;i<10;i++)
{
write_dat(table2[i]);
}
write_dat(table3[(uchar)(bai)]);
write_dat(table3[10]); //显现小数点
write_dat(table3[(uchar)(shi)]);
write_dat(table3[(uchar)(ge)]);
}
void init() //LCD1602初始化
{
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
}
void adc()//ADC0832转化
{
uchar i;
cs=1;
clk=0;
cs=0;
di=1;
clk=1;//榜首个脉冲
clk=0;
clk=1;//第二个脉冲
if(key!=1) //丈量通道转化
{
F0=!F0;
while(key!=1);
}
clk=0;
di=F0;
clk=1;//第三个脉冲
clk=0;
clk=1;
for(i=0;i<8;i++)
{
clk=0;
adc_data<<=1;
adc_data|=(uchar)(dox);
clk=1;
}
cs=1;
}
void adx() //ADC0832数制转化
{
bai=adc_data/51;
shi=((adc_data%51)*10)/51;
ge=((((adc_data%51)*10)%51)*10)/51;
}
void main()
{
F0=0;
SP=0x30;
init();
while(1)
{
adc();
adx();
top();
bot();
delay();
}
}