View previous topic :: View next topic |
Author |
Message |
asic1984
Joined: 09 Mar 2005 Posts: 6
|
delay problem? |
Posted: Wed Mar 09, 2005 12:32 pm |
|
|
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
so what is the problem
thanks for help |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 09, 2005 12:43 pm |
|
|
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
|
|
Posted: Wed Mar 09, 2005 12:55 pm |
|
|
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 |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Mar 09, 2005 12:56 pm |
|
|
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
|
|
Posted: Wed Mar 09, 2005 1:12 pm |
|
|
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
|
|
Posted: Wed Mar 09, 2005 3:16 pm |
|
|
It wouldn't hurt ya to post what is in 1.h! |
|
|
asic1984
Joined: 09 Mar 2005 Posts: 6
|
|
Posted: Wed Mar 09, 2005 10:22 pm |
|
|
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
|
|
Posted: Thu Mar 10, 2005 6:51 am |
|
|
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
|
|
Posted: Thu Mar 10, 2005 9:49 am |
|
|
hi
thanks too much i will try it
|
|
|
|