|
发表于 2012-3-5 04:16:46
|
显示全部楼层
first of all, you should learn to ask good questions.
2ndly, it will depend on how your code.
3rd, generally, you should try to preseve the portion of TMOD that your code doesn't touch. For example, if your pwm uses just TMR0, you should set up TMOD this way:
#define TMR_MODE0 0x00 //tmr mode0
#define TMR_MODE1 0x01 //tmr mode1
#define TMR_MODE2 0x02 //tmr mode2
#define TMR_MODE3 0x03 //tmr mode3
#define TMR_GATED 0x08 //tmr dated
#define TMR_COUNTER 0x04 //tmr as counter
#define TMR_TIMER 0x00 //tmr as timer
void tmr0_init(unsigned char mode) {
TR0 = 0; //stop the timer
TMOD = (TMOD & 0xf0) | (mode & ~0xf0);
//you may wish to initialize the tmr/counters now
TR0 = 1; //start the timer
}
so in your code, you set tmr0 accordingly:
tmr0_init(TMR_TIMER | TMR_MODE1); //set tmr0 as timer, not gated and in mode1 |
|