专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

八通道adc0808数据采集

作者:佚名   来源:互联网   点击数:  更新时间:2014年09月17日   【字体:

#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit EN=P0^4;
sbit EOC=P0^6;
sbit STA=P0^7;
sbit ADA=P0^0;
sbit ADB=P0^1;
sbit ADC=P0^2;
sbit ALE=P0^5;
uchar code tab[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xD8,0x80,0x90,0xff};
uchar code wela[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar data shu[8]={0,0,0,0,0,0,0,0};
uint ada=1222,adb=0;
uchar alley=0;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=4;y>0;y--);
}
void display()
{

uchar i,hp;

for(i=0;i<8;i++)
{
if(i==1)hp=0x80;else hp=0;
P3=wela[i];
P2=tab[shu[i]]+hp;
delay(10);
P3=0X00;
}
}
void disan()
{
ada=ada*100/51;
shu[4]=alley/1000;
shu[5]=alley%1000/100;
shu[6]=alley%100/10;
shu[7]=alley%10;
shu[0]=ada/1000;
shu[1]=ada%1000/100;
shu[2]=ada%100/10;
shu[3]=ada%10;
}
void adc()
{

ADA=alley&0x01;
ADB=alley&0x02;
ADC=alley&0x04;
STA=0;
delay(30);
STA=1;
delay(30);
STA=0;
while(!EOC)delay(1);
EN=1;
delay(2);
ada=P1;
EN=0;
}
void main()
{
uchar a=100;
while(1)
{
a=1000;
alley++;
if(alley>7)alley=0;
adc();
disan();
while(a--)
{

display();
}
}
}

 

 

 

关闭窗口

相关文章