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

A very small problem with delay

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



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

A very small problem with delay
PostPosted: Thu Sep 13, 2007 9:52 am     Reply with quote

Hi all ccs coders...i have a small issue with delay_ms() function.My code should blink 5 leds connected to port D0-D4 on a pic16f877;my code is here:


#include "D:\CCS WORK\asta.h"


void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

// TODO: USER CODE!!

set_tris_d(0x00);
while(1){
output_high(pin_d0); //leds are off
output_high(pin_d1);
output_high(pin_d2);
output_high(pin_d3);
output_high(pin_d4);
delay_ms(1000); //delay 1 sec
output_low(pin_d0); //led on
delay_ms(1000); //delay 1 sec
output_high(pin_d1);
delay_ms(1000); //delay 1 sec
output_low(pin_d2);
delay_ms(1000); //delay 1 sec
output_high(pin_d3);
delay_ms(1000); //delay 1 sec
output_low(pin_d4);
delay_ms(1000); //delay 1 sec

}
}


When i don`t use delay_ms() sintax the leds are on as they should...but when i put delay_ms(1000) they aren`t doing anything(leds are off).

Please guide me where my mistake is. thank you all
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Sep 13, 2007 10:03 am     Reply with quote

First, when using output_high() or output_low() you don't need to set the tris. The compiler will take care of this for you.

Next, post the #fuses you are using. Are you using the internal oscillator or do you have a crystal attached?

Ronald
Vodka



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

PostPosted: Thu Sep 13, 2007 10:32 am     Reply with quote

i use :

#fuses HS,NOLVP, NOWDT,NOPROTECT

the crystal is external at 20Mhz
Ttelmah
Guest







PostPosted: Thu Sep 13, 2007 3:01 pm     Reply with quote

You have:
#use_delay(clock=20000000)

I hope.

Best Wishes
Vodka



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 4:00 am     Reply with quote

no i have:

#use delay (clock=20000000)
Vodka



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

PostPosted: Sat Sep 15, 2007 6:40 am     Reply with quote

seems like no one can help me?? i have to try other compliers?? but i love ccs .....should i choose another version???
Ttelmah
Guest







PostPosted: Sat Sep 15, 2007 9:00 am     Reply with quote

Seriously, I have compiled the code, with the fuses as quoted, and the delay, and it works.
One thing, where is the delay statement?. It must be after the fuse statement.
What is the compiler version?.
I have tried (just for the hell of it), 3.212, 3.249, 4.051. All worked fine.

Best Wishes
Ttelmah
Guest







PostPosted: Sat Sep 15, 2007 9:20 am     Reply with quote

As a couple more comments.
The placement of the delay statement, doesn't seem to matter on the newer compilers, but better to put it on the next line to 'play safe'. Obvious comment though, how are the LED's connected?. Non operation, could be caused by something electrical, like having the LED's directly connected to the output pins, with no current limiting resistors. Without the delay, they would only be 'on' for a few uSec, and the current internal limiting, and capacitances on the supply line, might allow it to work, but with the delay, they may well simply droop the supply rail, and restart the processor, so quickly, that it looks as if they are not lighting.

Best Wishes
Vodka



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

PostPosted: Sun Sep 16, 2007 4:12 am     Reply with quote

Well i have tried with ccs ver 4.013 but i can`t find any of the version you mentioned... if you please help me with one of those versions just to be sure that the compiler is ok i`ll be very grateful. My e-mail is stea2003@yahoo.com
ckielstra



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

View user's profile Send private message

PostPosted: Sun Sep 16, 2007 5:51 am     Reply with quote

Quote:
Well i have tried with ccs ver 4.013 but i can`t find any of the version you mentioned...
V3.249 is an old but stable release, still available for download from the CCS website. V4.051 has been superseeded by the newer v4.056, also available for download from the CCS site. This all assuming you are an official customer ofcourse.

Quote:
just to be sure that the compiler is ok
V4.013 is known to be very unreliable. It was one of the first v4.0xx releases and very disappointing in quality. The v4.0xx compilers became useable around release v4.030.
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