Hello friends, I'm working on a simple project of the cyclic timer with AT89s52.
I have attached all the require snaps of my Circuit design, Schematic & Program.
The Problem associated with the hardware is after completion of 10 to 12 cycles of ON time=~4.5 sec and OFF time=~3 min, the controller output remains continuously ON. After restarting the power or pressing the RESET button it works as per expectation. the nature of this error is random sometimes it keeps the load on for more than 9s.
Suggest me if there is an error in my circuit design or relay/transistor portion.
Thank you in advance. Here is the code & snaps
<pre>
#include<reg51.h>
sbit led=P2^0; //Led connected to port-2 pin#0
void delay1(){int count1=0; while(count1!=2250) { TMOD=0x01; //16-bit timer0 selected TH0=0xF8; // Loading high byte in TH TL0=0xCC; // Loaded low byte in TL TR0=1; // Running the timer while(!TF0); //Checking the timer flag register if it is not equal to 1 TR0 = 0; // If TF0=1 stop the timer TF0 = 0; // Clear the Timer Flag bit for next calculation
count1++; }
}void delay2(){int count2=0;int count3=0;for(count3=0; count3<180;count3++){ for(count2=0; count2<500;count2++) { TMOD=0x01; //16-bit timer0 selected TH0=0xF8; // Loading high byte in TH TL0=0xCC; // Loaded low byte in TL TR0=1; // Running the timer while(!TF0); //Checking the timer flag register if it is not equal to 1 TR0 = 0; // If TF0=1 stop the timer TF0 = 0; // Clear the Timer Flag bit for next calculation
} }
}
void main(){P2=0x00; //Port-2 Declared Output
while(1) // Constantly running while loop.{led=0; // LED glows heredelay1(); // ON DELAYled=1; // LED switch offdelay2(); // OFF DELAY}
</pre>