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

PIC 32 Microcontroller

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



Joined: 06 Jun 2011
Posts: 1

View user's profile Send private message

PIC 32 Microcontroller
PostPosted: Mon Jun 06, 2011 10:50 am     Reply with quote

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>


#define RedLedON()         mPORTDSetBits (BIT_0)
#define RedLedOFF()         mPORTDClearBits (BIT_0)

#define YellowLedON()      mPORTDSetBits (BIT_1)
#define YellowLedOFF()      mPORTDClearBits (BIT_1)

#define GreenLedON()      mPORTDSetBits (BIT_2)
#define GreenLedOFF()      mPORTDClearBits (BIT_2)

const int SW1 = BIT_6;
//#define SW1ON            mPORTDSetBits (BIT_6)
//#define SW1OFF         mPORTDClearBits (BIT_6)

//#define SYS_FREQ      (80000000)   
//void Timing(unsigned int);

int main()
{

mPORTDSetPinsDigitalIn(BIT_6);
mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2);

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2011 11:01 am     Reply with quote

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