View previous topic :: View next topic |
Author |
Message |
GSFC PIC
Joined: 05 Apr 2005 Posts: 8
|
Need help with WatchDog problem |
Posted: Mon Jun 20, 2005 12:56 pm |
|
|
To all PIC programmer master;
Please help , I am new with PIC programmer in C, I am having a problem with the program below. I just want to put a "high" on all pins on port D when pin C7 is "high",if not, just put a high on pin D7. The program won't work if I DISABLE the watch dog, it will work fine if I ENABLE the watchdog with the watchdog postscaler set at either 1:1 or 1:128. I am using CCS C PCWH to compile this program. What did I do wrong. Your advice is greatly appreciated. Thanks
#include <PIC18F452.h>
#use delay (clock=4000000)
void main( ) {
set_tris_c(0xff); // set port C as input port
set_tris_d(0x00); // set port D as output port
if (input(PIN_C7)= = 1) // read pin C7
{
output_D(0xFF);
}
else
output_D(0x80);
} |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Jun 20, 2005 1:05 pm |
|
|
It's because the WDT is timing out and resetting your program. The real problem is that you do not have a loop in your main routine and it is hitting the sleep command that CCS C puts at the end of the code.
set_tris_c(0xff); // set port C as input port
set_tris_d(0x00); // set port D as output port
void main( ) {
Do {
if (input(PIN_C7)= = 1) // read pin C7
{
output_D(0xFF);
}
else
output_D(0x80);
}
}while(1); |
|
|
sh1
Joined: 04 Mar 2005 Posts: 5
|
|
Posted: Mon Jun 20, 2005 5:07 pm |
|
|
don't take me wrong, dyeatman, just a small correction.
those 2 set_tris functions should be inside main, just before the do..while statement... ;) |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Jun 20, 2005 5:53 pm |
|
|
Yep you're correct. I was distracted by one of my employees and neglected to put them back where they belong... Thanks for the catch...
void main( ) {
set_tris_c(0xff); // set port C as input port
set_tris_d(0x00); // set port D as output port
Do {
if (input(PIN_C7)= = 1) // read pin C7
{
output_D(0xFF);
}
else
output_D(0x80);
}
}while(1); |
|
|
|