CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Can not read analog input

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yusufselimkaratas



Joined: 24 Oct 2019
Posts: 1

View user's profile Send private message

Can not read analog input
PostPosted: Thu Oct 24, 2019 2:42 pm     Reply with quote

Hello, I am using PIC16F887 on Proteus and can not read analog voltage. It always returns 0. Any help will be appreciated.

Thanks.
Code:

#INT_AD
void  AD_isr(void)
{

}

#INT_RDA
void  RDA_isr(void)
{

}

void main()
{
   int deger;
   setup_adc_ports(AN0);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_bit);      //128 us overflow
   
   


   setup_adc(ADC_CLOCK_DIV_8);
   enable_interrupts(INT_AD);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   //Example blinking LED program
   while(true)
   {
     set_adc_channel(0);
  delay_us(20);
  deger = read_adc();
      output_low(LED);
      delay_ms(DELAY);
      fprintf(PORT1,"%d",deger);
      output_high(LED);
      delay_ms(DELAY);
   }

}
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 3:36 pm     Reply with quote

Please read PIC101 sticky....

Quick answer.. Proteus is busted, flawed, corrupt,defective.....

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 24, 2019 6:35 pm     Reply with quote

Besides the Proteus problems, you have these flaws in your program:

1. #INT_AD is not needed to read the ADC. Remove the routine.

2. #INT_RDA has no code in it to read the UART. Remove the routine.

3. The following 3 lines are not needed, because interrupts are not
needed in a test program to read the ADC. Remove these lines:
Code:

enable_interrupts(INT_AD);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);


4. You did not post your #fuses, #use delay(), #use rs232(), and
#device lines. Something could be wrong in those lines that we can't see.
Post them.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Fri Oct 25, 2019 7:36 am     Reply with quote

DELAY is not defined also PORT1.

The program is very simple, use real hardware, that PIC have inside debugger and you are paying for it.
_________________
Electric Blue
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group