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

How do I blink an LED?...

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








How do I blink an LED?...
PostPosted: Sat Oct 14, 2006 12:12 am     Reply with quote

New to the world of PICs... Ive got a 16f628A, how do I blink an LED so many times? Ive got VSS and VDD connected,wanna use internal clock, and LED is connected to RA2..

Can someone show me an example?
Guest








PostPosted: Sat Oct 14, 2006 1:53 am     Reply with quote

I wrote this code for it but I don't know whats going on but it seems to just hang at the delay.. am I missing something? The LED goes on, but doesnt go off =/

Code:
#include <16F628A.h>
#use delay (clock=4000000)
#fuses INTRC

 main()

 {
int x = 0;

   output_high(PIN_A2);
   delay_ms(1000);
   output_low(PIN_A2);

 }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 1:59 am     Reply with quote

Use the program in this post as a guide:
http://www.ccsinfo.com/forum/viewtopic.php?t=24160&start=5
Ttelmah
Guest







PostPosted: Sat Oct 14, 2006 2:47 am     Reply with quote

As a comment to 'why is the LED staying on', it isn't, but the 'off' period is only going to be perhaps 3uSec, so you will never see it...

Best Wishes
linux123



Joined: 09 Oct 2006
Posts: 17

View user's profile Send private message

Ok
PostPosted: Tue Oct 24, 2006 8:44 am     Reply with quote

This code, it's correct:

#include <16F628A.h>
#use delay (clock=4000000)
#fuses INTRC

main()

{
output_high(PIN_A2);
delay_ms(1000);
output_low(PIN_A2);
delay_ms(1000);
}
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 24, 2006 10:24 am     Reply with quote

Almost there linux123....

The LED will only flash once then hit a sleep statement (added by the compiler). You need to put the code in a 'never ending' while loop. i.e

Code:
#include <16F628A.h>
#use delay (clock=4000000)
#fuses INTRC

main()
{
    while(TRUE)
    {
        output_high(PIN_A2);
        delay_ms(1000);
        output_low(PIN_A2);
        delay_ms(1000);
    }
}


or use a for loop to stop a 'condition always TRUE' compiler warning

Code:

    for (;;)
    {
        ....
    }

_________________
Regards,
Simon.
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