shubham kumar
Member level 3
- Joined
- Sep 11, 2014
- Messages
- 59
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Location
- bangalore
- Activity points
- 511
Hi I am trying to implement the ADC without using the library functions like ADC_init() and ADC_Read().
I followed the data-sheet for the same but didn't got through.
I am using PIC18F452 at a frequency of 20MHz. // (which will be 20/4=5Mhz later)
Here is my code.
I followed the data-sheet for the same but didn't got through.
I am using PIC18F452 at a frequency of 20MHz. // (which will be 20/4=5Mhz later)
Here is my code.
Code:
void AD_init();
int AD_Read(unsigned char );
void main()
{
int i;
unsigned char txt[16];
LCD_init();
AD_init();
while(1){
i=AD_Read(1);
IntToStr(i,txt);
LCD_out(1,1,txt);
LCD_out(2,8,"mikroC");
}
}
void AD_init()
{
ADCON1=0x04; // AN0,AN1,AN3 = analog pins rest as digital
}
int AD_Read(unsigned char pt) //here I am just taking the channel but not using it
{ // late I'll try to make it concatenate in ADCON0 for any channel
int k;
k= (0x01001000 ) ; //channel selection as 1 and clock selection as T/8
ADCON0 = k;
ADCON0.B0=1; //ADC powered on
ADCON0.B2 = 1; Delay_ms(10); //conversion start
while( ADCON0.B2==1); // wait till conversion
k=ADRESH;
return (k);
}