Introduction to lighting the MSP430

Source: Internet
Author: User

/***************************************************
Program function: Control 8 LED flashing, control the flow of light and flow rate
---------------------------------------------------
***************************************************/
#include <msp430x14x.h>

/* Close all IO ports below */
#define CLOSE_IO p1dir = 0XFF; P1out = 0XFF; P2dir = 0XFF; P2out = 0XFF; P3dir = 0XFF; P3out = 0XFF; P4dir = 0XFF; P4out = 0XFF; P5dir = 0XFF;    P5out = 0XFF; P6dir = 0XFF; P6out = 0XFF;

typedef unsigned int uint;

UINT i = 0,j = 0,dir = 0;
UINT flag = 0,speed = 0; flag--light flow mode, speed--light flow speed

/**************** Main function ****************/
void Main (void)
{
void P_setting ();
Close_io;
P_setting ();
_eint (); Enable global interrupt
LPM0; CPU enters LPM0 mode
}
/* Package the settings */
void p_setting (void) {

Wdtctl = Wdtpw + wdthold; Turn off the watchdog
P6dir |= BIT2;    P6out |= BIT2; Turn off level translation
P5out &= ~bit7;
CCTL0 = CCIE; Enable CCR0 Interrupt
CCR0 = 50000;

Tactl = tassel_2 + id_3 + mc_1; Timer A's clock source select SMCLK, Count mode
P2dir = 0xFF; Set P2 port direction to output
P2out = 0xFF;

}

/*******************************************
Function Name: timer_a
Function: Timer A's interrupt service function, which passes the flag here
Control flow direction and flow speed of running water lamp
********************************************/

#pragma vector = Timera0_vector
__interrupt void timer_a (void)
{
if (flag = = 0)
{
P2out = ~ (0x80>> (i++)); Light-lit sequence D8-D1
}
else if (flag = = 1)
{
P2out = ~ (0x01<< (i++)); Light-lit sequence D1-D8
}
Else
{
if (dir)//light order D8, D1,D1, D8, round-robin
{
P2out = ~ (0x80>> (i++));
}
Else
{
P2out = ~ (0x01<< (i++));
}
}

if (i = = 8)
{
i = 0;
dir = ~dir;
}

j + +;
if (j = = 40)
{
i = 0;
j = 0;
flag++;
if (flag = = 4) flag = 0;
Switch (speed)
{
Case 0:
Tactl &=~ (ID0 + ID1); Increment count mode
Tactl |= id_3; 8 frequency
Break
Case 1:
Tactl &=~ (ID0 + ID1);
Tactl |= id_2; 4 frequency
Break
Case 2:
Tactl &=~ (ID0 + ID1);
Tactl |= id_1; 2 frequency
Break
Case 3:
Tactl &=~ (ID0 + ID1);
Tactl |= Id_0; 1 frequency
Break
Default
Break
}
if (flag! = 3) speed++;
if (speed = = 4) Speed = 0;
}
}

"Tested for f149 series"

Introduction to lighting the MSP430

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.