Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help on A/D conversion on pic18F2620

Status
Not open for further replies.

lionman

New Member
:p 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.

Latest threads

New Articles From Microcontroller Tips

Back
Top