View previous topic :: View next topic |
Author |
Message |
Guest
|
How do I blink an LED?... |
Posted: Sat Oct 14, 2006 12:12 am |
|
|
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
|
|
Posted: Sat Oct 14, 2006 1:53 am |
|
|
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
|
|
|
Ttelmah Guest
|
|
Posted: Sat Oct 14, 2006 2:47 am |
|
|
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
|
Ok |
Posted: Tue Oct 24, 2006 8:44 am |
|
|
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
|
|
Posted: Tue Oct 24, 2006 10:24 am |
|
|
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
_________________ Regards,
Simon. |
|
|
|