View previous topic :: View next topic |
Author |
Message |
Vodka
Joined: 13 Sep 2007 Posts: 14
|
A very small problem with delay |
Posted: Thu Sep 13, 2007 9:52 am |
|
|
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
|
|
Posted: Thu Sep 13, 2007 10:03 am |
|
|
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
|
|
Posted: Thu Sep 13, 2007 10:32 am |
|
|
i use :
#fuses HS,NOLVP, NOWDT,NOPROTECT
the crystal is external at 20Mhz |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 13, 2007 3:01 pm |
|
|
You have:
#use_delay(clock=20000000)
I hope.
Best Wishes |
|
|
Vodka
Joined: 13 Sep 2007 Posts: 14
|
|
Posted: Fri Sep 14, 2007 4:00 am |
|
|
no i have:
#use delay (clock=20000000) |
|
|
Vodka
Joined: 13 Sep 2007 Posts: 14
|
|
Posted: Sat Sep 15, 2007 6:40 am |
|
|
seems like no one can help me?? i have to try other compliers?? but i love ccs .....should i choose another version??? |
|
|
Ttelmah Guest
|
|
Posted: Sat Sep 15, 2007 9:00 am |
|
|
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
|
|
Posted: Sat Sep 15, 2007 9:20 am |
|
|
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
|
|
Posted: Sun Sep 16, 2007 4:12 am |
|
|
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 [email protected] |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Sep 16, 2007 5:51 am |
|
|
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. |
|
|
|