help on A/D conversion on pic18F2620

Status
Not open for further replies.

lionman

New Member
hi guys,

i am using Pic18f2620 to sense a analog( eg temp sensor) input and convert it to digital input...
i came up with this code i wonder is it correct or wong.... do i need to add additional files?

eg temp sensor, compare it with the desire temp. and if is over the desire temp, the alarm will be triggered.

#include <p18f2620.h>
#include <adc.h>
#include <stdlib.h>

#define TempTrip 0x7F
TRISD =0x00;

PORTD = 0x00;
TRISCbits.TRISC2=0;
PORTCbits.RC2=0;

ADCON0 = 0b11000001;
ADCON1 = 0b00000000;

SetChanADC(ADC_CH0)
ConvertADC();
While(BusyADC());
adc_result = ReadADC();
close();

if (adc_result > TempTrip)
{
PORTDbits.RD0 = 1;
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…