AT89S51 Timer sample program required?

Status
Not open for further replies.

prevravanth

New Member
I am using AT89S51 with 11.0592MHz crystal.

I want to make timer for 5 minutes or some customised time.

can u help me some sample source code in C.

can i use 2 timings in same chip if so use timer o and timer 1 for specific timings.

Can some body help in source code.

Thanks
 
Last edited:
sure here you go:

Here is a function to setup the timer interrupts

setup_interrupts(){
EA = 1;
TMOD = 0X22; //timer mode (auto reload)
TH0 = 0; // the auto loaded vaue
TH1 = 200; // the auto loaded vaue
TR1 = 1;
ET0 = 1;
ET1 = 1;
}

now, there are no variables that will hold a 5 minutes delay so you need to do it yourself like in this example:

time_5_min interrupt 1{ //called each time timer 0 counts from 0 to 255
counter1++;
if (counter1 > 250){
counter1 = 0;
counter2++;
if (counter2 > 250){
counter2 = 0;
..
.. //put here the code you want to be executed
..
}
}
}

this will give you delay of 255 * 250 * 250 pulses, i don't know exactly how much time this will give you.. but you should have got the idea!
 
Tell me if you want a compleat source code of a program i wrote that uses timer 0 and timer1 interrupts..

Also a note about using the 2 interrupts at the same time, if the 2 timers have very small time delays, your program will freeze, because each time the processor starts to execute a timer routine, the other timer calls it, and when before it finishes executing the 2nd timer, the first timer calls again.. even if you use priorities, your main program whill never get executed... so be careful
 
Hi

I made a small program that can calculate Delay loops and generate them

you can test it

**broken link removed**

I hope it dose not have any bugs
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…