// M. Buccini / L. Westlund // Texas Instruments Inc. // October 2005
// Built with IAR Embedded Workbench Version: 3.40A
//******************************************************************************
#include
unsigned char s;
void main(void) {
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO //DCOCTL = 0;
//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
while(1) {
P1OUT |= 0x20; // P1.5 = 1, 通过开关P1.5来体现MCLK,这两条指令的周期大概为SMCLK的1/10
P1OUT &= ~0x20;//20; } }
5.
//*************************************************************************
*****
// 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+.
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = DCO = (121+1) x 2 x ACLK = 7995392Hz
// //* An external watch crystal between XIN & XOUT is required for ACLK *// //
// MSP430xG461x // ----------------- // /|\\| XIN|- // | | | 32kHz // --|RST XOUT|- // | |
// | P1.1|--> MCLK = 8MHz // | |
// | P1.5|--> ACLK = 32kHz // | | //
// K. Quiring/ M. Mitchell // Texas Instruments Inc. // October 2006
// Built with IAR Embedded Workbench Version: 3.41A
//*****************************************************************************
#include
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer FLL_CTL0 |= DCOPLUS + XCAP18PF; // DCO+ set, freq = xtal x D x N+1 SCFI0 |= FN_4; // x2 DCO freq, 8MHz nominal DCO SCFQCTL = 121; // (121+1) x 32768 x 2 = 7.99 MHz P1DIR = 0x22; // P1.1 & P1.5 to output direction P1SEL = 0x22; // P1.1 & P1.5 to output MCLK & ACLK
while(1); // Loop in place }
6.
//****************************************************************************
// MSP430xG46x Demo - Flash In-System Programming, Copy SegA to SegB //
// Description: This program first erases flash seg A, then it increments all // values in seg A, then it erases seg B, then copies seg A to seg B. // Assumed MCLK 550kHz - 900kHz.
// //* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *// //
// MSP430xG461x // ----------------- // /|\\| XIN|- // | | | // --|RST XOUT|- // | | //
// M. Mitchell
// Texas Instruments Inc. // Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include
char value; // 8-bit value to write to segment A
// Function prototypes void write_SegA (char value); void copy_A2B (void);
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
value = 0; // Initialize value
while(1) // Repeat forever {
write_SegA(value++); copy_A2B(); _NOP(); } }
void write_SegA (char value) {
char *Flash_ptr; unsigned int i;
Flash_ptr = (char *) 0x1080; FCTL1 = FWKEY + ERASE; FCTL3 = FWKEY; *Flash_ptr = 0;
FCTL1 = FWKEY + WRT;
for (i=0; i<128; i++) {
*Flash_ptr++ = value; }
FCTL1 = FWKEY; FCTL3 = FWKEY + LOCK; }
// Write segment A, increment value // Copy segment A to B // SET BREAKPOINT HERE // Flash pointer // Initialize Flash pointer // Set Erase bit // Clear Lock bit
// Dummy write to erase Flash segment // Set WRT bit for write operation // Write value to flash // Clear WRT bit // Set LOCK bit
void copy_A2B (void) {
char *Flash_ptrA; // Segment A pointer char *Flash_ptrB; // Segment B pointer unsigned int i;
Flash_ptrA = (char *) 0x1080; // Initialize Flash segment A pointer Flash_ptrB = (char *) 0x1000; // Initialize Flash segment B pointer FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrB = 0; // Dummy write to erase Flash segment B FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++) {
*Flash_ptrB++ = *Flash_ptrA++; // Copy value segment A to segment B }
FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit }
7.
//******************************************************************************
// MSP430xG46x Demo - Software Port Interrupt on P1.0 from LPM4 //
// Description: A hi/low transition on P1.0 will trigger P1_ISR which,
// toggles P2.1. Normal mode is LPM4 ~ 0.1uA. LPM4 current can be measured // with the LED removed, all unused P1.x/P2.x configured as output or inputs // pulled high or low, and ensure the P2.0 interrupt input does not float. // ACLK = 32.768kHz, MCLK = SMCLK = default DCO //