我测试,只有16位才是正确结果,也就是(寄存器的值/65535*VCC),但是官网写的是10位应该用1024???是我撞对了还是手册错了?
#include <STC8.H>
unsigned int ADCReadBt;
unsigned char ADCReadBtH,ADCReadBtL;
unsigned int VREF;
unsigned char VREFnow;
unsigned char flag = 0;
void Delay1000ms(void) //@11.0592MHz
{
unsigned char data i, j, k;
i = 43;
j = 6;
k = 203;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void STC8UartInit(){
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x40; //定时器时钟1T模式
AUXR &= 0xFE; //串口1选择定时器1为波特率发生器
TMOD &= 0x0F; //设置定时器模式
TL1 = 0xE0; //设置定时初始值
TH1 = 0xFE; //设置定时初始值
ET1 = 0; //禁止定时器中断
TR1 = 1; //定时器1开始计时
}
void STC8UartSend(unsigned int ADCRead){
SBUF = ADCRead;
while(TI==0);
TI=0;
}
void ADCInit(){
ADC_CONTR = 0xCF;
ADCCFG = 0x0F;
ADCTIM = 0x2A;//2a
EA = 1;
EADC = 1;
}
void ADCIRT()interrupt 5{
ADC_CONTR = 0x8F;
flag = 1;
ADCReadBt = ADC_RES<<8 | ADC_RESL;
ADCReadBtH = ADCReadBt/256;
ADCReadBtL = ADCReadBt%256;
}
void main(){
P1M0 = 0x00;
P1M1 = 0x04;
ADCReadBt = 0;
ADCReadBtH = 0;
ADCReadBtL = 0;
ADCInit();
STC8UartInit();
while(1){
if(flag){
flag = 0;
STC8UartSend(ADC_RES);
STC8UartSend(ADC_RESL);
// STC8UartSend('\r');
// STC8UartSend('\n');
ADC_CONTR = 0xCF;
}
Delay1000ms();
}
}
|