This document contains the source code for a uVision project that initializes GPIO port F on an LM4F120 microcontroller. It includes initialization code to configure port F pins for input switches and output LEDs. The main loop continuously reads the switch inputs and sets the LED outputs accordingly to indicate whether a door is locked or unlocked based on the switch states.
13. eece237lab2/main2.s
;****************** main.s ***************
; Program written by: ***Your Name Here***
; Date Created: 1/30/2015
; EECE237 Fall Semester 2016
; Lab number: 2
; The overall objective of this system is a simple user interface
; Hardware connections
; PF0 is switch input (1 means switch is not pressed, 0 means
switch is pressed)
; PF44 is switch input (1 means switch is not pressed, 0 means
switch is pressed)
; PF1, 2, 3 are LED output (0 means door is locked, 1 means
door is unlocked)
; The specific operation of this system is to unlock if both
switches are pressed
; Useful declarations
THUMB
14. ; PortF register declarations
GPIO_PORTF_DATA_R EQU 0x400253FC
GPIO_PORTF_DIR_R EQU 0x40025400
GPIO_PORTF_AFSEL_R EQU 0x40025420
GPIO_PORTF_PUR_R EQU 0x40025510
GPIO_PORTF_DEN_R EQU 0x4002551C
GPIO_PORTF_LOCK_R EQU 0x40025520
GPIO_PORTF_CR_R EQU 0x40025524
GPIO_PORTF_AMSEL_R EQU 0x40025528
GPIO_PORTF_PCTL_R EQU 0x4002552C
GPIO_LOCK_KEY EQU 0x4C4F434B ; Unlocks the
GPIO_CR register
SYSCTL_RCGC2_R EQU 0x400FE108
SYSCTL_RCGC2_GPIOF EQU 0x00000020 ; port F Clock
Gating Control
AREA DATA, ALIGN=2
; Global variables go here, you will not need any in
lab2.
15. ALIGN ; make sure the end of this section is aligned
AREA |.text|, CODE, READONLY, ALIGN=2
EXPORT Start
Start
; Write initialization code here. This segment is only executed
once at reset
;------------PortF_Init------------
; Initialize GPIO Port F for negative logic switches on PF0 and
; PF4 to match Launchpad wiring. Weak internal pull-up
; resistors are enabled, and the NMI functionality on PF0 is
; disabled. R,G, and B LED's Pins (PF1-PF3) set as outputs.
; Follows Valvano Text program 4.1.
; Input: none
; Output: none
; Modifies: R0, R1, R2
PortF_Init
16. LDR R1, =SYSCTL_RCGC2_R ; 1) activate clock for
Port F
LDR R0, [R1]
ORR R0, R0, #0x20 ; set bit 5 to turn on clock
STR R0, [R1]
NOP
NOP ; allow time for clock to finish
; 2) unlock the
lock register
; unlock GPIO
Port F Commit Register
; enable commit
for Port F
; 1 means allow
access
; 3) disable
analog functionality
; 0 means analog
is off
; 4) configure as
GPIO
; 0 means
configure Port F as GPIO
17. ; 5) set direction
register
; PF0 and PF7-4
input, PF3-1 output
; 6) regular port
function
; 0 means disable
alternate function
; pull-up resistors
for PF4,PF0
; enable weak
pull-up on PF0 and PF4
; 7) enable Port F
digital port
; 1 means enable
digital I/O
mainloop
; Write your main program here. This segment
loops indefinitely while the microcontroller is on
18. ; You must use the Portf_Input and Portf_Output
functions to access PortF
B mainloop ;infinite main loop
; Useful Functions
; (From Valvano Text Program 4.1)
;------------PortF_Input------
; Read ProtF
; Input: none
; Output: R0 value read from PortF
; Modifies: R1
PortF_Input
LDR R1, =GPIO_PORTF_DATA_R ; pointer to Port F
data
LDR R0, [R1] ; read all of PortF
AND R0,R0,#0x11 ; just the input
pins, bits 4,0
BX LR ; return R0 with inputs
19. ;------------PortF_Output------
; Set the output state of PF3-1.
; Input: R0 new state of PF
; Output: none
; Modifies: R1
PortF_Output
LDR R1, =GPIO_PORTF_DATA_R ; pointer to Port F
data
STR R0, [R1] ; write to PF3-1
BX LR
ALIGN ; make sure the end of this section is aligned (For
the code/data to follow)
END ; mark end of file
eece237lab2/startup.s
; <<< Use Configuration Wizard in Context Menu >>>
;****************************************************
**************************
20. ;
; startup_rvmdk.S - Startup code for use with Keil's uVision.
;
; Copyright (c) 2012 Texas Instruments Incorporated. All rights
reserved.
; Software License Agreement
;
; Texas Instruments (TI) is supplying this software for use
solely and
; exclusively on TI's microcontroller products. The software is
owned by
; TI and/or its suppliers, and is protected under applicable
copyright
; laws. You may not combine this software with "viral" open-
source
; software in order to form a larger program.
;
; THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL
FAULTS.
; NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR
STATUTORY, INCLUDING, BUT
21. ; NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
TI SHALL NOT, UNDER ANY
; CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL
; DAMAGES, FOR ANY REASON WHATSOEVER.
;
; This is part of revision 9453 of the EK-LM4F120XL Firmware
Package.
;
;****************************************************
**************************
; Edited to conform with ISR names as described in
; "Embedded Systems: Introduction to ARM Cortex M
Microcontrollers",
; ISBN: 978-1469998749, Jonathan Valvano, copyright (c)
2012
; "Embedded Systems: Real Time Interfacing to ARM Cortex
M Microcontrollers",
; ISBN: 978-1463590154, Jonathan Valvano, copyright (c)
2012
; "Embedded Systems: Real-Time Operating Systems for ARM
23. ;****************************************************
**************************
;
; Allocate space for the stack.
;
;****************************************************
**************************
AREA STACK, NOINIT, READWRITE, ALIGN=3
StackMem
SPACE Stack
__initial_sp
;****************************************************
**************************
;
; Allocate space for the heap.
;
;****************************************************
**************************
24. AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
HeapMem
SPACE Heap
__heap_limit
;****************************************************
**************************
;
; Indicate that the code in this file preserves 8-byte alignment of
the stack.
;
;****************************************************
**************************
PRESERVE8
;****************************************************
**************************
;
; Place code into the reset code section.
25. ;
;****************************************************
**************************
AREA RESET, CODE, READONLY
THUMB
;****************************************************
**************************
;
; The vector table.
;
;****************************************************
**************************
EXPORT __Vectors
__Vectors
DCD StackMem + Stack ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
26. DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor
Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
DCD GPIOPortA_Handler ; GPIO Port A
DCD GPIOPortB_Handler ; GPIO Port B
DCD GPIOPortC_Handler ; GPIO Port C
DCD GPIOPortD_Handler ; GPIO Port D
DCD GPIOPortE_Handler ; GPIO Port E
DCD UART0_Handler ; UART0 Rx and Tx
32. DCD Timer5B_Handler ; Timer 5 subtimer B
DCD WideTimer0A_Handler ; Wide Timer 0
subtimer A
DCD WideTimer0B_Handler ; Wide Timer 0
subtimer B
DCD WideTimer1A_Handler ; Wide Timer 1
subtimer A
DCD WideTimer1B_Handler ; Wide Timer 1
subtimer B
DCD WideTimer2A_Handler ; Wide Timer 2
subtimer A
DCD WideTimer2B_Handler ; Wide Timer 2
subtimer B
DCD WideTimer3A_Handler ; Wide Timer 3
subtimer A
DCD WideTimer3B_Handler ; Wide Timer 3
subtimer B
DCD WideTimer4A_Handler ; Wide Timer 4
subtimer A
DCD WideTimer4B_Handler ; Wide Timer 4
subtimer B
DCD WideTimer5A_Handler ; Wide Timer 5
subtimer A
33. DCD WideTimer5B_Handler ; Wide Timer 5
subtimer B
DCD FPU_Handler ; FPU
DCD PECI0_Handler ; PECI 0
DCD LPC0_Handler ; LPC 0
DCD I2C4_Handler ; I2C4 Master and Slave
DCD I2C5_Handler ; I2C5 Master and Slave
DCD GPIOPortM_Handler ; GPIO Port M
DCD GPIOPortN_Handler ; GPIO Port N
DCD Quadrature2_Handler ; Quadrature Encoder 2
DCD Fan0_Handler ; Fan 0
DCD 0 ; Reserved
DCD GPIOPortP_Handler ; GPIO Port P
(Summary or P0)
DCD GPIOPortP1_Handler ; GPIO Port P1
DCD GPIOPortP2_Handler ; GPIO Port P2
DCD GPIOPortP3_Handler ; GPIO Port P3
DCD GPIOPortP4_Handler ; GPIO Port P4
DCD GPIOPortP5_Handler ; GPIO Port P5
34. DCD GPIOPortP6_Handler ; GPIO Port P6
DCD GPIOPortP7_Handler ; GPIO Port P7
DCD GPIOPortQ_Handler ; GPIO Port Q
(Summary or Q0)
DCD GPIOPortQ1_Handler ; GPIO Port Q1
DCD GPIOPortQ2_Handler ; GPIO Port Q2
DCD GPIOPortQ3_Handler ; GPIO Port Q3
DCD GPIOPortQ4_Handler ; GPIO Port Q4
DCD GPIOPortQ5_Handler ; GPIO Port Q5
DCD GPIOPortQ6_Handler ; GPIO Port Q6
DCD GPIOPortQ7_Handler ; GPIO Port Q7
DCD GPIOPortR_Handler ; GPIO Port R
DCD GPIOPortS_Handler ; GPIO Port S
DCD PWM1Generator0_Handler ; PWM 1 Generator
0
DCD PWM1Generator1_Handler ; PWM 1 Generator
1
DCD PWM1Generator2_Handler ; PWM 1 Generator
2
DCD PWM1Generator3_Handler ; PWM 1 Generator
3
35. DCD PWM1Fault_Handler ; PWM 1 Fault
;****************************************************
**************************
;
; This is the code that gets called when the processor first starts
execution
; following a reset event.
;
;****************************************************
**************************
EXPORT Reset_Handler
Reset_Handler
;
; DO NOT Enable the floating-point unit. This must be
done here to handle the
; case where main() uses floating-point and the function
prologue saves
; floating-point registers (which will fault if floating-point
is not
; enabled). Any configuration of the floating-point unit
36. using
; DriverLib APIs must be done here prior to the floating-
point unit
; being enabled.
;
; Note that this does not use DriverLib since it might not
be included
; in this project.
;
; MOVW R0, #0xED88
; MOVT R0, #0xE000
; LDR R1, [R0]
; ORR R1, #0x00F00000
; STR R1, [R0]
;
; Call the C library enty point that handles startup. This
will copy
; the .data section initializers from flash to SRAM and
zero fill the
37. ; .bss section.
;
IMPORT Start
B Start ;call user assembly language program
;****************************************************
**************************
;
; This is the code that gets called when the processor receives a
NMI. This
; simply enters an infinite loop, preserving the system state for
examination
; by a debugger.
;
;****************************************************
**************************
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
38. ;****************************************************
**************************
;
; This is the code that gets called when the processor receives a
fault
; interrupt. This simply enters an infinite loop, preserving the
system state
; for examination by a debugger.
;
;****************************************************
**************************
HardFault_Handler
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler
PROC
39. EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler
56. ; outputs: none
EnableInterrupts
CPSIE I
BX LR
;*********** StartCritical ************************
; make a copy of previous I bit, disable interrupts
; inputs: none
; outputs: previous I bit
StartCritical
MRS R0, PRIMASK ; save old status
CPSID I ; mask all (except faults)
BX LR
;*********** EndCritical ************************
; using the copy of previous I bit, restore I bit to previous value
; inputs: previous I bit
; outputs: none
57. EndCritical
MSR PRIMASK, R0
BX LR
;*********** WaitForInterrupt ************************
; go to low power mode while waiting for the next interrupt
; inputs: none
; outputs: none
WaitForInterrupt
WFI
BX LR
;****************************************************
**************************
;
; Make sure the end of this section is aligned.
71. ; Hardware connections
; PF0 is switch input (1 means switch is not pressed, 0 means
switch is pressed)
; PF44 is switch input (1 means switch is not pressed, 0 means
switch is pressed)
; PF1, 2, 3 are LED output (0 means door is locked, 1 means
door is unlocked)
; The specific operation of this system is to unlock if both
switches are pressed
; Useful declarations
THUMB
; PortF register declarations
GPIO_PORTF_DATA_R EQU 0x400253FC
GPIO_PORTF_DIR_R EQU 0x40025400
GPIO_PORTF_AFSEL_R EQU 0x40025420
GPIO_PORTF_PUR_R EQU 0x40025510
GPIO_PORTF_DEN_R EQU 0x4002551C
GPIO_PORTF_LOCK_R EQU 0x40025520
72. GPIO_PORTF_CR_R EQU 0x40025524
GPIO_PORTF_AMSEL_R EQU 0x40025528
GPIO_PORTF_PCTL_R EQU 0x4002552C
GPIO_LOCK_KEY EQU 0x4C4F434B ; Unlocks the
GPIO_CR register
SYSCTL_RCGC2_R EQU 0x400FE108
SYSCTL_RCGC2_GPIOF EQU 0x00000020 ; port F Clock
Gating Control
AREA DATA, ALIGN=2
; Global variables go here, you will not need any in
lab2.
ALIGN ; make sure the end of this section is aligned
AREA |.text|, CODE, READONLY, ALIGN=2
EXPORT Start
Start
; Write initialization code here. This segment is only executed
once at reset
73. ;------------PortF_Init------------
; Initialize GPIO Port F for negative logic switches on PF0 and
; PF4 to match Launchpad wiring. Weak internal pull-up
; resistors are enabled, and the NMI functionality on PF0 is
; disabled. R,G, and B LED's Pins (PF1-PF3) set as outputs.
; Follows Valvano Text program 4.1.
; Input: none
; Output: none
; Modifies: R0, R1, R2
PortF_Init
LDR R1, =SYSCTL_RCGC2_R ; 1) activate clock for
Port F
LDR R0, [R1]
ORR R0, R0, #0x20 ; set bit 5 to turn on clock
STR R0, [R1]
NOP
NOP ; allow time for clock to finish
; 2) unlock the
74. lock register
; unlock GPIO
Port F Commit Register
; enable commit
for Port F
; 1 means allow
access
; 3) disable
analog functionality
; 0 means analog
is off
; 4) configure as
GPIO
; 0 means
configure Port F as GPIO
; 5) set direction
register
; PF0 and PF7-4
input, PF3-1 output
; 6) regular port
function
; 0 means disable
alternate function
; pull-up resistors
75. for PF4,PF0
; enable weak
pull-up on PF0 and PF4
; 7) enable Port F
digital port
; 1 means enable
digital I/O
mainloop
; Write your main program here. This segment
loops indefinitely while the microcontroller is on
; You must use the Portf_Input and Portf_Output
functions to access PortF
B mainloop ;infinite main loop
; Useful Functions
; (From Valvano Text Program 4.1)
;------------PortF_Input------
76. ; Read ProtF
; Input: none
; Output: R0 value read from PortF
; Modifies: R1
PortF_Input
LDR R1, =GPIO_PORTF_DATA_R ; pointer to Port F
data
LDR R0, [R1] ; read all of PortF
AND R0,R0,#0x11 ; just the input
pins, bits 4,0
BX LR ; return R0 with inputs
;------------PortF_Output------
; Set the output state of PF3-1.
; Input: R0 new state of PF
; Output: none
; Modifies: R1
PortF_Output
LDR R1, =GPIO_PORTF_DATA_R ; pointer to Port F
77. data
STR R0, [R1] ; write to PF3-1
BX LR
ALIGN ; make sure the end of this section is aligned (For
the code/data to follow)
END ; mark end of file
eece237lab2/startup.s
; <<< Use Configuration Wizard in Context Menu >>>
;****************************************************
**************************
;
; startup_rvmdk.S - Startup code for use with Keil's uVision.
;
; Copyright (c) 2012 Texas Instruments Incorporated. All rights
reserved.
; Software License Agreement
;
78. ; Texas Instruments (TI) is supplying this software for use
solely and
; exclusively on TI's microcontroller products. The software is
owned by
; TI and/or its suppliers, and is protected under applicable
copyright
; laws. You may not combine this software with "viral" open-
source
; software in order to form a larger program.
;
; THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL
FAULTS.
; NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR
STATUTORY, INCLUDING, BUT
; NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
TI SHALL NOT, UNDER ANY
; CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL
; DAMAGES, FOR ANY REASON WHATSOEVER.
;
; This is part of revision 9453 of the EK-LM4F120XL Firmware
79. Package.
;
;****************************************************
**************************
; Edited to conform with ISR names as described in
; "Embedded Systems: Introduction to ARM Cortex M
Microcontrollers",
; ISBN: 978-1469998749, Jonathan Valvano, copyright (c)
2012
; "Embedded Systems: Real Time Interfacing to ARM Cortex
M Microcontrollers",
; ISBN: 978-1463590154, Jonathan Valvano, copyright (c)
2012
; "Embedded Systems: Real-Time Operating Systems for ARM
Cortex M Microcontrollers",
; ISBN: 978-1466468863, Jonathan Valvano, copyright (c)
2013
;
;****************************************************
**************************
;
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
81. AREA STACK, NOINIT, READWRITE, ALIGN=3
StackMem
SPACE Stack
__initial_sp
;****************************************************
**************************
;
; Allocate space for the heap.
;
;****************************************************
**************************
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
HeapMem
SPACE Heap
__heap_limit
;****************************************************
82. **************************
;
; Indicate that the code in this file preserves 8-byte alignment of
the stack.
;
;****************************************************
**************************
PRESERVE8
;****************************************************
**************************
;
; Place code into the reset code section.
;
;****************************************************
**************************
AREA RESET, CODE, READONLY
THUMB
;****************************************************
**************************
90. DCD WideTimer2A_Handler ; Wide Timer 2
subtimer A
DCD WideTimer2B_Handler ; Wide Timer 2
subtimer B
DCD WideTimer3A_Handler ; Wide Timer 3
subtimer A
DCD WideTimer3B_Handler ; Wide Timer 3
subtimer B
DCD WideTimer4A_Handler ; Wide Timer 4
subtimer A
DCD WideTimer4B_Handler ; Wide Timer 4
subtimer B
DCD WideTimer5A_Handler ; Wide Timer 5
subtimer A
DCD WideTimer5B_Handler ; Wide Timer 5
subtimer B
DCD FPU_Handler ; FPU
DCD PECI0_Handler ; PECI 0
DCD LPC0_Handler ; LPC 0
DCD I2C4_Handler ; I2C4 Master and Slave
DCD I2C5_Handler ; I2C5 Master and Slave
DCD GPIOPortM_Handler ; GPIO Port M
91. DCD GPIOPortN_Handler ; GPIO Port N
DCD Quadrature2_Handler ; Quadrature Encoder 2
DCD Fan0_Handler ; Fan 0
DCD 0 ; Reserved
DCD GPIOPortP_Handler ; GPIO Port P
(Summary or P0)
DCD GPIOPortP1_Handler ; GPIO Port P1
DCD GPIOPortP2_Handler ; GPIO Port P2
DCD GPIOPortP3_Handler ; GPIO Port P3
DCD GPIOPortP4_Handler ; GPIO Port P4
DCD GPIOPortP5_Handler ; GPIO Port P5
DCD GPIOPortP6_Handler ; GPIO Port P6
DCD GPIOPortP7_Handler ; GPIO Port P7
DCD GPIOPortQ_Handler ; GPIO Port Q
(Summary or Q0)
DCD GPIOPortQ1_Handler ; GPIO Port Q1
DCD GPIOPortQ2_Handler ; GPIO Port Q2
DCD GPIOPortQ3_Handler ; GPIO Port Q3
DCD GPIOPortQ4_Handler ; GPIO Port Q4
92. DCD GPIOPortQ5_Handler ; GPIO Port Q5
DCD GPIOPortQ6_Handler ; GPIO Port Q6
DCD GPIOPortQ7_Handler ; GPIO Port Q7
DCD GPIOPortR_Handler ; GPIO Port R
DCD GPIOPortS_Handler ; GPIO Port S
DCD PWM1Generator0_Handler ; PWM 1 Generator
0
DCD PWM1Generator1_Handler ; PWM 1 Generator
1
DCD PWM1Generator2_Handler ; PWM 1 Generator
2
DCD PWM1Generator3_Handler ; PWM 1 Generator
3
DCD PWM1Fault_Handler ; PWM 1 Fault
;****************************************************
**************************
;
; This is the code that gets called when the processor first starts
execution
; following a reset event.
93. ;
;****************************************************
**************************
EXPORT Reset_Handler
Reset_Handler
;
; DO NOT Enable the floating-point unit. This must be
done here to handle the
; case where main() uses floating-point and the function
prologue saves
; floating-point registers (which will fault if floating-point
is not
; enabled). Any configuration of the floating-point unit
using
; DriverLib APIs must be done here prior to the floating-
point unit
; being enabled.
;
; Note that this does not use DriverLib since it might not
be included
; in this project.
94. ;
; MOVW R0, #0xED88
; MOVT R0, #0xE000
; LDR R1, [R0]
; ORR R1, #0x00F00000
; STR R1, [R0]
;
; Call the C library enty point that handles startup. This
will copy
; the .data section initializers from flash to SRAM and
zero fill the
; .bss section.
;
IMPORT Start
B Start ;call user assembly language program
;****************************************************
**************************
;
95. ; This is the code that gets called when the processor receives a
NMI. This
; simply enters an infinite loop, preserving the system state for
examination
; by a debugger.
;
;****************************************************
**************************
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
;****************************************************
**************************
;
; This is the code that gets called when the processor receives a
fault
; interrupt. This simply enters an infinite loop, preserving the
system state
; for examination by a debugger.
112. ; Some code in the normal code section for initializing the heap
and stack.
;
;****************************************************
**************************
AREA |.text|, CODE, READONLY
;****************************************************
**************************
;
; Useful functions.
;
;****************************************************
**************************
EXPORT DisableInterrupts
EXPORT EnableInterrupts
EXPORT StartCritical
EXPORT EndCritical
EXPORT WaitForInterrupt
113. ;*********** DisableInterrupts ***************
; disable interrupts
; inputs: none
; outputs: none
DisableInterrupts
CPSID I
BX LR
;*********** EnableInterrupts ***************
; disable interrupts
; inputs: none
; outputs: none
EnableInterrupts
CPSIE I
BX LR
;*********** StartCritical ************************
; make a copy of previous I bit, disable interrupts
114. ; inputs: none
; outputs: previous I bit
StartCritical
MRS R0, PRIMASK ; save old status
CPSID I ; mask all (except faults)
BX LR
;*********** EndCritical ************************
; using the copy of previous I bit, restore I bit to previous value
; inputs: previous I bit
; outputs: none
EndCritical
MSR PRIMASK, R0
BX LR
;*********** WaitForInterrupt ************************
; go to low power mode while waiting for the next interrupt
; inputs: none
115. ; outputs: none
WaitForInterrupt
WFI
BX LR
;****************************************************
**************************
;
; Make sure the end of this section is aligned.
;
;****************************************************
**************************
ALIGN
;****************************************************
**************************
;
116. ; Tell the assembler that we're done.
;
;****************************************************
**************************
END
Lab 02 EECE 237, Fall 2016 Semester
Objectives:
1. To gain experience with the ARM Assembly and the TI TIVA
C Launchpad
Development Board.
2. To gain experience of the Keil ARM development
environment and debugging
features.
3. To gain experience with the ARM I/O port con_guration and
interfacing GPIO
pins to buttons and LEDs.
Reference:
1. Textbook x4:1:1 and x4:2:1.
Introduction: In this experiment you will write assembly code to
control to implement
a rudimentary user interface of your launchpad. There are two
push buttons and three
LEDs that are mounted on your TM4C123 board as shown in
Figure 1.
Figure 1: Switch and LED interface on the Launchpad
In this lab, we will poll the switches and drive the LEDs in
interesting ways. The
challenge is con_guring the GPIO pins appropriately, reading
values from PF0 and
117. PF4 (your push buttons) and driving the appropriate output pins
in response (namely,
PF1, PF2, and PF3 for the red, blue, and green LEDs
respectively). Note from the
schematic in Figure 1 that the LEDs are positive logic and the
switches are negative
logic. Also, the switches will need pull-up resistors. This will
be provided by enabling
internal pull-ups in the TM4C123 through GPIO PORTF PUR R.
Experiment:
1. Download the project in eece237lab2.zip from the course
website as a starting
point. The _rst step is to initialize the TM4C123 GIPIO Port F
as appropriate
to the LEDs and push buttons that are mounted on the TIVA C
Development
board. As described in the course text in section 4.2.1 there are
several registers
that need to be set to speci_c values for PF0-PF4 to be
con_gured correctly. Do
this _rst.
2. Implement the following LED output behaviors based on the
button inputs.
_ If both buttons are simultaneously pressed we would like to
illuminate the
green LED, indicating the user has been granted access.
_ If only SW1 is pressed, light the Blue LED.
_ If only SW2 is pressed, light the Red LED.
_ If no buttons are pressed, no LEDs will be illuminated.
Your code should poll the switches and illuminate the LEDs as
described above.
You must use the Portf Input and Portf Output functions to
access
PortF. These two functions are provided in main2.s in
eece237lab2.zip.
What to turn in:
118. 1. Write a document describing how you design your code using
owcharts. The
writeup is due on Oct. 10 at the beginning of the class. Print
your writeup on
paper to turn in.
2. The code is due on Oct. 9 at 11:00 pm. Submit your code in
Blackboard Learn. Compress yourcode in a .zip" _le and then
upload it to Blackboard Learn. Please include all the code that
makes your launchpad runnable.