?? 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 + -