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

Need help with WatchDog problem

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



Joined: 05 Apr 2005
Posts: 8

View user's profile Send private message

Need help with WatchDog problem
PostPosted: Mon Jun 20, 2005 12:56 pm     Reply with quote

To all PIC programmer master;

Please help Sad , 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: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jun 20, 2005 1:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 20, 2005 5:07 pm     Reply with quote

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: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jun 20, 2005 5:53 pm     Reply with quote

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);
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