# MSP430G2553 switch to light up the LED
This is my first blog post. If there is any irregularity, I hope you can point it out. Recently I started learning MSP430G2553, and I will share with you the problems encountered in learning and learning results. What I shared with you today is a section that turns on the LEDs on the two boards by pressing the button P1.3 to switch cyclically.
#include <msp430.h>
/*
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |=BIT6; //LED2——P1.6设为输出
P1OUT &=~BIT6; //初始化P1.6为低电平,LED2灭
P1DIR |=BIT0; //LED1——P1.0设为输出
P1OUT |=BIT0; //初始化P1.0为低电平,LED1亮
P1DIR &=~BIT3; //按键——P1.3设为输入
P1REN |=BIT3; //Enable internal pull-up resistor
P1OUT |=BIT3; //Set pull-up resistor for P1.3
while(1)
{
if((P1IN&BIT3)==0)
{
DCOCTL = CALDCO_16MHZ; //设置MCLK频率为16MHZ
BCSCTL1 = CALBC1_16MHZ;
P1OUT ^=BIT6;
P1OUT ^=BIT0;
__delay_cycles(8000000); //延时 8M*(1/16M)秒
}
}
}
The following video is the corresponding key control and phenomenon.
LED switch on