thannara123
Advanced Member level 5
I am trying to read ADC value from AN0 pin of Pic16F72A but not reading the ADC below the cod e what is the problem
Am using interrupt meathod
Whener the GO_DONE = 1; works the ADC stuck .
what is the problem please help me
Am using interrupt meathod
C:
#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);
}
}
Whener the GO_DONE = 1; works the ADC stuck .
what is the problem please help me