//单片机 STC12C5204AD A/D 转换程序,那位帮我看下这个 程序 那里出了错误。。
#include
#define uchar unsigned char
#define uint unsigned int
sbit DAT=P1^4;
sbit CLK=P1^5;
sbit a=P1^7;
sbit b=P1^6;
uchar stmp,qian,bai,shi,ge;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xff};//0-9,-,全灭 共阳数码管
void delay(uint z) //延时
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void sendbyte(uchar byte)//显示
{
uchar num,c;
num=tab[byte];
for(c=0;c {
CLK=0;
DAT=num&0x80; //(0x80即十进制的128, 二进制的10000000 按位发送)
CLK=1;
num }
}
void display(uchar qian,bai,shi,ge)
{
P1=0xfe;
sendbyte(ge);
delay(10);
P1=0xfd;
sendbyte(shi);
delay(10);
P1=0xfb;
sendbyte(bai);
delay(10);
P1=0xf7;
sendbyte(qian);
delay(10);
}
void main()
{
b=0;
ADC_POWER=1;
delay(20);
P16ASF=1;
ADC_FLAG=0; //转换结束清0
ADC_START=0; //开始清0
ADC_CHS0=0;
ADC_CHS1=0;
ADC_CHS2=0;
// ADC_CONTR = ADC_CONTR&0xE0;
ADC_CHS0=0;// 选择模拟输入通道P1.7
ADC_CHS1=1;
ADC_CHS2=1;
ADC_SPEED1=1;
ADC_SPEED0=1;
delay(10);
ADC_RES=0; //转换结果标志位清0
ADC_START=1;
// do { ; }
/* if((ADC_CONTR & 0x10)==0)
{
ADC_FLAG=0;
ADC_START=0;
stmp=ADC_RES;
qian=stmp/1000;
bai=stmp/100%10;
shi=stmp%100/10;
ge=stmp%10;
display(qian,bai,shi,ge);
delay(10);
}*/
if(ADC_FLAG==1)
{
display(2,0,1,5);
delay(10);
}
else
{
display(3,2,1,1);
delay(10);
}
}