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 support@ccsinfo.com

How do you toggle an LED on and off using 12F509

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



Joined: 30 Dec 2008
Posts: 3

View user's profile Send private message

How do you toggle an LED on and off using 12F509
PostPosted: Wed Dec 31, 2008 12:39 pm     Reply with quote

I want to toggle on and off an LED when I press a button, I want it to turn on when I press it and I want it to turn off when I press it again. It also has to repeat so I can do it over and over again.

If someone could please give me some code examples it would really help me out.

THANK YOU
ALLEN
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 31, 2008 2:45 pm     Reply with quote

See the program below. This will flash an LED on and off. That's a good
place to start. Connect a series resistor and an LED to pin B2.
Look at Figure 5 (on page 2) of the link below to see a schematic of the
LED and resistor circuit. Do it the same way, except use pin B2 instead
of pin B0. You can use a resistor from 220 to 470 ohms. I assume your
PIC is running at +5v.
http://www.siriusmicro.com/projects/b2.pdf
Then try this program:
Code:
#include <12F509.h>
#fuses INTRC, NOWDT, NOMCLR
#use delay(clock=4000000)

//==================================
void main()
{

while(1)
  {
   output_high(PIN_B2);
   delay_ms(500);
   output_low(PIN_B2);
   delay_ms(500);
  }
 
}
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