- UID
- 112652
- 性别
- 男
|
各位老师:你们好!我用的是MC68HC908JL3,外部时钟是8M。程序如下。我想PTB_PTB1得到2.4K的方波。可是实际只有623.5的方波。
#include /* for EnableInterrupts macro */
#include /* include peripheral declarations */
unsigned char counter1;
/********* Timer init procedure *********/
void InitTimer(void) {
TSC |= 0x70;
TSC |= 0x07; /* Prescaler 64 BUS Cycles, 8MHz - 1/8uS */
TMODH = 0x03; /* Modulo value set to create 100Us overflow - interrupt */
TMODL = 0x20;
TSC = 0x47;
}
/********* Timer interrupt Procedure ***********/
#pragma TRAP_PROC /* mark it as interrupt service routine */
void TimerInterrupt(void) {
/*PWM 2.4kHZ */
if (counter1 == 0) {
PTB_PTB1=0;
} else if (counter1 >= 1 && counter1 <= 1) {
PTB_PTB1=0;
} else if (counter1 >= 2 && counter1 <= 3) {
PTB_PTB1=1;
} else {
PTB_PTB1=0;
counter1=0;
}
counter1++;
TSC &= 0x7F; /*reset TOF flag */
}
void main(void) {
InitTimer();
EnableInterrupts; /* allow interrupts to occur */
for(;;) {
COPCTL = COPCTL;/*COP refresh */
__RESET_WATCHDOG();
}/* for ever */
} |
|