|
|
View previous topic :: View next topic |
Author |
Message |
BMaxwell
Joined: 07 May 2004 Posts: 20
|
Problems with rebooting....help |
Posted: Wed Jun 02, 2004 4:08 pm |
|
|
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
|
|
Posted: Wed Jun 02, 2004 4:44 pm |
|
|
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
|
Thanks |
Posted: Wed Jun 02, 2004 4:56 pm |
|
|
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
|
|
Posted: Wed Jun 02, 2004 5:28 pm |
|
|
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
|
It was the puts statements |
Posted: Wed Jun 02, 2004 5:46 pm |
|
|
I changed those to printf(""); and it seemed to work alot better.
Thanks for the help guys.
Bryan |
|
|
|
|
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
|