标题:
adc0832数字电压表proteus仿真及51单片机源程序
[打印本页]
作者:
51黑ff
时间:
2016-9-25 17:25
标题:
adc0832数字电压表proteus仿真及51单片机源程序
用adc0832芯片和51单片机做的电压表,里面有仿真,C源程序,可根据不同的应用场合不同,稍改程序就能改变量程,达到你的要求
0.png
(24.82 KB, 下载次数: 122)
下载附件
2016-9-25 17:23 上传
0.png
(51.57 KB, 下载次数: 101)
下载附件
2016-9-25 17:22 上传
adc0832数字电压表的源程序和仿真工程文件下载:
数字电压表的设计.rar
(55.75 KB, 下载次数: 177)
2016-9-25 17:25 上传
点击文件名下载附件
下载积分: 黑币 -5
源程序:
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit cs=P3^5;
sbit clk=P3^3;
sbit dati=P3^4;
sbit dato=P3^4;
sbit P20=P2^4;
uchar dat=0x00;
uchar count=0x00;
uchar CH;
uchar dis[]={0x01,0x02,0x03,0x04};
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code tablewe[]={0xfd,0xfb,0xf7,0xf0,0xdf,0xfe};
uchar adc0832(uchar CH)
{ uchar i,test,adval;
adval=0x00;
test=0x00;
clk=0;
dati=1;
_nop_();cs=0; _nop_();clk=1;_nop_();
if(CH==0x00)
{ clk=0;
dati=1;
_nop_();clk=1;_nop_();clk=0;
dati=0;
_nop_();clk=1;_nop_();}
else { clk=0;dati=1;
_nop_();
clk=1;_nop_();clk=1;
_nop_();clk=0;dati=1;
_nop_();clk=1;_nop_();}
clk=0;dati=1;
for(i=0;i<8;i++)
{_nop_();adval<<=1;clk=1;
_nop_();clk=0;
if(dato) adval|=0x01;
else adval|=0x00; }
for(i=0;i<8;i++)
{test>>=1;
if(dato) test|=0x80;
else test|=0x00; _nop_();
clk=1;
_nop_();
clk=0;}
if(adval==test)
dat=test;_nop_();
cs=1;
dato=1;clk=1;return dat;}
void delay(void)//延时函数
{uint r;
for(r=10;r<500;r++)
;
}
void convdata(uchar i)
{ dis[0]=i/51;
dis[1]=(i%51)*10/51;
dis[2]=((i%51)*10%51)*10/51;
}
void display(void)
{P2=0x02;
P0=tab[dis[0]]&0x7f;
delay();
P2=0x04;
P0=tab[dis[1]];
delay();
P2=0x08;
P0=tab[dis[2]];
delay();
}
void main(void)
{ P2=0xff;
P0=0xff;
delay();
delay();
CH=0x00;
TMOD=0x01;
TH0=15535/256;
TL0=15536%256;
IE=0x82;
TR0=1;
while(1)
{dat=adc0832(CH);
convdata(dat);
display();
}}
void timero(void) interrupt 1
{ TMOD=0x01;
TMOD=0x01;
TH0=15535/256;
TL0=15536%256;
IE=0x82;
TR0=1;
count++;
if(count==0x01)
{count=0x00;dat=adc0832(CH);}}
复制代码
作者:
越快乐越堕落
时间:
2017-5-5 00:01
范围多大
作者:
Dong东
时间:
2018-6-30 13:34
很不错,很简易的帖子。
作者:
川哥哥
时间:
2018-7-10 13:17
很不错的帖子,赞一个
作者:
s360221867
时间:
2018-9-17 19:31
不错 试验很成功
作者:
Z_SIMPLE
时间:
2018-12-19 13:02
大佬我想问一下,这个能测量外电压吗
作者:
zhc1028683236
时间:
2018-12-20 12:39
点一个站 刚谢分享
作者:
Shawn666
时间:
2018-12-24 14:12
怎么检测是AC还是DC
作者:
cqxlwq
时间:
2019-5-2 19:16
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit cs=P3^5;
sbit clk=P3^3;
sbit dati=P3^4;
sbit dato=P3^4;
sbit P20=P2^4;
uchar dat=0x00;
uchar count=0x00;
uchar CH;
uchar dis[]={0x01,0x02,0x03,0x04};
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code tablewe[]={0xfd,0xfb,0xf7,0xf0,0xdf,0xfe};
uchar adc0832(uchar CH)
{ uchar i,test,adval;
adval=0x00;
test=0x00;
clk=0;
dati=1;
_nop_();cs=0; _nop_();clk=1;_nop_();
if(CH==0x00)
{ clk=0;
dati=1;
_nop_();clk=1;_nop_();clk=0;
dati=0;
_nop_();clk=1;_nop_();}
else { clk=0;dati=1;
_nop_();
clk=1;_nop_();clk=1;
_nop_();clk=0;dati=1;
_nop_();clk=1;_nop_();}
clk=0;dati=1;
for(i=0;i<8;i++)
{_nop_();adval<<=1;clk=1;
_nop_();clk=0;
if(dato) adval|=0x01;
else adval|=0x00; }
for(i=0;i<8;i++)
{test>>=1;
if(dato) test|=0x80;
else test|=0x00; _nop_();
clk=1;
_nop_();
clk=0;}
if(adval==test)
dat=test;_nop_();
cs=1;
dato=1;clk=1;return dat;}
void delay(void)//延时函数
{uint r;
for(r=10;r<500;r++)
;
}
void convdata(uchar i)
{ dis[0]=i/51;
dis[1]=(i%51)*10/51;
dis[2]=((i%51)*10%51)*10/51;
}
void display(void)
{P2=0x02;
P0=tab[dis[0]]&0x7f;
delay();
P2=0x04;
P0=tab[dis[1]];
delay();
P2=0x08;
P0=tab[dis[2]];
delay();
}
void main(void)
{ P2=0xff;
P0=0xff;
delay();
delay();
CH=0x00;
TMOD=0x01;
TH0=15535/256;
TL0=15536%256;
IE=0x82;
TR0=1;
while(1)
{dat=adc0832(CH);
convdata(dat);
display();
}}
void timero(void) interrupt 1
{ TMOD=0x01;
TMOD=0x01;
TH0=15535/256;
TL0=15536%256;
IE=0x82;
TR0=1;
count++;
if(count==0x01)
{count=0x00;dat=adc0832(CH);}}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1