Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <8051.h>
unsigned long count = 0;
// If CPU clock frequency is 12 Mhz,
// Timer0 is incremented 12 million / 12 = 1 million times per second.
// Timer0 counts 65536 clock cycles and then interrupts as it rolls over to 0
// "count" is incremented 1 million / 65536 = 15.258789 times per second
// 10 hours = 10 hours x 60 minutes x 60 seconds = 36000 seconds
// 36000 seconds x 15.258789 counts per second = 549316.4065 = 10 hours
void timer0_isr(void) __interrupt 1 __using 1
{
count++;
}
int main()
{
TMOD = 0x01; // configure timer0 to 16 bit timer
TH0 = 0x00; // set timer0 to count to 65536
TL0 = 0x00;
EA = 1; // enable global interrupt
ET0 = 1; // enable timer0 interrupt
TR0 = 1; // start timer0 running
while(1)
{
if(count == 549316) // 10 hours has passed
{ } // do whatever you want when 10 hours is up here
}
}