This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430g2553红外遥控程序

Other Parts Discussed in Thread: MSP430G2553, MSP430F149

用g2553单片机控制红外接收发送程序使用不了,怎么样修改;

 

#include <msp430g2553.h>
#define Ir_Pin  (P1IN & 0X02)                        //定义红外接收头端口

unsigned char Ir_Buf[4];                             // 用于保存解码结果

unsigned int Ir_Get_Low();
unsigned int Ir_Get_High();
 
void main(void)
{
     unsigned int temp,delay;
     char i,j;

     WDTCTL = WDTPW + WDTHOLD;                       // 关闭看门狗
     BCSCTL1 &= ~XT2OFF;                             // XT2on
     BCSCTL2 |= SELM1 + SELS;                        // MCLK为8M
     for(delay=5000;delay>0;delay--);
     IFG1 &=~OFIFG;

     CCR0=0XFFFF;
     P1DIR =0X40;//P1.6输出
     P1OUT=0XFF;// 输入设置

 

     while(1)
     {
     restart:
             while(Ir_Pin);                          //等待红外信号
             temp=Ir_Get_Low();
             if(temp<8500 || temp>9500) continue;    //引导脉冲低电平9000
             temp=Ir_Get_High();
             if(temp<4000 || temp>5000) continue;    //引导脉冲高电平4500
             for(i=0;i<4;i++)                        //4个字节
             for(j=0;j<8;j++)                        //每个字节8位
             {
                  temp=Ir_Get_Low();
                  if(temp<200 || temp>800) goto restart;
                  temp=Ir_Get_High();
                  if(temp<200 || temp>2000) goto restart;
                  Ir_Buf[i]>>=1;
                  if(temp>1120) Ir_Buf[i]|=0x80;
             }
      if(Ir_Buf[2]==0X0C)P1OUT =0X00;        //如果按的是0按键则点亮LED
      else if(Ir_Buf[2]==0X16)P1OUT =0X40;   //如果按的是CH-按键则关闭LED
      }
}

/******************************************************************************
函数名称:Ir_Get_Low
功    能:计算低电平持续的时间
参    数:无

返回值  :TAR
******************************************************************************/
unsigned int Ir_Get_Low()
{
      TAR=0X0000;
      TACTL=TASSEL_2 + TACLR + ID0 +ID1 + MC_1;

      while(!Ir_Pin  && (TAR&0x8000)==0);    //等待高电平到来
      TACTL=0X00;
      return TAR;
}

/******************************************************************************
函数名称:Ir_Get_High
功    能:计算高电平持续的时间
参    数:无

返回值  :TAR
******************************************************************************/
unsigned int Ir_Get_High()
{
      TAR=0X0000;
      TACTL=TASSEL_2 + TACLR + ID0 +ID1 + MC_1;

      while(Ir_Pin && (TAR&0x8000)==0);
      TACTL=0X00;
      return TAR;
}

怎么样才能是这段程序在G2553中成功的运行,谢谢!