|
|
View previous topic :: View next topic |
Author |
Message |
CCSguest Guest
|
INPUT PIN stays high at all times!! |
Posted: Thu Apr 26, 2007 7:50 pm |
|
|
Hi!
I am testing the PIC18F4550 with a simple code below. The LEDs turn on using the OUTPUT_HIGH funtion; however, PIC ran through the entire code without us feeding a high voltage to the input PINs.
I suspect that the state of the INPUT pins might have stayed high the whole time. Is this a programming or hardward problem? Could someone please be so kind and help me with my problem?
Thank you so much!
[#include <18F4550.h>
#include <stdlib.h>
#include <stdio.h>
#USE standard_io(D)
#USE standard_io(B)
#USE standard_io(A)
#fuses HS,NOWDT,NOPROTECT,NOLVP
#USE delay(clock=20000000)
#USE rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, stream=com5)
void main()
{
int x=0;//counter for do while loop
do{
output_high(PIN_A0);
delay_ms(1000);
output_low(PIN_A0);
delay_ms(1000);
output_high(PIN_A0);
delay_ms(1000); //turn LED1 on, off, on
while(!input(PIN_A5)); //waits til PIN_A5 is HIGH
output_high(PIN_A1);
delay_ms(1000);
output_low(PIN_A1);
delay_ms(1000);
output_high(PIN_A1);
delay_ms(1000); //turn LED2 on, off, on
while(!input(PIN_A2)); //waits til PIN_A2 is HIGH
output_high(PIN_A3);
delay_ms(1000);
output_low(PIN_A3);
delay_ms(1000);
output_high(PIN_A3);
delay_ms(1000); //turn LED3 on, off, on
while(!input(PIN_B6)); //waits til PIN_B6 is HIGH
output_high(PIN_B7);
delay_ms(1000);
output_low(PIN_B7);
delay_ms(1000);
output_high(PIN_B7);
delay_ms(1000);
x++;
}while(x < 3);
}
] |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Apr 27, 2007 1:57 am |
|
|
Many I/O-pins on the PIC processor can be configured to perform one of several functions, for example pin A5 can be a digital input, a digital output, an analog input, a Slave Select input for SSP and some more. Because of hardware design some of these functions will disable the pin to be used for one of the other functions. For example, when a pin is configured as analog input it can not be used as a digital input anymore. Check the datasheet Table 10-1 for details.
On power up most PIC processors have the I/O-pins configured as analog inputs, overruling the digital input function for your pins A2 and A5. I didn't check, but it might be possible pin B6 reads a high level input because it's pull-up resistor is activated (some versions of the CCS compiler do add this code to the startup code).
Try if things improve by adding the following code to the start of main(): Code: | setup_adc_ports(NO_ANALOGS);
setup_comperator(NC_NC_NC_NC);
port_B_pullups(FALSE); |
|
|
|
|
|
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
|