Question: -Use CCS -MSP432 microcontroller Write an assembly program to control the Red, Green, Blue LEDs on the evaluation board according to the statuses of the
-Use CCS
-MSP432 microcontroller
Write an assembly program to control the Red, Green, Blue LEDs on the evaluation board according to the statuses of the two switches S1 and S2.
Press only S1: RED
Press only S2: Green
Press both S1 and S2: Blue
Complete the following template to write the assembly program in Code Composer Studio. Fill in the blanks in the comments to answer the questions. Complete the missing directives, instructions, and operands accordingly. When done build the program and test it using the evaluation board.
Assembly Program Template:
Note: You must use the following program template and make it work. Failure to do so will result in a reduction of 10 points.
; Lab 6
; Setting the RGB LEDs color according to the status of the switches.
; Question 1 (Switches)
; Switch S1:
; From the evaluation board schematics determine: which I/O port and bit# ; is connected to S1, and is it connected as positive or negative logic?
; Switch S2:
; From the evaluation board schematics determine: which I/O port and bit# ; is connected to S2, and is it connected as positive or negative logic?
; (Hints: you need a pull-up resistor for negative logic input)
; Question 2 (LEDs)
; built-in red LED is connected to which I/O port and bit#?
; built-in green LED is connected to which I/O port and bit#?
; built-in blue LED is connected to which I/O port and bit#?
.thumb
.text
.align 2
; I/O mapping for I/O port x used for input
; (replace x with the correct number)
PxIN .field __________ ,32 ; Port x Input
PxOUT .field __________ ,32 ; Port x Output
PxDIR .field __________ ,32 ; Port x Direction
PxREN .field __________ ,32 ; Port x Resistor Enable
PxDS .field __________ ,32 ; Port x Drive Strength
PxSEL0 .field __________ ,32 ; Port x Select 0
PxSEL1 .field __________ ,32 ; Port x Select 1
; I/O mapping for I/O port y used for output
; (replace y with the correct number)
PyIN .field __________ ,32 ; Port y Input
PyOUT .field __________ ,32 ; Port y Output
PyDIR .field __________ ,32 ; Port y Direction
PyREN .field __________ ,32 ; Port y Resistor Enable
PyDS .field __________ ,32 ; Port y Drive Strength
PySEL0 .field __________ ,32 ; Port y Select 0
PySEL1 .field __________ ,32 ; Port y Select 1
; LED color constant
RED .equ ____ ; constant to turn Red ON
GREEN .equ ____ ; constant to turn Grn ON
BLUE .equ ____ ; constant to turn Blu ON
NONE .equ ____ ; constant to turn all OFF
; Switch status constant
SW1 .equ ____ ; input value S1 pressed
SW2 .equ ____ ; input value S2 pressed
SW12 .equ ____ ; value S1 and S2 pressed
NOSW .equ ____ ; S1 and S2 not pressed
.global main
.thumbfunc main
main: .asmfunc
BL Portx_Init BL Porty_Init
loop
BL Portx_Input ; scan S1 and S2
CMP R0, ____
BEQ sw1pressed ; switch 1 pressed
CMP R0, ____
BEQ sw2pressed ; switch 2 pressed
CMP R0, ____
BEQ bothpressed ; both switches pressed
CMP R0, ____
BEQ nonepressed ; neither switch pressed
BL Porty_Output ; Output LEDs color accordingly
B loop
sw1pressed
MOV R0, ____ ; which color should be ON?
BL Porty_Output
B loop
sw2pressed
MOV R0, ____ ; which color should be ON?
BL Porty_Output
B loop
bothpressed
MOV R0, ____ ; which color should be ON?
BL Porty_Output
B loop
nonepressed
MOV R0, ____ ; which color should be ON?
BL Porty_Output
B loop
.endasmfunc
;---------------------------------------------------------------
; Subroutine: Portx_Init (replace x with the correct port number)
; Description: Configure Px two bit# for negative logic
; input for S1 and S2 with weak internal pull-up resistors enabled.
; Input: none
; Output: none
; Modifies: R0, R1
;---------------------------------------------------------------
Portx_Init: .asmfunc
; configure Px.a and Px.b as GPIO
LDR R1, PxSEL0
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
LDR R1, PxSEL1
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; make P1.4 and P1.1 inputs
LDR R1, PxDIR
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; enable pull resistors on both input pins
LDR R1, PxREN
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; Configure resistors as pull-up
LDR R1, PxOUT
LDRB R0, [R1]
____ R0, ____
STRB
; finish R0, [R1]
BX LR
.endasmfunc
;---------------------------------------------------------------
; Subroutine: Portx_Input
; Description: Read and return the status of the switches.
; Input: none
; Output: R0 0x__ Switch 1 pressed
; R0 0x__ Switch 2 pressed
; R0 0x__ Both S1 and S2 pressed
; R0 0x__ No switches are pressed
; Modifies: R1
;---------------------------------------------------------------
Portx_Input: .asmfunc
LDR R1, PxIN
LDRB R0, [R1] ; read Port x
____ R0, ____
BX LR
.endasmfunc ; extract data for S1 and S2
;---------------------------------------------------------------
; Subroutine: Porty_Init, replace y with the correct port number)
; Initialize GPIO Port y red, green, and blue LEDs
; Input: none
; Output: none
; Modifies: R0, R1
;---------------------------------------------------------------
Porty_Init: .asmfunc
; configure Port y RGB LED outputs as PGIO
LDR R1, PySEL0
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
LDR R1, PySEL1
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; configure port y 3 output pins to have high-drive strength
LDR R1, PyDS
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; configure port y output pins as outputs
LDR R1, PyDIR
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
; turn off Red, Grn, and Blu LEDs
LDR R1, PyOUT
LDRB R0, [R1]
____ R0, ____
STRB R0, [R1]
BX LR
.endasmfunc
;---------------------------------------------------------------
; Subroutine: Porty_Output ; Set the output state of Py.
; Input: R0 new state of Py (only 8 least significant bits)
; Output: none
; Modifies: R1
;---------------------------------------------------------------
Porty_Output: .asmfunc
LDR R1, PyOUT
____ __, _____ ; output to control LEDs
BX LR
.endasmfunc
.end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
