MCU restarting after few seconds

Status
Not open for further replies.

Chullaa

Advanced Member level 4
Joined
Aug 27, 2010
Messages
113
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,298
Activity points
2,019
Hi

I am using PIC16F877A, CCS C v4.057, and proteus v7.7. I made a LED fleshing cube and it is working fine. But my program is restarting after few seconds. I have disabled WDT. CLOCK= 4MHZ

SCHEMATIC

Code:
#include "J:\Data\UIT WORK\FYP\Workshop\Material\lecture 04\LED PROJECT\CODE\led project.h"
void TRBL(int k);
void TRBL_Rv(int k);
void TRBL_all(int k,int j);
void msd(int td);

#define fo portb0
#define ba portb1
#define to portb2
#define le portb3
#define ri portb4
#define bo portb5



unsigned int k,i,j;
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   TRISB=0x00;
   PORTB=0x00;
   while(1)
   {
   TRBL(500);
   TRBL_RV(500);
   TRBL_all(3,500);
   
   }
}

void TRBL(k)
{
to=1;             // top on
delay_ms(k);
to=0;
ri=1;             //right on
delay_ms(k);
ri=0;
bo=1;             //bottom on
delay_ms(k);
bo=0;
le=1;             //left on
delay_ms(k);
le=0;
}

void TRBL_Rv(k)
{
to=1;             // top on
delay_ms(k);
to=0;
le=1;             //left on
delay_ms(k);
le=0;
bo=1;             //bottom on
delay_ms(k);
bo=0;
ri=1;             //left on
delay_ms(k);
ri=0;
}
void TRBL_all(k,j)
{
while(k>0)
   {
   to=le=ri=bo=1;
   delay_ms(j);
   to=le=ri=bo=0;
   j=j*2;
   delay_ms(j);                                                                           ///////////////Here is my PROGRAM RESTARTS
   k--;
   }
}

void msd(int td)
{
for(i=0;i<td;i++)
   for(j=0;j<135;j++)
   {}
}
 

There are 6 LEDs connect to each side of a cube(box). Now i want to flash these leds in different patterns, like disco ball. No relay driving. just 6 led connected connected to ports.

All peripheral are disabled because i only need IO operation. and time delay.

Thanks
 

Just clear watchdog timer first in delay,if problem solves then it means that configuaration bits are not properly set.
 

Hi
hear you are using the variable as int, but in this the the variable only the limit of 256, and how it be getting the 500 and (500*2) in to the variable, try to change the variable int16 in your compiler, and check it once again..
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…