Questions for you to answer
-
related to the code below.
Paste the file into a new CCS project.
Then change your Project build settings:
-
Project -> Show Build Settings
-
Build -> MSP430 Compiler -> Advanced Options -> Assembler Options
-
Check both:
-
Keep the generated …
-
Generate listing file
-
and Build the project!
Look at the generated assembly code:
-
Debug ->
main.asm
/*
modified from original:
msp430fr69xx_p1_03.c
*/
//******************************************************************************
// MSP430FR69xx Demo - Software Port Interrupt Service on P1.1 from LPM4
//
// Description: A Hi/Lo transition on P1.1 will trigger P1ISR the first time.
// On hitting the P1ISR, device exits LPM4 mode and executes section of code in
// main() which includes toggling an LED and the P1.1 IES bit which switches
// between Lo/Hi and Hi/Lo trigger transitions to alternatively enter the P1ISR.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
//
// MSP430FR6989
// -----------------
// /|\| |
// | | |
// --|RST |
// /|\ | |
// --o--|P1.1 P1.0|-->LED
// \|/
//
// William Goh
// Texas Instruments Inc.
// April 2014
// Built with IAR Embedded Workbench V5.60 & Code Composer Studio V6.0
//******************************************************************************
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
/* Question A:
This example is not great for demonstrating "best practices",
it is really just the shortest path to getting things set up.
What is a better way to handle the part of main() that configures
the peripherals?
*/
// Configure GPIO
P1OUT = BIT1; // Pull-up resistor on P1.1
P1REN = BIT1; // Select pull-up mode for P1.1
P1DIR = 0xFF ^ BIT1; // Set all but P1.1 to output direction
P1IES = BIT1; // P1.1 Hi/Lo edge
P1IFG = 0; // Clear all P1 interrupt flags
P1IE = BIT1; // P1.1 interrupt enabled
P2OUT = 0;
P2DIR = 0xFF;
P3OUT = 0;
P3DIR = 0xFF;
P4OUT = 0;
P4DIR = 0xFF;
PJOUT = 0;
PJDIR = 0xFFFF;
/* Question B
* What is the purpose of the following line again?
* Write in your own words what this does and why it's needed.
*/
PM5CTL0 &= ~LOCKLPM5;
while(1)
{
/* Question C
* The following line does two things. What are they and
* what is the net effect in your own words?
* (look up SR status register and the #defines)
*/
__bis_SR_register(LPM4_bits | GIE); // Enter LPM4 w/interrupt
__no_operation(); // For debugger
/* Question D
* Describe what effect the following line has in the system.
* Convert to a function call: what is the function name?
*/
P1OUT ^= BIT0;
/* Question E
* After the above line executes, what is the next CPU instruction?
*/
}
}
/* Question F
* Change the name of this function to be a little bit more
* descriptive of its purpose.
*/
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
//P1IES ^= BIT1; // Toggle interrupt edge
P1IFG &= ~BIT1; // Clear P1.1 IFG
__bic_SR_register_on_exit(LPM4_bits); // Exit LPM4
}