1669 views|0 replies

2015

Posts

0

Resources
The OP
 

Learn MSP430F5529 programming routine 1 [Copy link]

Use the multi-channel timing of Timer_A comparison mode to make the LED flash
.


MSP430 has two types of timers: Timer_A (3) & Timer_B (1).
Each timer is equipped with different capture compare registers: Timer0_A (5), Timer1_A (3), Timer2_A (3), Timer0_B (7).

The chip pin diagram of F5529 is shown below:
Insert picture description here
It can be seen that P1.1-P1.5 are the five capture compare registers of Timer0_A. TA0CCR0 is not used here because it has the highest priority and has a dedicated interrupt vector.

The maximum value stored in the counter is 0xFFFF, so we divide it into five segments. Due to the continuous mode, when the counter reaches the value of TA0CCR1, that is, 13107, the interrupt flag CCIFG is set, and the TAIFG interrupt flag is set at the same time. And so on, until it overflows.

The code is as follows 1

#include <msp430.h>
#include <msp430f5529.h>

/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= (BIT1+BIT2+BIT3+BIT4+BIT5+BIT6);
P1OUT = 0x00;
TA0CCTL1 = CCIE; //Capture compare register to enable CCIFG bit interrupt
TA0CCR1 = 13107; //Implant the value to be compared 0xffff/5=13107
TA0CCTL2 = CCIE;
TA0CCR2 = 26214;
TA0CCTL3 = CCIE;
TA0CCR3 = 39321;
TA0CCTL4 = CCIE;
TA0CCR4 = 52428;

TA0CTL |= TACLR + TAIE; //Enable interrupt and clear
TA0CTL |= TASSEL_1 + MC_2 + TAIE; //Select ACLK=32.768KHZ as clock, continuous mode, enable interrupt

__enable_interrupt();
while(1);

return 0;
}

#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer(void)
{
switch(__even_in_range(TA0IV,14))
/*The statements in the switch statement will only be executed when the value of TA0IV is an even number between 0 and 14.
This can improve the efficiency of the switch statement*/
{
case 2:
P1OUT=BIT6;
break;
case 4:
P1OUT=BIT2;
break;
case 6:
P1OUT=BIT3;
break;
case 8:
P1OUT=BIT4;
break;
case 14: //Timer overflows
P1OUT=BIT5;
break;
default:
break;
}
}

If you can't play a video, you can just post a picture of five small colored lights flashing in turn.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list