Ⅰ 求基於AT89S52的ADC0809位AD轉換晶元的程序
(1). 進行A/D轉換時,採用查詢EOC的標志信號來檢測A/D轉換是否完畢,若完畢則把數據通過P0埠讀入,經過數據處理之後在數碼管上顯示。
(粗配2). 進行漏凳敗A/D轉換之前,要啟動轉換的方法:
ABC=110選擇第三通道
ST=0,ST=1,ST=0產生啟動轉換的正脈沖返顫信號 .
C語言源程序
#include
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char dispbuf[8]={10,10,10,10,10,0,0,0};
unsigned char dispcount;
sbit ST="P3"^0;
sbit OE="P3"^1;
sbit EOC="P3"^2;
unsigned char channel="0xbc";//IN3
unsigned char getdata;
void main(void)
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
TR0=1;
ET0=1;
EA=1;
P3=channel;
while(1)
{
ST=0;
ST=1;
ST=0;
while(EOC==0);
OE=1;
getdata=P0;
OE=0;
dispbuf[2]=getdata/100;
getdata=getdata%10;
dispbuf[1]=getdata/10;
dispbuf[0]=getdata%10;
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
P1=dispcode[dispbuf[dispcount]];
P2=dispbitcode[dispcount];
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
Ⅱ adc8080的ad轉換單片機程序
#include "reg51.h"
#define data_point P0
sbit EOC=P2^0;
sbit ADDA=P2^1;
sbit ADDB=P2^2;
sbit ADDC=P2^3;
sbit OE=P2^5;
sbit START=P2^6;
sbit CLK=P2^7;
sbit ALE=P2^6;
unsigned char disp[3]={0,0,0};
char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char t0count=0;
unsigned int temp;
double sum;
unsigned char val_Integer; //整數
unsigned int val_Decimal; //小數
sbit k1 = P1^0;
sbit k2 = P1^1;
sbit k3 = P1^2;
sbit k4 = P1^3;
void delay(unsigned char ms)
{
unsigned char i;
while(ms--)
for(i=0;i<125;i++);
}
void display()
{
disp[0]=disp[0]&0x7f;
P3= disp[0];
k1 = 1;
delay(2);
k1 = 0;
P3= disp[1];
k2 = 1;
delay(2);
k2 = 0;
P3= disp[2];
k3 = 1;
delay(2);
k3 = 0;
P3= disp[3];
k4 = 1;
delay(2);
k4 = 0;
}
unsigned char ADC0808()
{
unsigned char d;
ADDC=0;
ADDB=0;
ADDA=0;
TR1=1;
ALE=1;ALE=0;
START=1;START=0;
while(EOC==0);
OE=1;
d=data_point;
OE=0;
TR1=1;
return d;
}
void covert(unsigned char x)
{
sum=x*0.0201378;
val_Integer=(unsigned char)sum;
val_Decimal=(unsigned int)((sum-val_Integer)*1000);
disp[3]=dispcode[val_Decimal%10];
disp[2]=dispcode[val_Decimal/10%10];
disp[1]=dispcode[val_Decimal/100];
disp[0]=dispcode[val_Integer];
}
void main()
{
TMOD=0x21;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TH1=256-2;
ET0=1;
ET1=1;
EA=1;
TR0=1;
OE=0;
START=0;
EOC=1;
while(1)
{
display();
}
}
void time0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
t0count++;
if(t0count==100)
{
t0count=0;
covert(ADC0808());
}
}
void time1() interrupt 3
{
CLK=~CLK;
}
Ⅲ ad中compile的作用是什麼,如何執行該命令
compile的作用是對你的代碼進行語法檢查,將你的文本程序語言轉化成計算機可以運行的「01010…形式的二進制文件。compile是exec和eval的低級版本大睜租。它不執行或計算您的語句或早冊表達式,但返回可以執行此操作的代碼對象。模式如下;compile(string,'','eval')返回完成滾兆eval(string)時將執行的代碼對象。