#include <msp430.h>
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
int cnt;
volatile int iflag=0;
void ir_open(){
iflag=0;
P2DIR |= BIT3;//P2.2, P2.3输出
P2SEL &= ~BIT3; //P2.2:IO P2.3:TA0
P2OUT &= ~BIT3;
//38K->P2.3
TBCCR0=15;
/*TBCCR0 = (int)(26.3*8 + 0.5);`
TBCCTL0 = OUTMOD_6;
TBCCR1 = (int)(13.15*8 + 0.5);
*/
TBCTL = TASSEL_2+MC_1+TACLR;
TBCCTL0=CCIE;
}
void ir_start(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
TBCTL =MC_1;
P2OUT &= ~BIT3;
iflag=0;
delay_us(4500);
TBCTL =MC_0;
}
void ir_next(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
P2OUT &= ~BIT3;
iflag=0;
delay_us(2250);
}
void ir_send_byte(unsigned char c){
unsigned char i;
for(i = 0; i != 8; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_end(){
P2OUT |= BIT3;
iflag=1;
delay_us(300);
P2OUT &= ~BIT3;
iflag=0;
}
void ir_put(unsigned char c){
ir_start();
ir_send_byte(0x00);
ir_send_byte(0x90);
ir_send_byte(0x04);
ir_send_byte(0x0A);
ir_end();
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |=BIT0 ; // P1.0 output
while(1)
{
//yanshi 1s
/* cnt = 1000;
TA0CCTL0 = ~CCIE;
while(cnt!= 0);
P1OUT ^= BIT0;
TA1CTL = MC_0; //mc_0=stop*/
P1OUT ^= BIT0;
ir_open();
__bis_SR_register(GIE);
ir_put(0x83);
}
}
//#pragma vector = TIMERB_A0_VECTOR
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR()
{
if(iflag==1);
P2OUT ^= BIT3;
}
请问问这程序有什么问题,38KHZ,我的定时器计时应该是13.8usIO电平翻转一次,但是
定时15之后进了中断之后就出不了,css不熟也不知道应该怎么调试,求大牛指点
|