|
實(shí)驗(yàn)C8051F410的ADC,使用串口輸出電壓值,但是輸出與實(shí)際的誤差隨實(shí)際電壓增大而增大,達(dá)到參考電壓時(shí)串口發(fā)送出去的值與實(shí)際電壓相差0.3V;
相關(guān)程序:
*******************************************
void ADC0_ISR (void) interrupt 10
{
static unsigned long accumulator = 0; // accumulator for averaging
static unsigned int measurements = 2048; // measurement counter
unsigned long result=0;
unsigned long mV; // measured voltage in mV
static unsigned int RH;
AD0INT = 0; // clear ADC0 conv. complete flag
accumulator += ADC0;
measurements--;
m=1;
if(measurements == 0)
{
measurements = 2048;
result = accumulator / 2048;
accumulator=0;
mV = result * 220 / 4095;
RI0=0;
TI0=0;
SBUF0=mV;
}
}
void UART0_Interrupt (void) interrupt 4
{
Delay_ms (2);
if (TI0==!0)
{
TI0=0;
}
else if(RI0==!0)
{
RI0=0;
}
}
********************************************
主程序是死循環(huán);參考電壓是2.2V,因?yàn)榇谳敵鲋荒茱@示16位二進(jìn)制,最大255,所以在計(jì)算時(shí)乘的220而不是2200。有沒有大佬幫忙看一下?
|
|