[PIC] 5v and 0v to digital value Conversion and blink LED accordingly in ADC of PIC16F887

Status
Not open for further replies.

Pari Boopathy

Newbie level 6
Joined
Mar 13, 2014
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
94
Hi,, i am new to tis ADC Module.. i m using PIC16F887+MPLAB IDE-Hi-Tech C.....

I ve some doubts,, i ve to give 5v to RA0 pin and 0v to RA1 pin of microcontroller..I just connected 2 LED's as output in any other port,,say PORTD.
Wen i m giving 5v,,one LED will blink and if 0v another LED will Blink..
In my program,, i first convert 5v to digital val(1111111111) and 0v to (0000000000)..Then check,,whether if its all 1,blink one LED..
Prgm:


Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
ADCON0=0x01;
ADCON1=0x80; 
 Val=ADRESH;
 Val=(Val<<8)|ADRESL;
 PORTD=Val;
 if(PORTD=0xFF)
 {
   RD0=1;
 }
  else RD1=1;

 

Is the above mentioned is your complete program.

Where are you checking, whether the ADC conversion is completed or not.

I mean this type of code.


Code C - [expand]
1
2
3
4
5
6
ADCON0bits.GO = 1;    //Start Conversion
        while(ADCON0bits.GO == 1);
        //Wait here until Conversion Complete
        adc_data = ADRESH & 0x00FF;
        adc_data = adc_data<<8;
        adc_data = adc_data | ADRESL;



If you dont know how to use adc, you can take help from google.
Have a look at this example also.
 

Ok,,i ill check it out..I ve to use channel2/RA1..So i set ADCON0=0x05...But,Channel1/RA0 is gettng enabled instead of Channel2/RA0.....
 

By updating the ADCON0 register value is enough or not??
For channel-1,, ADCON0 =0x05 [CHS3:CHS2:CHS1:CHS0=0:0:0:1 ;ADON=1]...But its not working...
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…