当前位置:文档之家› MSP430G2553_官方例程(加注释版)

MSP430G2553_官方例程(加注释版)

DCOCTL = CALDCO_1MHZ;// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;// Set LFXT1为vol时钟即12kHZ
P1DIR = BIT6;// P1.6 output (green LED),其余位为输入,也可以用P1DIR=0x40;
// Texas Instruments Inc.
// October 2005
// Built with IAR Embedded Workbench Version: 3.40A
//******************************************************************************
//BCSCTL1 = CALBC1_16MHZ;
//DCOCTL = CALBC1_16MHZ;
P1DIR |= 0x31; // P1.0,5 and P1.4 outputs
P1SEL |= 0x11; // P1.0,4 ACLK/VLO, SMCLK/DCO output
//SMCLK Sub-System Main Clk,ACLK和SMCLK可以通过复用引脚输出,MCLK不能直接输出体现, MCLK可以配置为VLO或者DCO
// P1.5.
// ACLK = LFXT1 = VLO, MCLK = SMCLK = default DCO
// //* External watch crystal installed on XIN XOUT is required for ACLK *//
//
// MSP430F20xx
// -----------------
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//Configure ADC10
ADC10CTL1 = INCH_10 + ADC10DIV_3; // Choose ADC Channel as Temp Sensor
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//Choose ADC Ref source
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
while(1)
{
P1OUT |= 0x20;// P1.5 = 1,通过开关P1.5来体现MCLK,这两条指令的周期大概为SMCLK的1/10
P1OUT &= ~0x20;//20;
}
}
5.
//******************************************************************************
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF)
{
while(1);// If calibration constants erased, trap CPU!!
}
// Configure Basic Clock
BCSCTL1 = CALBC1_1MHZ;// Set range
// MSP430G2xx2
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.0|-->LED
//
//******************************************************************************
// LaunchPad Lab5 - ADC10, Sample A10 Temp and Convert to oC and oF
//
// MSP430G2452
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A10 |
P1IFG &= ~BIT3; // P1.3 IFG cleared
P1IE |= BIT3; // P1.3 interrupБайду номын сангаас enabled
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
P1OUT = 0;// LED off
IFG1 &= ~OFIFG;// Clear OSCFault flag
BCSCTL2 |=SELM_1 + DIVM_0;// Set MCLK
for(;;)
{
P1OUT = BIT6;// P1.6 on (green LED)
_delay_cycles(100);
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from 0(SR)
#include <msp430x20x3.h>
unsigned char s;
void main(void)
{
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
//DCOCTL = 0;
LaunchPad
一切皆为2012TI杯电子设计大赛
1.
//******************************************************************************
// LaunchPad Lab2 - Software Toggle P1.0,
//
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;
__no_operation(); // SET BREAKPOINT HERE
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO = (121+1) x 2 x ACLK = 7995392Hz
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.4/SMCLK|-->SMCLK = Default DCO
// | P1.5|-->MCLK/10 = DCO/10
// | P1.0/ACLK|-->ACLK = VLO
//
// M. Buccini / L. Westlund
#include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//在MSP430的information A Flash段中一般会有一些比如DCO校正信息,温度传感器校正等等的数据存在,这些是出厂设置好的!但是有时候用户会不小心把infoA擦除掉,而擦除后的内容就为0xFF了。下面程序段的作用是,判断CALBC1_1MHZ的地址内容是否被擦除了,如果擦除了,那么while(1)。如果没有,那么将校正信息添入相应的寄存器,可以得到精度相对高的DCO输出频率
//
//******************************************************************************
#include "msp430g2553.h"
long temp;
long IntDegF;
long IntDegC;
void main(void)
// MSP430xG46x Demo - FLL+, Runs Internal DCO at 8MHz
//
// Description: This program demonstrates setting the internal DCO to run at
// 8MHz with auto-calibration by the FLL+.
#pragma vector=PORT1_VECTOR
相关主题