TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430G2001: 时钟怎么配置呀 想配置一个8MHz的时钟

Part Number:MSP430G2001

#include "stdio.h"
#include <string.h>
#include <io430g2001.h>
#include "stdlib.h"
#include "io430.h"
unsigned int Timer_Counter;
void IoInit(void);
void TimerA_Init(void);

int main( void )
{
unsigned int i,j;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
IoInit();
// SystemInit();
TimerA_Init();
__enable_interrupt(); while(1){
i++;
}
}

/*******************************************
// 函数名称: IoInit
// 实现功能: Io初始化
// 参 数: No
// 返回值 : No
********************************************/
void IoInit(){ P1DIR=0x08;P1OUT=0x00; //P1.3=0时录像
P2DIR=0x80;P2OUT=0x00; //P2.7输出低脉冲时存储录像
}
/*******************************************
// 函数名称: TimerA_Init
// 实现功能: Timer0初始化,?ms产生1次中断
// 参 数: No
// 返回值 : No
********************************************/
void TimerA_Init(){ TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 =39063-1; //25e6/(8*80)=39062.5; 100ms中断一次,分频前为640Hz
TA0CTL = TASSEL_2 + ID_3 + MC_1 + TACLR; //SCLK,up mode, ID_3是8分频,clear TAR
// TA0EX0 = TAIDEX_7; //再8分频
}

/*******************************************
// 函数名称:Timer_A
// 功 能:Timer0中断服务程序,每ms中断一次
// 参 数:No
// 返回值 :No
********************************************/
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void){ Timer_Counter++; //100ms中断一次
if(Timer_Counter%100 ==0){
P1OUT = P1OUT^BIT3;
}
}

这是参考的程序 刚刚学习还不太懂 求大佬指点  最好帮我补全程序

Susan Yang:

您可以使用内部的DCO来作为时钟源,具体可以参考

https://www.ti2k.com/wp-content/uploads/ti2k/DeyiSupport_MSP430_node

if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)                                    

 {  

   while(1);                               // If calibration constants erased

                                           // do not load, trap CPU!!

 }

//8Mhz

 BCSCTL1 = CALBC1_8MHZ;                    // Set range

 DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */

赞(0)
未经允许不得转载:TI中文支持网 » MSP430G2001: 时钟怎么配置呀 想配置一个8MHz的时钟
分享到: 更多 (0)