??? 06/07/06 18:08 Read: times |
#117968 - some C code Responding to: ???'s previous message |
#include <reg52.h>
void main (void) { // Timer 0 init ET0=1; TMOD=0x01; TH0=0x3c; TL0=0xb0; TR0=1; // Timer 2 init T2CON = 0x00; TH2 = 0xec; TL2 = 0x77; RCAP2H = 0xec; RCAP2L = 0x77; TR2 = 1; IE |= 0xA0; while(1); eldelss loop } void Timer2_IntHandler (void) interrupt 5 using 2 { TF2 = 0; // stop timer2 EA=0; // some usefull code here EA=1; // start timer2 } void Timer0_IntHandler(void) interrupt 1 using 1 { TR0=0; // stop timer0 TH0=0x3c; TL0=0xb0; TR0=1; // srart timer0 // some usefull code here } If you are new to uC programming you'll have to read carefully the datasheet for your uC. So you can reveal the meaning of some lines of this code, like TH0,TL0, RCAP1,RCAP2 and etc. Timers are counting up from value that you specify ( usualy 16 bit number divided into two bytes ) untill 0xff when interrupt occurs. Then interrupt routine is executed. It is important to have some example code working for start. This code does nothing until you write some additional lines, but it is code structure for timer interrupt handling. Best, Dmitri |
Topic | Author | Date |
Need C code for Interrupt cnt and timmer | 01/01/70 00:00 | |
jumping ahead | 01/01/70 00:00 | |
Thanks you | 01/01/70 00:00 | |
general info | 01/01/70 00:00 | |
You already have it! | 01/01/70 00:00 | |
some C code | 01/01/70 00:00 | |
thanks![]() | 01/01/70 00:00 |