新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > AD8008實現(xiàn)A/D轉(zhuǎn)換

AD8008實現(xiàn)A/D轉(zhuǎn)換

作者: 時間:2016-11-17 來源:網(wǎng)絡 收藏
C代碼:

#include
#include
//#include
sbit ST=P3^2;
sbit EOC=P3^1;
sbit OE=P3^0;
sbit ADDA=P3^4;
sbit ADDB=P3^5;
sbit ADDC=P3^6;
unsigned char a,b,c;
unsigned char code dispbitcode[]={0x00,0x08,0x04,0x02,0x01};//共陰位碼
unsigned char code dispcode[]={ 0X3F,/*0*/
0X06,/*1*/
0X5B,/*2*/
0X4F,/*3*/
0X66,/*4*/
0X6D,/*5*/
0X7D,/*6*/
0X07,/*7*/
0X7F,/*8*/
0X6F,/*9*/
};//共陰段碼
/*************延時子程序*******************************/
void delay(unsigned int x)//最小1毫秒
{
unsigned char j;
while(x--)
{
for(j=0;j<125;j++)
{;}
}
}
/***************顯示子程序**********************/
void display(unsigned char bai,unsigned char shi,unsigned char ge)
{
//P3=dispbitcode[5];
//P2=dispcode[11];
P2=dispbitcode[1];
P0=dispcode[bai]; //顯示佰位
delay(5);
//P3=dispbitcode[5];
//P2=dispcode[11];
P2=dispbitcode[2];
P0=dispcode[shi]; //顯示十位
delay(5);
//P3=dispbitcode[5];
//P2=dispcode[11];
P2=dispbitcode[3];
P0=dispcode[ge]; //顯示個位
delay(5);
}
void main(void)
{
unsigned char c;
ADDA=0;
ADDB=0;
ADDC=0; //選 0通道

本文引用地址:http://butianyuan.cn/article/201611/315529.htm

while(1)
{
ST=0;
ST=1; //啟動AD轉(zhuǎn)換
_nop_(); //程序空操作一次,即延時一下;
ST=0;
delay(1); // 延時等待轉(zhuǎn)換結(jié)束
OE =1; // 輸出轉(zhuǎn)換得到的數(shù)據(jù)

c=P1; // 記下得到的數(shù)據(jù)
OE = 0;
a=c/100; //送去顯示
b=c%100/10;
c=c%100%10;
display(a,b,c);
}
}



關鍵詞: AD8008AD轉(zhuǎn)

評論


技術專區(qū)

關閉