2021-10-06
Announcements
-
zy08
reading for Friday. -
Friday class time will be programming a state machine using that content on your MSP430 LaunchPad, so please bring yours to class.
Class time
What does this code do?
How do you find out?
https://dev.ti.com/tirex/explore/node?node=AGvymQa3ERQcC1c76Z5pKAIOGqZriLATEST&search=msp430fr6989
// example file
// msp430fr69xx_ta0_02.c
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1DIR |= BIT0;
P1OUT |= BIT0;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
TA0CCTL0 = CCIE; // TACCR0 interrupt enabled
TA0CCR0 = 50000;
TA0CTL = TASSEL__SMCLK | MC__UP; // SMCLK, UP mode
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
__no_operation(); // For debugger
}
// Timer0_A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
P1OUT ^= BIT0;
}
This is pretty much how the zyBook TimerISR()
is implemented!
volatile unsigned char TimerFlag = 0;
void TimerISR() {
TimerFlag = 1;
}
Figure 4.6.1
#include "RIMS.h"
volatile unsigned char TimerFlag=0; // ISR raises, main() lowers
void TimerISR() {
TimerFlag = 1;
}
enum BL_States { BL_SMStart, BL_LedOff, BL_LedOn } BL_State;
void TickFct_Blink() {
switch ( BL_State ) { //Transitions
case BL_SMStart:
BL_State = BL_LedOff; //Initial state
break;
case BL_LedOff:
BL_State = BL_LedOn;
break;
case BL_LedOn:
BL_State = BL_LedOff;
break;
default:
BL_State = BL_SMStart;
break;
}
switch (BL_State ) { //State actions
case BL_LedOff:
B0 = 0;
break;
case BL_LedOn:
B0 = 1;
break;
default:
break;
}
}
void main() {
B = 0; //Init outputs
TimerSet(2000);
TimerOn();
BL_State = BL_SMStart; // Indicates initial call to tick-fct
while (1) {
TickFct_Blink(); // Execute one synchSM tick
while (!TimerFlag){} // Wait for BL's period
TimerFlag = 0; // Lower flag
}
}