Activating free output pins?

Hi everyone,

I am having issues with the functionality of the available outputs. I am using serial communication so my PD0 and PD1 are being used, leaving me only PC5 to use as an output. I am trying to use the information being received from serial to turn on PC5 at specified times. For some reason, I have been having a lot of difficulties. At first I thought it was a problem with processing the serial, but now I am thinking it may be how I am activating PC5.

Are there any examples of code showing how to control PC5? I want to compare mine with it.

Thanks!

First you have to set the direction of the pin (DDRC)
Then write a 1 or 0 to the pin. You change the values of the register as a whole, so you have to use bitwise operators.

DDRC |= (1<<PORTC5); //Set pin 5 (the 6th) as an output - the data direction register wil be 'OR'ed with 00100000' 
PORTC |= (1<<PORTC5);  //Turn pin on port register will be 'OR'd with the same value above.
PORTC &=  ~(1<<PORTC5);  //turn pin off - port register will be 'AND'ed with the inverted form of 00100000, which is 11011111.

That should work. DDRC only needs to be set once.

Hello.

Another user basically just posted the same question. Rather than repeat my response, I’ll just link you to it here:

- Ben