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

delay problem?

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



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

delay problem?
PostPosted: Wed Mar 09, 2005 12:32 pm     Reply with quote

hi

i am new to ccs and to programming pic with the c language

i made a simple program that output to portb pin 6 of pic 16f877

Code:

#include "E:\pic16f877\ccs\1\1.h"
#use delay(clock=10000000)

void main() {
 while(true)
 {
   output_high(PIN_B6);
   delay_ms( 10 );
   output_low(PIN_B6);
   delay_ms( 10);
 }

}

the problem is that the delay should be 10 milliseconds but in fact it is nearly up to 4 seconds Shocked

so what is the problem

thanks for help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 12:43 pm     Reply with quote

Quote:
#include "E:\pic16f877\ccs\1\1.h"

It wouldn't surprise me if it has something to do with the mysterious "1.h" file.

Your simple program should not look like that, it should look more
like the following one. In this one, you can see the #fuses statement.

Also, I suspect that you may be using ICD2. If so, ICD2 uses pins B6
and B7. You should pick another pin for your output. I assume you
have a demo board. If you have PicDem2-Plus, it has LEDs on pins
B0 to B3. So a good choice for your test program would be pin B0.

Also, what are you using for a crystal or oscillator. Do you guarantee
that it's really running at 10 MHz ? What numbers are stamped on
the crystal or oscillator ?

Code:
#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=10000000)

void main()
{

while(1)
  {
   output_high(PIN_B6);
   delay_ms( 10 );
   output_low(PIN_B6);
   delay_ms( 10);
  }

}
asic1984



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 12:55 pm     Reply with quote

hi

thanks for your help

Quote:

Quote:
#include "E:\pic16f877\ccs\1\1.h"

It wouldn't surprise me if it has something to do with the mysterious "1.h" file.


it was generated by the ccs ...not by me

i am not using any emulator like icd2 i am just using jdm programmer and then put it to a circuit from my design ...so no problem in slected pins


Quote:

Also, what are you using for a crystal or oscillator. Do you guarantee
that it's really running at 10 MHz ? What numbers are stamped on
the crystal or oscillator ?



the oscillator is 10MHZ as what is stamped on the crystal Rolling Eyes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 12:56 pm     Reply with quote

Can you check that your oscillator is really running at 10MHz?. It could be defective and running 400 times slower.

The only thing that is supposed to happen at anywhere near that speed is the Watchdog timer. Try disabling the WDT and see if things change.

Next I would look at the assembly code in the .lst file. If you have ever done assembly code for any uP this simple program should not be hard to figure out.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 1:12 pm     Reply with quote

Quote:
#include "E:\pic16f877\ccs\1\1.h"
it was generated by the ccs ...not by me

I've never heard of this.
What compiler do you have ? Is it PCW ? What version ?
The version is at the top of the .LST file, which is generated when
you compile a program. It will be a number like 3.219 or 3.221, etc.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 09, 2005 3:16 pm     Reply with quote

It wouldn't hurt ya to post what is in 1.h!
asic1984



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 10:22 pm     Reply with quote

hi

that it is the code inside the 1.h file.....
Code:

#include <16F877.h>
#device adc=8
#use delay(clock=10000000)
#fuses HS,WDT
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 10, 2005 6:51 am     Reply with quote

Well as PCM Programmer told you, you have problems there. You have the watchdog timer enabled and are not resetting it. You have LVP enabled. I suggest you try his code.
asic1984



Joined: 09 Mar 2005
Posts: 6

View user's profile Send private message

PostPosted: Thu Mar 10, 2005 9:49 am     Reply with quote

hi

thanks too much i will try it

Idea
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