ADC problem in mikroC

Status
Not open for further replies.

swapan

Full Member level 4
Joined
Feb 20, 2009
Messages
199
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Activity points
2,806
Hi friends,

I am trying to implement ADC module of 16F676 in MikroC. Please see the code below. A LED, connected to RA5 of MCU is made ON/OFF depending on the value of analogue input to AN4 of MCU. I have tested the hardware developing the code in assembly. But when I try to develop the code in MikroC, it does not work. No effect is seen in output (RA5) while varying the input analogue voltage at AN4. Please suggest an way out.


swapan


Code:
int g_volt;

void main() {

     TRISC    =   0x00;
     TRISA    =   0x7;

     ANSEL    =   0x30;
     CMCON    =   0x7;
     do {

     g_volt = ADC_Read (4);       // Take adc at channel AN4

     if  (g_volt > 108)
     PORTA= 00100000;             // Turn ON LED at RA5
else
     PORTA= 00000000;             // Turn OFF LED at RA5
     }  
     while (1);
}
 

hello

try TRISA=0x1F;
to put RA4 as input..
if Ana4 is on RA4
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…