STC12c5a60s2
单片机读取的,转换出来的电压值偏小,请大家帮我看看,是不是龙错了。我用的是P1.4!!
/*----------------------------
Get ADC result
----------------------------*/
GetADCResult(int ch)
{
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
_nop_(); //Must wait before inquiry
_nop_();
_nop_();
_nop_();
while (!(ADC_CONTR & ADC_FLAG)); //Wait complete flag
ADC_CONTR &= ~ADC_FLAG; //Close ADC
return (ADC_RES*4+ADC_RESL); //Return ADC result
}
/*----------------------------
Ini
tial ADC sfr
----------------------------*/
void InitADC()
{
P1ASF = 0xff; //Open 8 channels ADC function
ADC_RES = 0;
ADC_RESL = 0; //Clear previous result
ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
// delay(2);
}
void ADC()
{
INT16U Shishu=0,shiwei=0,ya=0;
double c;
INT16U cdisplay;
shiwei=GetADCResult(4);
/*lcd_pos(0x40); //ÉèÖÃÏÔʾλÖÃΪµÚÒ»ÐеĵÚ1¸ö×Ö·û
lcd_wdat('A');
lcd_pos(0x41);
lcd_wdat('=');
lcd_pos(0x42);
lcd_wdat(shiwei/1000+0x30);
lcd_pos(0x43);
lcd_wdat((shiwei%1000)/100+0x30);
lcd_pos(0x44);
lcd_wdat((shiwei%100)/10+0x30);
lcd_pos(0x45);
lcd_wdat((shiwei%10)+0x30);*/
c = ((double)shiwei*(5.50/1024))*100;
cdisplay = (INT16U) c;
GraphicDispNum(0, 0,DISPLAY_NORMAL, cdisplay/100);
GraphicDispNum(0, 5,DISPLAY_NORMAL, cdisplay%100);
GraphicDispNum(0, 12,DISPLAY_NORMAL, shiwei%100);
2