View previous topic :: View next topic |
Author |
Message |
huma
Joined: 23 Jun 2006 Posts: 12
|
Problem |
Posted: Tue Jul 11, 2006 8:27 am |
|
|
hello ,
i want to turn on/off the LED after 5 sec using delay.
i write the following code .but its not changing the value on RD0,plz tell me where is the problem.Its my first program in C for PIC
///////////////////////code////////////////////////////
#include "16f877.h"
#fuses XT,NOWDT
#use delay(clock = 4000000)
void delay_seconds(int n)
{
for(;n!=0 ;n--)
delay_ms(1000);
}
void main()
{
set_tris_d(0x00);
while(true)
{
output_high(pin_D0);
delay_seconds(5);
output_low(pin_D0);
}
}
/////////////////////////////////////////////////  |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jul 11, 2006 8:50 am |
|
|
A classic error.
After setting the output_low a delay is missing, on the next instruction the processor will call ouput_high again. Too fast for your eye to see.
Code: | while(true)
{
output_high(pin_D0);
delay_seconds(5);
output_low(pin_D0);
delay_seconds(5); // Add this line
} |
|
|
 |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Jul 11, 2006 8:51 am |
|
|
Please post code using the code button.
You messed up in the while loop. If you follow the logic around
high
delay
low
high //you don't delay before this and you will not see the previous low
delay
low
high
...beat me by a min. :o) |
|
 |
huma
Joined: 23 Jun 2006 Posts: 12
|
|
Posted: Wed Jul 12, 2006 12:53 am |
|
|
Thanks a lot ckielstra and treitmey.
its running well now.
Thanks once again. |
|
 |
|