NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Checking a Pins Status
February 04, 2011 by Twarter369 ![]() |
What is a simple way I an check the status of a pin in my code? For instance if(PC3==1) PORTC &= (1<<PC3) else PORTC |= (1<<PC3) Something like that to create a toggle effect would be great! I am trying to send a message from my GUI (c++ for the desktop and PHP for the web)to get the state of individual pins so I can find out if something is already on before I try to turn it on again. |
---|---|
February 04, 2011 by bretm ![]() |
PC3 is just a constant, so doing "if (PC3==1)" won't work. To check if pin PC3 is set, you can do
To read the value of PC3 as a 0 or 1 bit:
To toggle pin PC3:
|
February 04, 2011 by Twarter369 ![]() |
Okay thanks. I will try those snippets, Thanks! Another problem I am running into is a two step Write/Read. I am sending a character from my GUI (t). On the chip is a line that fires a method when it receives that character. Part of that method is to write back to the serial port the temp. In the c++ I have
where chipIO is my SerialPort^ connection. I have verified the writing is working fine. When I go to read the line back I get an "Unathorized Access" Error? |
Please log in to post a reply.
Did you know that a piezoelectric buzzer can be used to play music with your microcontroller? Learn more...
|