手機(jī)訪問更快捷
更多流量 更易傳播
隨時(shí)掌握行業(yè)動(dòng)態(tài)
網(wǎng)絡(luò)課堂 行業(yè)直播
產(chǎn)品推薦:水表|流量計(jì)|壓力變送器|熱電偶|液位計(jì)|冷熱沖擊試驗(yàn)箱|水質(zhì)分析|光譜儀|試驗(yàn)機(jī)|試驗(yàn)箱
壓力校驗(yàn)儀開發(fā)工程師依照demo編寫了如下代碼,卻打不開AD轉(zhuǎn)換(顯示的轉(zhuǎn)換結(jié)果亂七八糟,沒有任何規(guī)律),其中displaystring()是用LCD顯示字符串的函數(shù),已經(jīng)調(diào)試成功。編寫程序如下:
#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
}
}
相關(guān)產(chǎn)品
免責(zé)聲明
客服熱線: 15024464426
加盟熱線: 15024464426
媒體合作: 0571-87759945
投訴熱線: 0571-87759942
下載儀表站APP
Ybzhan手機(jī)版
Ybzhan公眾號(hào)
Ybzhan小程序