關於APP020的類比轉數位問題
|
||||
---|---|---|---|---|
新會員
|
想請問我現在已經寫了一個程式,當SW5按一下時LED1會亮再按一下SW5時LED1會暗,想請問我還要再加上設定兩段電壓範圍來控制LED1的亮跟暗,當在電壓範圍一4V到4.1V時LED1要暗,當在電壓範圍二2V到3V時要亮,我是利用PIC30F4011的AN0腳位來當類比輸入,以下是我的程式,我編譯時沒問題,執行動作時按SW5時動作都正常,可是電壓不同時沒有改變,以下主要部分為類比轉數位輸入時的程式,想請教各位前輩幫小弟看一下類比轉數位的程式有何問題,謝謝!!!PS(.....為我按SW5控制LED1的程式為求版面簡潔所以就沒放
#define __dsPIC30F4011__ #include <p30F4011.h> #define LED1 LATEbits.LATE0 #define DIR_LED1 TRISEbits.TRISE0 #define SW5 PORTEbits.RE8 #define DIR_SW5 TRISEbits.TRISE8 #define INPUT 1 #define OUTPUT 0 #define LED_DATA LATE void InitADC10(void); void ADCCON(void); int main(void ) { InitADC10(); ADCCON(); DIR_LED1 = OUTPUT ; DIR_SW5 = INPUT ; LED_DATA = 0xffff ; while (1) {…….. ……… ……….. } //End of While(1) Loop }// End of main program} // void InitADC10(void) { ADPCFG = 0x0078; ADCON1 = 0x026E; ADCON2 = 0x0000; ADCHS = 0x0000; ADCON3 = 0x0003; IFS0bits.ADIF = 0; IEC0bits.ADIE = 1; ADCON1bits.ADON = 1; } void ADCCON(void) { float ADC_Value; ADC_Value = ADCBUF0; if(( ADC_Value < 0x399 ) && ( ADC_Value > 0x333)) { LED1 = 1 ; } if (( ADC_Value < 0x266 ) && ( ADC_Value > 0x199)) { LED1 = 0 ; } }
發表於: 2008/6/17 20:14
|
|||
|