OK, next step is to initialize the ADC. Tried it but cannot go further. Would be nice to see a run-down of all the settings like ADSEL, for novice programmers like me to see exactly what these settings do. So here is the code that does not read ADC port AN0. Now, I use PortA.4 and PortA.5 so I use this:
TrisA = 001111
Code:#CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF #ENDCONFIG high portc.0 DEFINE OSC 4 DEFINE ADC_BITS 10 ' 10 bit A/D Conversion DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 ' 50 uS A/D sample time VRCON = 000000 ' Disable Comparator Voltage Reference ANSEL = 000001 ' Set pin (AN0) to analog input, the rest to digital ADCON0 = 001001 ' Set up A/D converter - Right Just., VDD REF., CH 0, ON ADCON1 = 110000 ' Set up A/D Converter clock source to internal RC TrisA = 001111 define LCD_DREG PORTB ' Data on PORTB define LCD_DBIT 4 ' Data starts on PORTB.4 DEFINE LCD_RSREG PORTA ' RS on PORTA DEFINE LCD_RSBIT 4 ' RS on A4 DEFINE LCD_EREG PORTA ' E on PORTA DEFINE LCD_EBIT 5 ' E on A5 DEFINE LCD_BITS 4 ' LCD 4 bit mode DEFINE LCD_LINES 2 ' 2 line LCD display Define LCD_COMMANDUS 2000 ' Command Delay (uS) Define LCD_DATAUS 50 ' Data Delay (uS) adval var byte Pause 500 ' Wait for LCD to startup mainloop: ADCIN 0, adval LCDOut $fe, 1 ' Clear LCD screen LCDOut "Magnetic Pulser" 'Charac 1234567890123456 LCDOut $fe, $c0 'Jump to second line lcdout "Voltage:", DEC adval toggle portc.0 pause 100 GoTo mainloop End





Bookmarks