微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > MSP G430 2553单片机程序求解

MSP G430 2553单片机程序求解

时间:10-02 整理:3721RD 点击:
//******************************************************************************
//  MSP430G2xx3 Demo - Basic Clock, Output Buffered clocks with preloaded DCO
//                     calibration constants for BCSCTL1 and DCOCTL.
//  Description: Buffer ACLK on P1.0, default SMCLK(DCO) on P1.4 and MCLK/10 on
//  P1.1. DCO is software selectable to 1, 8, 12, or 16Mhz using calibration
//  contstants in INFOA.
//
//  ACLK = LFXT1 = 32768, MCLK = SMCLK = Selectable at 1, 8, 12 or 16Mhz
//  //* External watch crystal installed on XIN XOUT is required for ACLK *//       
//        //* By default, the MSP430 uses XT1 to source ACLK; P2.6/7 configured
//  //* automatically.
//               MSP430G2xx3
//             -----------------
//         /|\|         P2.6/XIN|-
//          | |                 | 32kHz
//          --|RST     P2.7/XOUT|-
//            |                 |
//            |       P1.4/SMCLK|-->SMCLK = Default DCO
//            |             P1.1|-->MCLK/10 = DCO/10
//            |        P1.0/ACLK|-->ACLK = 32kHz
//  D. Dang
//  Texas Instruments Inc.
//  December 2010
//   Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include  <msp430g2553.h>
void main(void)
{
  WDTCTL = WDTPW +WDTHOLD;                  // Stop Watchdog Timer
  if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                    
  {  
    while(1);                               // If calibration constants erased
                                            // do not load, trap CPU!
  }
//1Mhz
  BCSCTL1 = CALBC1_1MHZ;                    // Set range
  DCOCTL = CALDCO_1MHZ;                     // Set DCO step + modulation */
/* //8Mhz
  BCSCTL1 = CALBC1_8MHZ;                    // Set range
  DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */
/* //12Mhz
  BCSCTL1 = CALBC1_12MHZ;                   // Set range
  DCOCTL = CALDCO_12MHZ;                    // Set DCO step + modulation*/
/* //16Mhz
  BCSCTL1 = CALBC1_16MHZ;                   // Set range
  DCOCTL = CALDCO_16MHZ;                    // Set DCO step + modulation*/
  P1DIR |= 0x13;                            // P1.0,1 and P1.4 outputs
  P1SEL |= 0x11;                            // P1.0,4 ACLK, SMCLK output
  while(1)
  {
    P1OUT |= 0x02;                                // P1.1 = 1
    P1OUT &= ~0x02;                         // P1.1 = 0
  }
}
每句都不太了解,麻烦大神详细解释一下每一句

每一句?孩子,你还是学习C语言去吧

这个没必要解释,你会用就可以了,若你以后做项目每条语句都要弄懂的话那项目你就没法做了,具体你看看G2553的user guide

哈哈,我最不怕的就是麻烦,我来逐句翻译下。
//******************************************************************************
//  MSP430G2xx3 Demo - Basic Clock, Output Buffered clocks with preloaded DCO
//                     calibration constants for BCSCTL1 and DCOCTL.
//  Description: Buffer ACLK on P1.0, default SMCLK(DCO) on P1.4 and MCLK/10 on
//  P1.1. DCO is software selectable to 1, 8, 12, or 16Mhz using calibration
//  contstants in INFOA.
//
//  ACLK = LFXT1 = 32768, MCLK = SMCLK = Selectable at 1, 8, 12 or 16Mhz
//  //* External watch crystal installed on XIN XOUT is required for ACLK *//        
//        //* By default, the MSP430 uses XT1 to source ACLK; P2.6/7 configured
//  //* automatically.
//               MSP430G2xx3
//             -----------------
//         /|\|         P2.6/XIN|-
//          | |                 | 32kHz
//          --|RST     P2.7/XOUT|-
//            |                 |
//            |       P1.4/SMCLK|-->SMCLK = Default DCO
//            |             P1.1|-->MCLK/10 = DCO/10
//            |        P1.0/ACLK|-->ACLK = 32kHz
//  D. Dang
//  Texas Instruments Inc.
//  December 2010
//   Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include  <msp430g2553.h>
void main(void)
{
      WDTCTL = WDTPW +WDTHOLD;           // Stop Watchdog Timer      
  /*  关闭看门狗,要不然单片机上电几十毫秒之后看门狗就会把单片机复位,
  这样样程序就执行不下去了。
  */
                                                                 
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)   
/*
这里是读取时钟配置,TI公司在芯片出厂前,将精确的时钟配置的数据放在了一个特殊的Flsh空间里面,
用户可以直接读取这里面的数据来配置时钟,而不用自己手动计算。如果个区域不小心被用户擦除,     
也就是说这块区域里面都变成了0xff。那么就让程序陷入死循环。如下面的while(1);  
*/                     
  {  
    while(1);                            // If calibration constants erased
                                            // do not load, trap CPU!
  }
//1Mhz     
  BCSCTL1 = CALBC1_1MHZ;                    // Set range
  DCOCTL = CALDCO_1MHZ;                     // Set DCO step + modulation */
/*
CALBC1_1MHZ和CALDCO_1MHZ这两个宏就代表读取上面说的特殊区域。
并将数据赋值给时钟控制寄存器CALDCO_1MHZ和DCOCTL。
*/
/* //8Mhz
  BCSCTL1 = CALBC1_8MHZ;                    // Set range
  DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */
/* //12Mhz
  BCSCTL1 = CALBC1_12MHZ;                   // Set range
  DCOCTL = CALDCO_12MHZ;                    // Set DCO step + modulation*/
/* //16Mhz
  BCSCTL1 = CALBC1_16MHZ;                   // Set range
  DCOCTL = CALDCO_16MHZ;                    // Set DCO step + modulation*/
  P1DIR |= 0x13;   // P1.0,1 and P1.4 outputs   
/*
这里是将P1.0,P1.1和P1.4配置为输出方向,430单片机io口使用时一定要配置方向
(输入或者输出)。通过PxDIR的某一位来控制PX相应的位的方向,比如,P1DIR最低位为0,
那么P1.0为输入,P1DIR最低位为1, 那么P1.0为输出。
这里还可以这样写,  P1DIR |=BIT0+BIT1+BIT4;
*/

P1SEL |= 0x11;        // P1.0,4 ACLK, SMCLK output
/*
430每个IO口都不止一个功能,最基本的功能是数字IO,也就是输出0和1的能力。
其他功能包括,AD,PWM,串口,SPI,I2C,中断,等等。
我们可以通过将PXSEL某一位置1,来选择PX相应IO的第二功能,比如,
这里将P1.0, 做辅助时钟输出, P1.4做主时钟输出。
*/
  while(1)
  {
    P1OUT |= 0x02;         // P1.1 = 1
/*
   PxOUT为PX的输出控制器。通过P1OUT来控制PX相应位是输出低电平还是高电平。
*/
    P1OUT &= ~0x02;       // P1.1 = 0
  }
}





嗯嗯,很受用,真的灰常感谢啦~

都是高手啊                                    

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top