#include <STC12C5A60S2.h>
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
void Delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void AD_Init()
{
P1M0=0x0f;
P1M1=0x0f;
ADC_CONTR=0xe0;
Delay(10);
}
int GetAD(unsigned char channel)
{
unsigned char AD_finished=0;
int result;
ADC_CONTR|=channel;
ADC_CONTR|=0x80;
while(AD_finished==0)
{
AD_finished=(ADC_CONTR&0x10);
}
result=ADC_RES*4+ADC_RESL;
ADC_CONTR&=0xf7;
return(result);
}
float Ad_AV(uchar channel)
{
float Val_Av=0;
uchar num;
for(num=100;num>0;num--);
{
Val_Av+=GetAD(channel);
}
Val_Av/=100.0;
Val_Av=Val_Av*5/1024;
return(Val_Av);
}
unsigned int ADC1()
{
float ad1;
AD_Init();
IE=0xA0;
ad1=Ad_AV(1);
while(1);
return(ad1);
}
这一部分while(AD_finished==0){AD_finished=(ADC_CONTR&0x10);}为啥调试的时候运行不过去?是有问题吗?等待ADC标志位变化,这样写可以吗? |