I am trying to program a microcontroller in such a way that, when switch 1 is pressed the red led will turn ON, and when I press the switch 1 again, the red led will switch off, and then the yellow led will switch on when the switch 1 on pic32 microcontroller is pressed. I was wondering if any1 know how to use a counter to keep track of the number of times the switch has been pressed. This is all I could write, I will really appreciate if someone will br able to help me out
Code:
/* Switch and Traffic Light exercise*/
/* Adds support for PIC32 Peripheral library functions and macros */
#include <plib.h>
#include <p32xxxx.h>
#include <GenericTypeDefs.h>
int n;
int i;
while(1) {
for (i = 0; i < 5; i++)
{
n = mPORTDReadBits (SW1);
if (n) mPORTDClearBits(BIT_0);
}
else
{
mPORTDSetBits(BIT_0);
}
}
return 0;
}
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
Posted: Mon Jun 06, 2011 11:01 am
You are in the wrong place... You posted Microchip C code and this is the
CCS C forum. The two compilers are not compatible.
You need to go to the Microchip forum:
http://www.microchip.com/forums/ _________________ Google and Forum Search are some of your best tools!!!!
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