View previous topic :: View next topic |
Author |
Message |
yusufselimkaratas
Joined: 24 Oct 2019 Posts: 1
|
Can not read analog input |
Posted: Thu Oct 24, 2019 2:42 pm |
|
|
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
|
|
Posted: Thu Oct 24, 2019 3:36 pm |
|
|
Please read PIC101 sticky....
Quick answer.. Proteus is busted, flawed, corrupt,defective.....
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 24, 2019 6:35 pm |
|
|
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
|
|
Posted: Fri Oct 25, 2019 7:36 am |
|
|
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 |
|
|
|