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

Problems with rebooting....help

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



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Problems with rebooting....help
PostPosted: Wed Jun 02, 2004 4:08 pm     Reply with quote

Im using a PIC 16F819 with a 8Mhz clock. Im using a very simple code and it keeps rebooting the pic. Here is the code, this was made very fast so im sure there is errors somwehere but im hyped on caffeine and cant seem them. Thanks in advance guys.
Bryan

#include <16F819.H>

#use delay(clock=8000000)
#use rs232(baud=19200, xmit=PIN_A1, rcv=PIN_A0)
#use I2C(master, sda=PIN_B4, scl=PIN_B5, fast)

#define FireSmoke1 PIN_B0
#define FireHeat1 PIN_B1
#define FireSmoke2 PIN_B2
#define FireHeat2 PIN_B3

int alarmstatus;
int counter;
int currentchar;



void receiveFireStatus()
{
if(input(FireSmoke1)==1)
{

puts("There is a Smoke Alarm in Room 1, Please Evacute the area.");
alarmstatus=1;
}
if(input(FireHeat1)==1)
{

puts("There is a Heat Alarm in Room 1, Please Evacute the area.");
alarmstatus=1;
}
if(input(FireSmoke2)==1)
{

puts("There is a Smoke Alarm in Room 2, Please Evacute the area.");
alarmstatus=1;
}
if(input(FireHeat2)==1)
{

puts("There is a Heat Alarm in Room 2, Please Evacute the area.");
alarmstatus=1;
}
if(alarmstatus==1)
return;
else
{

puts("Room 1 status:No Fire ............ Room 2 status:No Fire");
}
}

void receiveFireRoom1()
{
if(input(FireSmoke1)==1)
{

puts("There is a Smoke Alarm in Room 1, Please Evacute the area.");
alarmstatus=1;
}
if(input(FireHeat1)==1)
{

puts("There is a Heat Alarm in Room 1, Please Evacute the area.");
alarmstatus=1;
}
if(alarmstatus==1)
return;
else
{

puts("Room 1 status:No Fire");
}

}

void receiveFireRoom2()
{
if(input(FireSmoke2)==1)
{

puts("There is a Smoke Alarm in Room 2, Please Evacute the area.");
alarmstatus=1;
}
if(input(FireHeat2)==1)
{

puts("There is a Heat Alarm in Room 2, Please Evacute the area.");
alarmstatus=1;
}
if(alarmstatus==1)
return;
else
{

puts("Room 2 status:No Fire");
}
}

void main()
{
setup_adc_ports( NO_ANALOGS );
alarmstatus=0;
puts("The fire alarm system is connected and running.");
counter=0;
while(1!=0)
{
while(counter!=2)
{
if(counter==0)
{
puts("Press A for system status, press B for room 1 status,");
puts(" press C for room 2 status. ");
counter++;
}
currentchar=getc();

if(currentchar=='a'||currentchar=='b'||currentchar=='c')
counter++;
else
{
puts("You have entered an incorrect character please try again.");
}
}

if(currentchar=='a')
receiveFireStatus();
if(currentchar=='b')
receiveFireRoom1();
if(currentchar=='c')
receiveFireRoom2();
puts("You have entered an incorrect character please try again.");
}

}

My output looks like this

"The fire alarm system is connected and running. Press A for system status, press B for room 1 status, press C for room 2 status.
The fire alarm system is connected and running. Press A for system status, press B for room 1 status, press C for room 2 status.
The fire alarm system is connected and running. Press A for system status, press B for room 1 status, press C for room 2 status.
The fire alarm system is connected and running. Press A for system status, press B for room 1 status, press C for room 2 status.
" and so on till I hit disconnect in hyperterminal.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Jun 02, 2004 4:44 pm     Reply with quote

If your Watchdog is enabled you will need a restart_wdt() command in there to reset the timer to keep it from resetting the pic. A good place is in your while(1) that loops inside of main().

Ronald
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Thanks
PostPosted: Wed Jun 02, 2004 4:56 pm     Reply with quote

Well I turned off the watchdog_timer, but now when i press 'a', 'b', or 'c' it just reboots. Is there a flaw in my logic? spam this is killing me. Thanks in advance guys.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 02, 2004 5:28 pm     Reply with quote

You don't show a #fuses statement, which I think is ominous.

I wonder if you have NOLVP in your #fuses statement ?
I suspect that you need it.
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

It was the puts statements
PostPosted: Wed Jun 02, 2004 5:46 pm     Reply with quote

I changed those to printf(""); and it seemed to work alot better.
Thanks for the help guys.
Bryan
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