📄 main.c
字号:
#include "msp430x22x4.h"
unsigned int user_code0,user_code1,operate_code;
unsigned char bitcnt;
unsigned char first = 1;
unsigned int last,temp;
void main( void )
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1=CALBC1_1MHZ; //设定DCO 为1MHZ
DCOCTL=CALDCO_1MHZ;
P1SEL|=0x02;//P1.1选择第二功能下降沿捕获发生中断
//P2DIR|=0x01;//方向寄存器选择输出
//P2OUT|=0x01;//输出高电平,蜂鸣器不叫
TACTL=0x0220;//选择时钟源为系统时钟,不分频,为连续计数模式,溢出中断禁止
TACCTL0=0x8918;//下降沿捕获,选择CCI0A做为输入源,同步捕获,允许捕获模块中断,为捕获模式
_EINT();
while(1)
{
if(bitcnt==42){bitcnt=0;}
}
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if(first ==1)
{
TACTL=0x0224;//定时器清零
P2OUT&=0xfe;
last=TACCR0;
last=0;
first=0;
}
else if(first==0)
{
TACTL=0x0224;//定时器清零
temp=TACCR0-last;
if(temp>1024&&temp<1225){ temp=0;} // 判断数据0信号
else if(temp>2145&&temp<2345){ temp=0x8000;} // 判断数据1信号
else if(temp>13400&&temp<14600) // 判断引导码信号
{ bitcnt=0;user_code0=0;user_code1=0;
operate_code=0; return;} // 返回,等待下次开始接收
else { first=1;return; } // 干扰信号
bitcnt++;
if(bitcnt<13){user_code0|=temp; user_code0>>=1;} //开始接收前13位用户识别码
else if(bitcnt==13){ user_code0|=temp;}
else if(bitcnt<26){user_code1|=temp;user_code1>>=1;} //开始接收后13位用户识别码
else if(bitcnt==26){user_code1|=temp;}
else if(bitcnt<42){operate_code|=temp;operate_code>>=1;} //开始接收16位(8位操作码和8位操作反码)
else if(bitcnt==42){operate_code|=temp;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -