高精度AD在ZC-3000-4压力校验仪开发花絮
时间:2015-06-20 阅读:2613
压力校验仪开发工程师依照demo编写了如下代码,却打不开AD转换(显示的转换结果乱七八糟,没有任何规律),其中displaystring()是用LCD显示字符串的函数,已经调试成功。编写程序如下:
#Include <REG1210.H> // The header file with the MSC register definitions
#Include <stdio.h> // Standard I/O so we can use the printf function
extern signed long bipolar(void);
#define LSB 298e-9
#Ifndef XTAL // if no XTAL compiler variable defined use:
#define XTAL 11059200 // XTAL frequency 11.0592 MHz
#Endif
Main(void) {
char i,j;
float result;
PDCON = 0x75; // Turn on the A/D
ACLK = XTAL/1000000; // ACLK freq. = XTAL Freq./(ACLK +1) = 0.9216 MHz
// 0.9216 Mhz/64 = 14,400 Hz
DECIMATION = 1440; // Data Rate = 14,400/1,440 = 10 Hz
ADMUX = 0x08; // AINP = AIN0, AINN = AINCOM
ADCON0 = 0x30; // Vref On, 2.5V, Buffer Off, PGA=1
ADCON1 = 0x01; // bipolar, auto, self calibration, offset, gain
//wait for the calibration to take place
for (i=0;i<3;i++){ // dump 3 conversions
while(!(AIE&0x20)) {}
j=ADRESL;
}
j=1;
while(1){
while(!(AIE&0x20)) {} // Waiting for conversion
result=bipolar(); // Save Results
sprintf (szBuffer, "%10.8f", result*LSB);
DisplayString(0x80, szBuffer); // Display ADResult on the first line of LCD
}
}