/********************************************************
*********************************************************
Sample Program for PIC16f1507
Program description:
All ADC channels (listed below) are configured as analog input and the ADC values are read from them.
RA0 - AN0
RA1 - AN1
RA2 - AN2
RA4 - AN3
RB4 - AN4
RB5 - AN5
RC0 - AN6
RC1 - AN7
RC2 - AN8
RC3 - AN9
RC6 - AN10
RC7 - AN11
IDE : MPLAB v8.80
Compiler : Hi tech PICC v9.83
Programed by : Naren Babu.k
Date : 25.01.2011
*********************************************************
********************************************************/
/*Header files include start*/
#include<htc.h>
/*Header files include end*/
/*Macros definition start*/
/*Macros definition end*/
/*Function Decleration start*/
void Delay(unsigned int);
unsigned int Read_ADC8(unsigned char);
unsigned int Read_ADC10(unsigned char);
/*Function Decleration end*/
/*Variable Deleration Start*/
unsigned int ADC_Result_8Bit=0,ADC_Result_10Bit=0,temp;
unsigned int a,b;
/*Variable Deleration end*/
/*Interrupt service routine start*/
/*Interrupt service routine end*/
/*Main function start*/
void main()
{
ANSELA = 0x0F;
TRISA = 0x0F;
ANSELB = 0x30;
TRISB = 0x30;
ANSELC = 0xCf;
TRISC = 0x00;
INTCON = 0b00000000;
while(1)
{
a=Read_ADC8(0);
b=Read_ADC10(0);
if(a>100)
{
}
if(b<100)
{
}
}
}
/*Function definition start*/
void Delay(unsigned int delay_val){while(delay_val--);}
unsigned int Read_ADC8(unsigned char Cha)
{
unsigned int ADC_Res_8bit=0;
ADC_Res_8bit=Read_ADC10(Cha);
return(ADC_Res_8bit>>2);
}
unsigned int Read_ADC10(unsigned char Cha)
{
unsigned int ADC_Res_10bit=0;
if(Cha>11)
{
ADC_Res_10bit=0;
}
else
{
ADCON1 =0b10000000;
ADCON0 =0b00000001;
ADCON0|=Cha<<2;
ADGO =1;
while(ADGO==1);
ADC_Res_10bit=(unsigned int)ADRESH<<8&ADRESL;
}
return(ADC_Res_10bit);
}
/*Function definition end*/