Define ADC_CLOCK = 3 'default value is 3
Define ADC_SAMPLEUS = 10 'default value is 20
Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 4
Define LCD_EREG = PORTC
Define LCD_EBIT = 5
Define LCD_RWREG = 0 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
Dim an0 As Word
AllDigital 'ansel & anselh to 0.
TRISA = %00000001 'set PORTA.0 pin as input
TRISB = 0x00 'POrtb all outputs
ANSEL = %00000001 'Make AN0 analog input
OSCCON = %01111100 'set 8mhz, osc setup based On Config fuses.
'Initialize the A/D converter
ADCON1 = %00000000 'make reference voltage = VDD, AdresH/L left justified
'as INTOSC is 8Mhz =>
ADCON0 = %10000101 'A/D clock is internal Fosc/32 , select AN0, enable conversion.
Lcdinit 1 'initialize LCD module; cursor is blinking
loop:
Adcin 0, an0
Lcdcmdout LcdClear 'clear LCD display
Lcdout "Analog input AN0" 'text for the line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "Value: ", #an0 'formatted text for line 2
WaitMs 50 'larger value 50ms should be used in real device
Goto loop 'loop forever