参考中文文档 19.1.4 带隙电压(Band-gap)输入应用
我参考文中代码 但是实际的打印效果并不理想 是我对问题理解有问题还是说怎么回事
- void READ_BANDGAP()
- {
-
- UINT8 a = 32;
- UINT8 BandgapHigh,BandgapLow;
- UINT16 Bandgap_Value;
- set_IAPEN; // Enable IAPEN
- IAPAL = 0x0C;
- IAPAH = 0x00;
- IAPCN = 0x04;
- set_IAPGO; // Trig set IAPGO
- BandgapHigh = IAPFD;
- IAPAL = 0x0d;
- IAPAH = 0x00;
- IAPCN = 0x04;
- set_IAPGO; // Trig set IAPGO
- BandgapLow = IAPFD;
- BandgapLow = BandgapLow&0x0F;
- clr_IAPEN; // Disable IAPEN
-
- Bandgap_Value = (BandgapHigh<<4)+BandgapLow;
- Bandgap_Voltage = 3072/(0x1000/Bandgap_Value);
- }
复制代码
- InitialUART0_Timer3(115200);
-
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
- Timer1_Delay10ms(100);
-
- // ÒÔϲ¿·Ö¹Ù·½Ô´Âë
-
- READ_BANDGAP();
- Enable_ADC_BandGap;
- ADC_Bypass();
- ADC_Bypass();
- ADC_Bypass();
- ADC_Bypass();
- ADC_Bypass();
- ADC_Bypass();
- clr_ADCF;
- set_ADCS;
- while(ADCF == 0);
- bgvalue = (ADCRH<<4) | ADCRL;
- VDD_Voltage = (0xFFF/bgvalue)*Bandgap_Voltage;
- printf ("\n Bandgap voltage = %e", Bandgap_Voltage);
- printf ("\n VDD voltage = %e", VDD_Voltage);
- while(1);
复制代码
加入延时 和 多次调用ADC_Bypass()是为了让芯片稳定 读出的数据更稳定
问题:
1.READ_BANDGAP 函数中3072 什么含义
2.程序 printf的打印值 为什么跟我理解差距太大 尤其是 Bandgap_voltage;
|