#define TM0_RUN (0<<7) //TM0运行 #define TM0_PAUST (1<<7) //TM0暂停 #define TM0_DIV4 (0<<4) //Fsys/4 #define TM0_DIV1 (1<<4)// Fsys #define TM0_DIVH16 (2<<4) //Fh/16 #define TM0_DIVH64 (3<<4) //Fh/64 #define TM0_FTBC (4<<4) //Ftbc #define TM0_YULIU (5<<4) //保留 #define TM0_TCKS (6<<4) //TCK0上升沿时钟 #define TM0_TCKX (7<<4) //TCK0下降沿时钟 #define TM0_ON (1<<3)//TM0ON #define TM0_OFF (0<<3)//TM0ON #define BIJIAO_MODE (0<<6)//b比较匹配输出模式 #define NONO_MODE (1<<6)//未定义模式 #define PWM_MODE (2<<6)//PWM输出模式 #define TM0_MODE (3<<6)//定时/计数模式 #define TM0_PPP (0<<0) //p匹配 #define TM0_PPA (1<<0) //A匹配 #define fsys 12/4//12M / 4分频设置_tm0c0 //#define T50US_VAL 50*fsys//(1024-fsys*50) #define T100US_VAL 100*fsys//724//(1024-fsys*100)//==724 void tm0_init(void) { _tm0c0 = TM0_RUN|TM0_DIV4|TM0_OFF;//|0x02 _tm0c1 = TM0_MODE|TM0_PPA; // _tm0dl =T100US_VAL % 256;// 212;// //设置定时器0 // _tm0dh =T100US_VAL / 256;// 2; _tm0al =T100US_VAL% 256; //212;T100US_VAL //设置定时器0 _tm0ah =T100US_VAL/256;//2; T100US_VAL _t0af = 0;//中断请求标志位 _t0on = 1;//定时器开始计时 _mf0e = 1;//多功能中断请求标志 _t0ae = 1;//中断使能 }