hi all,
am trying to understand how to implament the ADC on the pic 16f877
my code is for a LM335 temp sensor connected to RA0(pin 2)
the VDD and VSS is from a 7805 voltage reg that also supplies the LM335
Cant get ADC to work from my circuit. or is it my code??????????????
why cant i use decimal ie 0.46 in my maths routine?????????????
This has had me up all week trying to get it to work
PLZ someone guide me in the correct direction
'PIC 16f877 with a LM335 temp sender
'
'
define osc 20 ' 20mhz oscillator
' LCD ROUTINES
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4 '4,5,6,7
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
define ADC_CLOCK 3 ' Set clock source
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
AD_RAW var word ' Create adval to store result
AD_RESULT var word
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10001110 ' Set PORTA analog and RIGHT justify result
ADCON0 = %10000001 ' Configure and turn on A/D Module
Pause 500 ' Wait .5 second
loop:
ADCIN 0, AD_RAW ' Read channel 0 to ad_raw
AD_RESULT = (ad_raw *0.48828) - 273.15 ' Convert Kelvins to Degrees C
Lcdout $fe, 1 ' Clear LCD
Lcdout "TEMP ", DEC AD_Result ," C" ' Display the decimal value
Pause 100 ' Wait .1 second
Goto loop ' Do it forever
End
Bookmarks