timer.c

Go to the documentation of this file.
00001 /*
00002  * main timing control
00003  *
00004  * (c) 2007 by Matthias Arndt <matthias.arndt@tu-clausthal.de>
00005  *
00006  * we generate Timer interrupts every single ms and signal if 62ms have passed
00007  * this generates a semaphore signal which in turn activates sensor sampling in the main loop
00008  */
00009 
00012 #include "t89c51cc02.h"
00013 #include "datatypes.h"
00014 #include "timer.h"
00015 
00022 volatile bit measurement_task; 
00023 
00025 BYTE timekeeper;
00026 
00032 void Timer_init()
00033 {
00034         measurement_task=0;     
00035 
00036         TR0=0;          /* stop Timer 0 */
00037         TMOD |= 1;      /* Timer 0 Mode 1 */
00038         TF0=0;          /* clear timer flag */
00039 
00040         timekeeper=TIMER_MILLISECONDS;
00041 
00042         /* initial timing value */
00043         TH0=TIMER_RELOAD_H;
00044         TL0=TIMER_RELOAD_L;
00045         
00046         TR0=1;          /* start Timer 0 */
00047         ET0=1;          /* activate Timer 0 interrupt */
00048 }
00049 
00056 void Timer_interrupt(void) interrupt 1 using 2
00057 {
00058         timekeeper--;
00059         if(timekeeper==0)
00060         {
00061                 measurement_task=1;     /* signal next sensor sampling is due */
00062                 timekeeper=TIMER_MILLISECONDS;
00063         }
00064         
00065         /* reload Timer 0 */
00066         TH0=TIMER_RELOAD_H;
00067         TL0=TIMER_RELOAD_L;
00068         TF0=0;          /* acknowledge Timer 0*/
00069 }

Generated on Wed Oct 24 12:57:24 2007 for SensorControl by  doxygen 1.4.6