#include "msp430.h"
void Clock_Config(void)
{
PJSEL0 |= BIT4 | BIT5; //将PJ4,PJ5复用为LFXIN,LPXOUT
CSCTL0 = 0xA500; //ulock CS register
CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz
CSCTL2 = SELA__LFXTCLK | SELS__LFXTCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
CSCTL4 &= ~LFXTOFF;
do
{
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
CSCTL0_H = 0; //lock CS register
}
//我想使能
timerB0通道1的定时功能,但是一直进不去中断,通道0可以正常进入,只有在通道0和
//通道1都使能的情况下才能进入中断,很不解,为什么不能单独配置?
void TimerB0_Init(void)
{
TB0CCTL0 |= CCIE;//这两行注释掉进不了中断,都不注释可以进入中断
TB0CCR0 = 5000;
TB0CCTL1 |= CCIE;//这两行注释掉能进中断。
TB0CCR1 = 5000;
TB0CTL |= TBSSEL__ACLK | MC__UP;
}
void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
PM5CTL0 &= ~LOCKLPM5;
Clock_Config();
TimerB0_Init();
P6DIR |= BIT6;
while(1);
}
#pragma vector = TIMER0_B1_VECTOR
__interrupt void Timer0_B1_ISR(void)
{
switch(TB0IV)
{
case TB0IV_NONE: break; // No interrupt
case TB0IV_TB0CCR1: // TB0CCR1 interrupt
P6OUT ^= BIT6;
break;
case TB0IV_TB0CCR2: break; // TB0CCR2 interrupt
case TB0IV_TB0CCR3: break; // TB0CCR3 interrupt
case TB0IV_TB0CCR4: break; // TB0CCR4 interrupt
case TB0IV_TB0CCR5: break; // TB0CCR5 interrupt
case TB0IV_TB0CCR6: break; // TB0CCR6 interrupt
case TB0IV_TB0IFG: // overflow
break;
default: break;
}
}
#pragma vector = TIMER0_B0_VECTOR
__interrupt void Timer0_B0_ISR(void)
{
P6OUT ^= BIT6;
}
补充内容 (2018-11-1 08:58):
刚看了手册是不是只有通道0才能定时呀?
手册关于定时模式位MC的介绍:
Mode control. Setting MC = 00h when Timer_A is not in use conserves power.
00b = Stop mode: Timer is halted
01b = Up mode: Timer counts up to TAxCCR0
10b = Continuous mode: Timer counts up to 0FFFFh
11b = Up/down mode: Timer counts up to TAxCCR0 then down to 0000h
从介绍来看他里面寄存器 用的是TAXCCR0,而不是TAXCCRX是不是说明只有通道0才具有定时功能呢,其他通道只有在捕获,比较输出模式才需要用到呢。
一周热门 更多>