.
ADC0809 做 AD 转换的 C 程序
#include
unsigned char code dispbitcode[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
unsigned char dispbuf[4];
unsigned int i;
unsigned int j;
unsigned char getdata;
unsigned int temp;
unsigned int temp1;
unsigned char count;
unsigned char d;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
sbit P34=P3^4;
sbit P35=P3^5;
sbit P36=P3^6;
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P17=P1^7;
void TimeInitial();
void Delay(unsigned int i);//
void TimeInitial()
..
.
{
TMOD=0x10;
TH1=(65536-200)/256;// 定时时间为 2us, 亦即 CLK 周期为 0.4us
TL1=(65536-200)%256;
EA=1;
ET1=1;
TR1=1;
}
void Delay(unsigned int i)// 延时函数
{
unsigned int j;
for(;i>0;i--)
{
for(j=0;j<125;j++)
{;}
}
}
void Display()//
{
P1=dispbitcode[dispbuf[3]];// 十位
P20=0;
P21=1;
P22=1;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[2]];// 个位
..
.
P17=1;// 显示小数点
P20=1;
P21=0;
P22=1;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[1]];// 十分位
P20=1;
P21=1;
P22=0;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[0]];// 百分位
P20=1;
P21=1;
P22=1;
P23=0;
Delay(10);
P1=0x00;
}
void main()// 主函数
{
TimeInitial();
while(1)
{
ST=0;// 关闭转换
OE=0;// 关闭输出
..
.
ST=1;// 开启转换
ST=0;// 关闭转换
P34=0;// 选择通道 0
P35=0;
P36=0;
while(EOC==0);// 判断是否转换结