pic programing

Thread Starter

abeychandran

Joined Feb 7, 2012
17
Hi, I'm new in programming. I need help in C programming using ADC in PIC18F4520. i have a sensor and character lcd . i need to indicate the temp in lcd
 

debjit625

Joined Apr 17, 2010
790
Here is how you initialize ADC for 18F4502,I have used HI TECH C compiler...
Rich (BB code):
#include "htc.h"
#define Value() ((((unsigned int)ADRESH)<<8)|(ADRESL))
#ifndef _XTAL_FREQ
 #define _XTAL_FREQ 4000000  //Using a 4MHz oscillator
#endif
int result = 0x00;//Variable to store your ADC value.
int main(void)
{
 //Using PORTA's bit 0 i.e.. RA0/AN0  as the ADC input
 PORTA = 0x00;
 TRISA = 0x01; 
//Setting up the ADC
 ADCON1 = 0x0E;
 ADCON0 = 0x01; 
 ADCON2 = 0x81;
//Reading the ADC
while(1)
{
__delay_us(25);
GODONE = 1;
while(1)
{
 if(GODONE == 0)
 break;
}
result = Value();
//Here goes the rest of your program
}
}
You could get more details on its datasheet

Good Luck
 
Top