-
大小: 23KB文件類型: .zip金幣: 2下載: 0 次發布日期: 2021-06-04
- 語言: 其他
- 標簽: msp430g2553??測頻??
資源簡介
msp430g2553測頻的程序,對初學者有一定的幫助,適合剛剛接觸的同學

代碼片段和文件信息
/*
?*?實驗不是很成功,捕獲仍有問題,理論是正確的,但仍存在誤觸發,有時一個下降沿觸發多次,有時會漏過一個沿
?*?如果只是單純捕獲周期還行
?*?main.c
?*/
#include?“msp430g2553.h“
#define?CPUCLK?1000000
float??FreqDuty;
unsigned?int?intcnt=0capcnt=0;
unsigned?int?Cap_Result[3]Buff1Buff2;
unsigned?char?keypress?=?0;
void?BasicClock_Init(void)
{
//設置時鐘源
if(CALBC1_1MHZ?==?0xFF?||?CALDCO_1MHZ?==?0xFF)
{
while(1);
}
BCSCTL1??=?CALBC1_1MHZ;??//DCO?---1MHz
DCOCTL???=?CALDCO_1MHZ;
BCSCTL3?|=?LFXT1S_0;?????//LFXT1?---32768Hz
IFG1????&=?~OFIFG;???????//?Clear?OSCFault?flag
//設置時鐘,ACLK=32768,MCLK=1M
BCSCTL2?|=?SELM_0?+?DIVM_0;
}
void?GPIO_Init(void)
{
//configure?LED
P1DIR?|=?BIT0?+?BIT6;
P1OUT?|=?BIT0?+?BIT6;
//configure?Timer1?CCI2A?Pin?TA1.2--P2.4功能選擇010?Datasheet?Page51
P2DIR??&=~BIT4;
P2SEL??|=?BIT4;
P2SEL2?&=~BIT4;
}
void?Timer_Init(void)
{
//1MHz連續計數模式,捕獲間隔為1us--65.535ms即輸入頻率在15.3Hz~1MHz之間
TA1CTL?=?TASSEL_2?+?MC_2?+?TACLR;;
//采用TA1.2引腳做捕獲輸入上升、下降都捕獲,捕獲模式、開CCI中斷
TA1CCTL2?=?CM_3+CCIS_0+CAP+CCIE;
}
void?main(void)
{
WDTCTL?=?WDTPW?+?WDTHOLD;
BasicClock_Init();
GPIO_Init();
Timer_Init();
_bis_SR_register(GIE);
while(1);
}
#pragma?vector?=?TIMER1_A1_VECTOR
__interrupt?void?Timer1_A1_ISR(void)
{
switch(__even_in_range(TA1IV10))
{
case?2:? //?TA0CCR1?CCIFG
P1OUT?^=BIT0+BIT6;
break;
case?4:?? //?TA0CCR2?CCIFG
Cap_Result[capcnt?++]?=?TA1CCR2;
if(capcnt?==?3)
{
capcnt?=?0;
Buff1?=?(Cap_Result[2]-Cap_Result[0]?>?0)?(Cap_Result[2]-Cap_Result[0]):(65535-Cap_Result[0]+Cap_Result[2]);
Freq?=1000000?*1.0?/Buff1;
if(TA1CCTL2?&?CCI?==?1)
Buff2?=?(Cap_Result[1]-Cap_Result[0]?>?0)?(Cap_Result[1]-Cap_Result[0]):(65535-Cap_Result[0]+Cap_Result[1]);
else
Buff2?=?(Cap_Result[2]-Cap_Result[1]?>?0)?(Cap_Result[2]-Cap_Result[1]):(65535-Cap_Result[1]+Cap_Result[2]);
Duty?=?Buff2*1.0/Buff1;
if(Freq?10000)
P1OUT?&=?~BIT0;
else
P1OUT?|=?BIT0;
if(Duty?0.5)
P1OUT?&=~BIT6;
else
P1OUT?|=?BIT6;
}
break;
case?10: //?TA0IFG
P1OUT?^=BIT0;
break;
default:
break;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-07-14?09:05??TimerA_Capture\
?????文件?????????490??2012-09-24?13:39??TimerA_Capture\.ccsproject
?????文件???????17857??2012-09-24?13:39??TimerA_Capture\.cproject
?????文件????????2579??2012-09-24?13:39??TimerA_Capture\.project
?????目錄???????????0??2013-07-14?09:05??TimerA_Capture\.settings\
?????文件??????????93??2012-09-24?13:39??TimerA_Capture\.settings\org.eclipse.cdt.codan.core.prefs
?????文件?????????154??2012-09-24?13:39??TimerA_Capture\.settings\org.eclipse.cdt.debug.core.prefs
?????文件?????????239??2012-09-25?00:01??TimerA_Capture\.settings\org.eclipse.core.resources.prefs
?????目錄???????????0??2013-07-14?09:05??TimerA_Capture\Debug\
?????文件???????11147??2013-04-02?15:03??TimerA_Capture\Debug\TimerA_Capture.map
?????文件???????18331??2013-04-02?15:03??TimerA_Capture\Debug\TimerA_Capture.out
?????文件??????????49??2013-04-12?15:47??TimerA_Capture\Debug\ccsObjs.opt
?????文件??????????12??2013-04-12?15:47??TimerA_Capture\Debug\ccsSrcs.opt
?????文件????????7962??2013-04-02?15:03??TimerA_Capture\Debug\main.obj
?????文件?????????311??2013-04-02?15:03??TimerA_Capture\Debug\main.pp
?????文件????????3297??2013-04-12?15:47??TimerA_Capture\Debug\makefile
?????文件?????????268??2013-04-12?15:47??TimerA_Capture\Debug\ob
?????文件????????1811??2013-04-12?15:47??TimerA_Capture\Debug\sources.mk
?????文件?????????832??2013-04-12?15:47??TimerA_Capture\Debug\subdir_rules.mk
?????文件?????????513??2013-04-12?15:47??TimerA_Capture\Debug\subdir_vars.mk
?????文件?????????822??2012-09-24?13:39??TimerA_Capture\MSP430G2553.ccxm
?????文件????????4912??2012-09-24?13:39??TimerA_Capture\lnk_msp430g2553.cmd
?????文件????????2172??2012-09-25?09:45??TimerA_Capture\main.c
- 上一篇:msp430g2553測頻率
- 下一篇:微票-微信小程序源碼
評論
共有 條評論