STC12C系列單片機(jī)讀四路AD數(shù)據(jù)函數(shù)程序
經(jīng)實(shí)際應(yīng)用下面的程序完全可以用,晶振11.0592M...讀出來(lái)的數(shù)據(jù)是送入數(shù)組內(nèi)部,用的時(shí)候直接讀取數(shù)組相應(yīng)的位就可以了.
void ADC_START(void);
void ADC0(void);
void ADC1(void);
void ADC2(void);
void ADC3(void);
sfrP1M0 = 0x92;
sfrP1M1 = 0x91;
sfrP1ASF = 0x9D;
sfrAD_CONTR = 0xBC;
sfrAD_RES = 0xBD;
sfrAD_RESL = 0xBE;
sfrIPH = 0xB7;
sfrAUXR1 = 0xA2;//AD寄存器數(shù)據(jù)調(diào)整位;
uint16 READ_ADIN_DATA[4]={0,0,0,0};
void ADC_START(void)
{
AD_CONTR = 0x80;//打開(kāi)AD電源
AD_RES = 0;//清數(shù)據(jù)存儲(chǔ)寄存器
AD_RESL = 0;
//AUXR1 &= 0xFB;
AUXR1 |= 0x04;//設(shè)置高低位存儲(chǔ)數(shù)據(jù);
AD_CONTR |= 0x08;//開(kāi)始AD轉(zhuǎn)換;
nop();//延時(shí)
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
while((AD_CONTR & 0x10) == 0);//判斷AD是否轉(zhuǎn)換成功
AD_CONTR &= 0xE7;//AD停止并清AD標(biāo)志位;
}
void ADC0(void)//讀P10 口AD數(shù)據(jù);
{
uint16 Value = 0;
AD_CONTR = 0xE0;//設(shè)置P10口為AD輸入端
ADC_START();//調(diào)用AD轉(zhuǎn)換函數(shù)
Value = AD_RES;//讀低8位數(shù)據(jù);
Value <<=8;
Value |= AD_RESL;//合成數(shù)據(jù);
READ_ADIN_DATA[0] = Value;//合成數(shù)據(jù)送數(shù)組;
}
void ADC1(void)
{
uint16 Value = 0;
AD_CONTR = 0xE1;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[1] = Value;
}
void ADC2(void)
{
uint16 Value = 0;
AD_CONTR = 0xE2;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[2] = Value;
}
void ADC3(void)
{
uint16 Value = 0;
AD_CONTR = 0xE3;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[3] = Value;
}