Re: 12F675 ADC 使用問題
|
||||
---|---|---|---|---|
新會員
|
GPIO有没有设定正确,Vref有没有设对。仔细对照datasheet,断点or单步看控制register值是不是设定值。
很可能是GPIO口AN2没有分配好。
發表於: 2009/7/22 17:10
|
|||
|
Re: 12F675 ADC 使用問題
|
||||
---|---|---|---|---|
資深會員
|
四樓的寫法可讀性較佳,不過一樓的寫法編譯執行並沒有問題,只是人類可讀性較差,
如果程式設定都沒問題,建議用電表測一下那隻腳的真正電壓值,看是不是硬體的問題。
發表於: 2009/7/22 6:15
|
|||
|
Re: 12F675 ADC 使用問題
|
||||
---|---|---|---|---|
新會員
|
ADCON0=0x00;// ADCON0.VCFG=0; Vref=VDD是5V沒錯
發表於: 2009/7/18 13:23
|
|||
|
Re: 12F675 ADC 使用問題
|
||||
---|---|---|---|---|
資深會員
|
10 bits adc = 0~1023
5V =1023 表示 Vref = 5V 1.3V =1023 , Vref = 1.3 V 要確定 Vref 來源是否設對! 可能要仔細看 adc data sheet !
發表於: 2009/7/18 10:15
|
|||
|
12F675 ADC 使用問題
|
||||
---|---|---|---|---|
新會員
|
第一次使用 12F675 ADC, 依照手冊設定 MCU SFR後, 若設定無誤, VDD=5V, ANALOG 輸入如果在1.3V以上應該可以得到1024/4以上的 AD值, 可是實際測試卻要接近5V左右, 不知問題出在哪裡
以上, 還請不吝指教 CODE如下 #include <pic12f675.h> //ADC utilities void init_a2d(void){ ANSEL=0x34;//ADC CLOCK INTERNAL, Analog Select only AN2 //ADCON0=0x80; // right justify result. ADCON0=0x00; // left justify ADON=1; // turn on the A2D conversion module } //unsigned int read_a2d(unsigned char channel){// for 10bit ADC unsigned char read_a2d(unsigned char channel){// for 8bit ADC channel&=0x03; // truncate channel to 2 bits ADCON0&=0xc3; // clear current channel select ADCON0|=(channel<<2); // apply the new channel select GO_DONE=1; // initiate conversion on the selected channel while(GO_DONE); //return (ADRESH<<8)+ADRESL; // return ADC value of the result return ADRESH; } void main(void) { //internal RC oscilator calibration _asm bsf STATUS, 5 ;Bank 1 call 3FFh ;Get the cal value movwf OSCCAL ;Calibrate bcf STATUS, 5 ;Bank 0 _endasm; TRISIO=0x04;// set AN2(GP2) as "input" direction pin CMCON=0x07; init_a2d(); /* // for debug and test code while(1) { delay_ms(1000); GPIO=GPIO^0x30; } */ while(1) if(read_a2d(2)>63) GP5=1; else GP5=0; }
發表於: 2009/7/17 15:25
|
|||
|