Now, if you plan to NOT use ADCIN, you must do everything manually. Here's ashort example... OK OK it looks huge but...
Code:' ' PIC configuration fuses ' ======================== asm __CONFIG _CONFIG1H, _HS_OSC_1H ; HS osc (20 MHz ; __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_27_2L & _PWRT_ON_2L ; Enable Brown out voltage detect ; Brown out voltage threshold 2.7 Volt ; __CONFIG _CONFIG2H, _WDT_OFF_2H ; Disable watch dog timer ; __CONFIG _CONFIG3H, _CCP2MX_OFF_3H ; Use default PORTC.1 for CCP2 ; __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L ; enable stack overflow ; disable low-voltage programming mode ; disable background debugger ; __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L ; disable code protect (user block) ; __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H ; disable code protect (boot block) ; __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L ; disable write protect (user block) ; __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H ; disable Write protect CONFIG regs ; disable write protect boot block ; disable rite protect Data EE ; __CONFIG _CONFIG7L, _EBTR0_OFF_7L ; Disable table Read protect user block ; __CONFIG _CONFIG7H, _EBTRB_OFF_7H ; Disable Read protect boot block enable endasm ' ' Hardware configuration ' ====================== ' DEFINE OSC 20 ' ' Adc ' --- ADCON0 = %10000001 ' Conversion clock = Fosc/32 ' AN0 selected ' turn on ADC ADCON1 = %110001110 ' right justified results ' Conversion clock = Fosc/32 ' PORTA.0 as analog, all other to digital ' ' Hardware assignment ' =================== ' ' LCD ' --- DEFINE LCD_DREG PORTD ' LCD data port DEFINE LCD_DBIT 4 ' LCD data starting bit 0 or 4 DEFINE LCD_RSREG PORTD ' LCD register select port DEFINE LCD_RSBIT 2 ' LCD register select bit DEFINE LCD_EREG PORTD ' LCD enable port DEFINE LCD_EBIT 3 ' LCD enable bit DEFINE LCD_BITS 4 ' LCD bus size 4 or 8 DEFINE LCD_LINES 2 ' Number lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us ' ' Alias definition ' ================ ' ' ADC ' --- GoDone var ADCON0.2 ' use to start/stop/check ' AD conversion ADON VAR ADCON0.0 ' use to start/shut-off ADC ' ' Variable definition ' =================== @AdResult = ADRESL AdResult var word EXT ' Store ADC result ' ' Software constants ' ================== ADC_SampleUs con 3 ' ADC sampling time ' ' Program Start here ' ================== Pause 500 ' LCD start up delay Start: ' ' A/D conversion ' -------------- adon = 1 ' turn on ADC pauseus adc_sampleus ' Wait minimum sampling time godone = 1 ' start conversion while godone : wend ' check if finished ' adon = 0 ' turn off ADC ' ' Show result on LCD ' ------------------ lcdout $FE,1, "Result=:", dec adresult ' show result on LCD pause 250 goto stART




Bookmarks