Question: Mode 0 Red LED blinks every 1 / 2 a second ( using execution loop ) Mode 1 Red LED blinks every 1 / 2

Mode 0
Red LED blinks every 1/2 a second (using execution loop)
Mode 1
Red LED blinks every 1/2 second (using execution loop)
Green LED blinks every 1/3 second (using timer & interrupt)
Mode 2
Red LED turns off
Green LED blinks every 1/3 second (using timer & interrupt)
Blue LED blinks every 1/4 second (using timer & signal)
Mode 3
Red LED stays off
Green LED turns off
Blue LED blinks slower, every 1/2 second (using timer & signal)
Objective
For this assignment, you should attempt to recreate the RGB LED activity listed above with the method inside parenthesis. Pressing the button on the Blacktop should advance to the next mode (advancing from 3 should go back to 0) and pressing the side button on the Launchpad should step back to the previous mode (moving backward from 0 should set the mode to 3).
Because you are using the buttons as interrupts, the completed program will have some initialization, execution loop and three interrupts: one for TIMER1_A0_VECTOR, one for PORT1_VECTOR and one for PORT2_VECTOR.
Tips
Do not recommend setting hardware parameters in the execution loop based on what mode you are in (for instance, checking to see what mode you are in every loop iteration and enabling interrupts for the timer if in Mode 1 or 2, otherwise disabling interrupts if in Mode 0 or 3).
This is a waste of time. You should set hardware parameters when changing modes.
```
#include
#define PC r0
4#define SP r1
5#define SR r2
##define CG r3
7
8;-----------------------------------------------------------------------------
9 ; PROGRAM DATA (READ-ONLY)
.section .rodata ; this should be placed in ROM
;-----------------------------------------------------------------------------
DISP: .byte 0b00111111 ; pattern for 0
.byte 0b00000110 ; pattern for 1
.byte 0b01011011 ; pattern for 2
.byte 0b01001111 ; pattern for 3
```
```
; PROGRAM DATA (READ AND WRITE)
.section .data ; this should be placed in RAM
```
```
; PROGRAM INSTRUCTIONS
.text ; this section is for instructions
.global MAIN
; disable watchdog and run at 1Mhz
mov #WDTPW|WDTHOLD, &WDTCTL
mov.b &CALBC1_1MHZ, &BCSCTL1
mov.b &CALDCO_1MHZ, &DCOCTL
; initialize stack pointer
mov #0x400, SP
; use P2.6 and P2.7 normally
bic.b #BIT6|BIT7, &P2SEL
bic.b #BIT6|BIT7, &P2SEL2
; initialize other things
; TODO: set up display
bis.b #-1, &P2DIR
bic.b #-1, &P2OUT
bis.b #BIT0, &P3DIR
bic.b #BIT0, &P3OUT
``````
Files ; TODO: set up P1.3 button
bic.b #BIT3, &P1DIR
bis.b #BIT3, &P1IE
bis.b #BIT3, &P1IES
bic.b #BIT3, &P1IFG
; TODO: set up P2.7 button
bic.b #BIT7, &P2DIR
bis.b #BIT7, &P2IE
bis.b #BIT7, &P2IES
bic.b #BIT7, &P2IFG
; TODO: green light
bic.b #BIT0, &P1DIR
bic.b #BIT0, &P10UT
; TODO: red light
bis.b #BIT6, &P3DIR
bic.b #BIT6, &P30UT
; TODO: blue light
bis.b #BIT5, &P3DIR
bic.b #BIT5, &P30UT
; put zero on display
mov #DISP, r15
add #0, r15
mov.b @r15, &P20UT
; TODO: initialize timer1 ;USED FOR THE GREEN LIGHT
mov #41667, &TA1CCR0
mov #CCEI, &TA1CCTLO
mov TASSEL_2|ID_3|MC_0, & TA1CTL
mov TASSEL_2|ID_3|MC_1, &TA1CTL
; TODO: initialize timer0 ; USED FOR THE BLUE LIGHT
mov #31250, &TA0CCR0
mov #OUTMOD_4, &TA0CCTL1
mov #TASSEL_2|ID_3|MC_1, &TA0CTL
; we'll definitely need interrupts enabled
eint
``````
.Lloop:
; execute forever
; TODO: blink red light
xor.b #BIT6, &P30UT
mov #500, R15
call #delay_ms
jmp .Lloop
```
```
; DELAY_MS FUNCTION
99 ;---------------------------------------------------------------------------
100 delay_ms:
101102 mov
r15, r14
#245, r15
r15
r15
2b
r14
1b
113 BUTTON1:
114 ; TODO: go back to previous mode
``````
BUTTON2:
; TODO: go forward to next mode
; debounce routine
and.b #BIT7, &P2IN
jz 1b
push r15
push r14
mov #32, r15
call #delay_ms
pop r14
pop r15
bic.b #BIT7, &P2IFG
reti
TIMER:
; TODO: what should timer do?
reti
UNEXPECTED_ISR:
reti
```
```
; INTERRUPT VECTOR TABLE
.section ".vectors", "ax", @progbits
.word UNEXPECTED_ISR ;0xffe0
.word UNEXPECTED_ISR ;0xffe2
.word BUTTON1- ;0xffe4(PORT1_VECTOR)
.wOrd BUTTON2 ;0xffe6(PORT2_VECTOR)
.word UNEXPECTED_ISR ;0xffe8
.word UNEXPECTED_ISR ;0xffea (ADC10_VECTOR)
.word UNEXPECTED_ISR ;0xffec (USCIABOTX_VECTOR)
.word UNEXPECTED_ISR ;0xffee (USCIAB0RX_VECTOR)
.word UNEXPECTED_ISR ;0xfff0(TIMER0_A1_VECTOR)
.word UNEXPECTED_ISR ;0xfff2(TIMER0_A0_VECTOR)
.word UNEXPECTED_ISR ;0xfff4(WDT_VECTO-R)
.word UNEXPECTED_ISR ;0xfff6(COMP-ARATORA_VECTOR)
.word UNEXPECTED_ISR ;0xfff8(TIMER1_A1_VECCTOR)
.word TIMER - ;0xfffa (TIMER1_A0_VECTOR)
.word UNEXPECTED_ISR ;0xfffc (NMI_VECTOR)
.word MAIN _ ;0xfffe (RESET_VECTOR)
.end
```
Mode 0 Red LED blinks every 1 / 2 a second (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!