View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
No response from PIN_A1 |
Posted: Thu Dec 08, 2005 2:57 pm |
|
|
I have the following simple program:
I want to wait for a input from pin A1 and then print out something, however, my program went to an endless loop, even I put PIN_A1 high (by connecting to 5V) and in the loop, it is print out as 0, why?
Code: |
#if defined(__PCM__)
#include <16f76.h>
#fuses HS, NOBROWNOUT,NOWDT,NOPROTECT,NOPUT
#use delay(clock =8000000)
#use RS232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7)
main()
{
setup_adc(ADC_OFF);
set_tris_a(0x0F);
while(1)
{
printf("waiting signal\r\n");
while(!input(PIN_A1))
{printf("Pin_A1 is: %u\r\n",INPUT(PIN_A1));
delay_ms(100);
}
printf("waiting signal1\r\n");
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 08, 2005 3:22 pm |
|
|
It could be that CCS is not setting up Port A for digital i/o.
Post your compiler version. I'll check the .LST file. |
|
|
Guest
|
|
Posted: Thu Dec 08, 2005 3:33 pm |
|
|
thank you:
It is version 3.202 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 08, 2005 3:43 pm |
|
|
There's a bug in the CCS start-up code for your version.
They're setting up Port A for all analog i/o pins.
To fix it, add the line shown in bold below, at the top of main():
Quote: |
main()
{
setup_adc_ports(NO_ANALOGS);
}
|
|
|
|
Guest
|
|
Posted: Thu Dec 08, 2005 3:53 pm |
|
|
THANK YOU. YOU ARE RIGHT!
I THOUGHT setup_adc(ADC_OFF); ALREADY SET THE PORT AS DIGITAL INPUT/OUTPUT. |
|
|
|