'jleblanc: 3.6.06
'Displays value of a pot on the LCD screen

DEFINE OSC 20

'This setup will tell PBP a 2-line LCD is connected in 4-bit 
'mode with the data bus on the top 4 bits of PORTB, Register 
'Select on PORTB.1, and Enable on PORTB.0.
'Data Bits it goes like: 3>B.7, 2>B.6, 1>B.5, 0>B.4

   ' Set LCD Data port
	DEFINE LCD_DREG	PORTB
	' Set starting Data bit (0 or 4) if 4-bit bus
	DEFINE LCD_DBIT	4
	' Set LCD Register Select port
	DEFINE LCD_RSREG	PORTB
	' Set LCD Register Select bit
	DEFINE LCD_RSBIT	1
	' Set LCD Enable port
	DEFINE LCD_EREG	PORTB
	' Set LCD Enable bit
	DEFINE LCD_EBIT	0
	' Set LCD bus size (4 or 8 bits)
	DEFINE LCD_BITS	4
	' Set number of lines on LCD
	DEFINE LCD_LINES	2
	' Set command delay time in us
	DEFINE LCD_COMMANDUS	2000
	' Set data delay time in us
	DEFINE LCD_DATAUS	50

'Setup ADC pins
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 5
TRISA = %11111111  'set all "A" ports to inputs
adcon1 = %10000010 'right justify results(?)
'declare variables
adcVar VAR WORD 'store adc input value
byteval VAR BYTE

PAUSE 2000

main:   
        ADCIN 0, adcVar
        byteval=adcVar/4
        LCDOUT $fe, 1, "wordval=", #adcVar   ' Send values to LCD
        LCDOUT $fe, $c0, "byteval=", #byteval ' Move to line 2  
        PAUSE 100

GOTO main       ' Do it forever