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

Reading PORTC problem

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



Joined: 29 Aug 2023
Posts: 5

View user's profile Send private message

Reading PORTC problem
PostPosted: Tue Aug 29, 2023 6:13 am     Reply with quote

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: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 7:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 8:16 am     Reply with quote

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: 19551

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 8:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 10:05 am     Reply with quote

Thank you,
I am using CCS c compiler version 5.109. Vusb is not connected.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 10:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 1:40 pm     Reply with quote

Sorry, on vUSB is 3 V.
ctest



Joined: 29 Aug 2023
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 29, 2023 2:38 pm     Reply with quote

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.
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