Solve the following problems using the MSP430 IAR Compiler/Assembler . Setup the
ID: 3875376 • Letter: S
Question
Solve the following problems using the MSP430 IAR Compiler/Assembler.
Setup the MSP430 LaunchPad to use Timer A to toggle the red LED each time the timer counts to 50,000. You should be able to do this using:
A- An assembly language program that calls a subroutine to configure Timer to toggle the LED every 50,000 cycles.
B- An assembly language program that sets up an interrupt from Timer A every 50,000 cycles.
C- Repeat the above part B but this time develop a mixed language program that calls the assembly language subroutines from the C language.
Additional requirements:
- For the above problems that combine C and assembly, the input data should be declared in the C portion of the program.
- For the above problems that only use assembly language, the input data should be stored in RAM.
- Code needed to test each problem should be included.
Explanation / Answer
// MSP430G2xx
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | P1.6|-->LED
// | P1.0|-->LED
//
// Aldo Briano
// Texas Instruments, Inc
// June 2010
// Built with Code Composer Studio v4
//***************************************************************************************
#include <msp430g2231.h>
#define LED_0 BIT0
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
unsigned int timerCount = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
LED_DIR |= (LED_0 + LED_1); // Set P1.0 and P1.6 to output direction
LED_OUT &= ~(LED_0 + LED_1); // Set the LEDs off
CCTL0 = CCIE;
TACTL = TASSEL_2 + MC_2; // Set the timer A to SMCLCK, Continuous
// Clear the timer and enable timer interrupt
__enable_interrupt();
__bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
timerCount = (timerCount + 1) % 8;
if(timerCount ==0)
P1OUT ^= (LED_0 + LED_1);
}.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.