#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include"lcd.h"
#include<stdio.h>
#define _XTAL_FREQ 1600000
unsigned int adc;
__interrupt isr()
{
if(ADIF==1)
{
adc = ADRES;
GO_DONE = 1;
}
}
void adc_initilize()
{ ADCON0 = 0x81; // 32 Tosc 7 ADC ON
ADCON1 = 0x05; // all input makes analog input
ADIE=1; //Enables the ADC interrupt
ADIF=0; //clear the A/D Converter Interrupt interrupt flag
__delay_us(40);
}
void main(void)
{ unsigned char buffer[8];
OPTION_REG &= 0x7F;
TRISB =0x00;
TRISA=0x01;// for adc first channel as input
unsigned int i;
TRISB =0x00;
GIE =1;
PEIE = 1;
LCD_init();
adc_initilize();
LINE1;
string(" ADC");
LINE2;
string("Stuck Here1");
LINE1;
while(1)
{
// ADCON0 = ADCON0|(0X04); // ADC starting GO/DONE Bit setting
GO_DONE = 1;
LINE1;
string("ADC Reading");
LINE2;
sprintf(buffer,"%d",adc);
}
}