View previous topic :: View next topic |
Author |
Message |
ctest
Joined: 29 Aug 2023 Posts: 5
|
Reading PORTC problem |
Posted: Tue Aug 29, 2023 6:13 am |
|
|
I have simple hardware as in the picture. I wrote the software for it. The LED is always lit regardless of the button. Port c5 always reads low state. What could be the problem?
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT,NOPROTECT, NOLVP, NOMCLR
//#use I2C(MASTER, I2C1, SLOW = 100000, STREAM = DS1307_STREAM)
#use delay(clock = 8MHz)
void main()
{
output_float(PIN_C4);
while(1){
if(input(PIN_C4)==0){
output_high(PIN_A1);
}
else{
output_low(PIN_A1);
}
}
} |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Tue Aug 29, 2023 7:13 am |
|
|
First you need to tell us the PIC you're using and the compiler version.
BOTH are necessary...
Your code accesses Port C.4, not C.5...which is confusing.
possible reasons
'Always low' could easily be a short on the PCB from C.5 to ground.
An unknown internal peripheral could be setting that pin low.
What is externally attached to the pin ?
perhaps you've got a low value pullup resistor wired as a pulldown ?
Does the PIC run a 'flashing 1Hz LED' program at the correct frequency ? |
|
|
ctest
Joined: 29 Aug 2023 Posts: 5
|
|
Posted: Tue Aug 29, 2023 8:16 am |
|
|
Thank you,
I am using 18f4550 microcontroller and pic CCS c compiler. I have the same devices connected to pin C5 and to pin C4. The first optocoupler H11AA1x is connected to C4, and the second optocoupler H11AA1x is connected to C5. Pin 5 of H11AA1x is connected to C4 (C5) of microcontroller 18f4550. A 10k pull-up resistor is connected to that connection. I measured the voltage on pin C4 and C5. It is 3V. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Tue Aug 29, 2023 8:26 am |
|
|
Is Vusb connected?.
The pins can only be used as normal digital inputs, if this is done. The
input gate requires this.
What compiler version?.
Since these are the USB pins, some old versions may not configure these
correctly. |
|
|
ctest
Joined: 29 Aug 2023 Posts: 5
|
|
Posted: Tue Aug 29, 2023 10:05 am |
|
|
Thank you,
I am using CCS c compiler version 5.109. Vusb is not connected. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Tue Aug 29, 2023 10:12 am |
|
|
It needs to be.
Problem is that the 'off' USB drivers short out one of the two pins if not
powered. Microchip did have a note that the peripheral needs to be powered
even if not used. |
|
|
ctest
Joined: 29 Aug 2023 Posts: 5
|
|
Posted: Tue Aug 29, 2023 1:40 pm |
|
|
Sorry, on vUSB is 3 V. |
|
|
ctest
Joined: 29 Aug 2023 Posts: 5
|
|
Posted: Tue Aug 29, 2023 2:38 pm |
|
|
Ttelmah thanks, problem solved. On this way:
I set addresses UCFG and UCON
#word UCFG = 0X0F6F;
#WORD UCON=0X0F6D;
#include <main9.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT,NOPROTECT, NOLVP, NOMCLR//no MCLR needed for my board
#use delay(clock = 8MHz)
#word UCFG = 0X0F6F;
#WORD UCON=0X0F6D;
void main()
{
UCFG=8;
UCON=0;
for(;;){
if(input(PIN_C4)==0){
output_high(PIN_A1);
}
else{
output_low(PIN_A1);
}
}
}
Thanks again, best regards. |
|
|
|