ADCON correct systax - understand thios ADCON stuff

Status
Not open for further replies.

MrDEB

Well-Known Member
trying to config a ADC input on port A.1 but this ADCON stuff??
Code:
Device = 18F452
Clock = 20

// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTd.3
#option LCD_EN = PORTd.2

// uses LCD and AD libraries...
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
          
// read the AD port and scale for 0 - 5 volts...
Function ADInAsVolt() As Word
   result = (ADC.Read(0) + 1) * 500 / 1024
End Function

// sampled AD value...
Dim ADVal As Word

// initialise and clear LCD...
ADCON1 = $07       // PORTd as digital (LCD)  ????
TRISA.1 = 1        // configure AN0 as an input ?????
ADCON1.7 = 1       // set analogue input on PORTA.0 ??????
DelayMS (500)
LCD.Cls

// main program loop...
While true
   ADVal = ADInAsVolt
   LCD.MoveCursor (1,1)
   LCD.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ")
   DelayMS(250)
Wend
 
ADCON1,
bit 7 = adfm ( AtoD format msb in ADRESH, or LSB in ADRESL )
bit 6 = adcs2 ( AtoD clock source, 3rd part of three, the other two are in ADCON0 )
bits 0,1,2,3 = pdfg 1,2,3,4 (port configuration)

TRISA.0 is AN0 direction port pin
and ADCON1 = $07 turns them all off ( makes them digital )
PORTD has nothing to do with the ADCON1 reg


so
Code:
ADCON1 = $0E   // PORTA.0 ANO enabled.
TRISA.0 = 1      // PORTA ddr = input
ADCON1.7 = 1   // MSB in ADRESH
TRISD = 0        // LCD port as output
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…