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

Problem

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



Joined: 23 Jun 2006
Posts: 12

View user's profile Send private message

Problem
PostPosted: Tue Jul 11, 2006 8:27 am     Reply with quote

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);
}
}

///////////////////////////////////////////////// Question
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jul 11, 2006 8:50 am     Reply with quote

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

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

PostPosted: Tue Jul 11, 2006 8:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 12, 2006 12:53 am     Reply with quote

Thanks a lot ckielstra and treitmey.
its running well now.
Thanks once again.
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