; GPIO.s ; Runs on LM4F120 and TM4C123 ; Implements a NOT gate described in clas
ID: 2267718 • Letter: #
Question
; GPIO.s
; Runs on LM4F120 and TM4C123
; Implements a NOT gate described in class
; PD3 is an output to LED, Positive logic
; PD0 is an input from switch, Positive logic
; Switch pressed causes LED to go OFF and
; release causes LED to go ON.
; **** To run this example in Simulator
; make sure and copy the C0DLL.dll file
;(in the folder where this [GPIO.s]file is)
; to your Keil ARM/Bin folder;
;; Note that running the simulator gives 4 warnings
;; Click OK and continue
GPIO_PORTD_DATA_R EQU 0x400073FC
GPIO_PORTD_DIR_R EQU 0x40007400
GPIO_PORTD_AFSEL_R EQU 0x40007420
GPIO_PORTD_DEN_R EQU 0x4000751C
SYSCTL_RCGCGPIO_R EQU 0x400FE608
AREA |.text|, CODE, READONLY, ALIGN=2
THUMB
EXPORT Start
GPIO_Init
; 1) activate clock for Port D
LDR R1, =SYSCTL_RCGCGPIO_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x08 ; R0 = R0|0x08
STR R0, [R1] ; [R1] = R0
NOP
NOP
NOP
NOP ; allow time to finish activating
; 3) set direction register
LDR R1, =GPIO_PORTD_DIR_R ; R1 = &GPIO_PORTD_DIR_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x08 ; R0 = R0|0x08 (make PD3 output)
;BIC R0, R0, #0x01 ; R0 = R0 & NOT(0x01) (make PD0 input)
STR R0, [R1] ; [R1] = R0
; 4) regular port function
LDR R1, =GPIO_PORTD_AFSEL_R ; R1 = &GPIO_PORTD_AFSEL_R
LDR R0, [R1] ; R0 = [R1]
BIC R0, R0, #0x09 ; R0 = R0&~0x09 (disable alt funct on PD3,PD0)
STR R0, [R1] ; [R1] = R0
; 5) enable digital port
LDR R1, =GPIO_PORTD_DEN_R ; R1 = &GPIO_PORTD_DEN_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x09 ; R0 = R0|0x09 (enable digital I/O on PD3,PD0)
STR R0, [R1] ; [R1] = R0
BX LR
Start
BL GPIO_Init
LDR R0, =GPIO_PORTD_DATA_R
loop
LDR R1,[R0]
ORR R1, #0x08 ;
STR R1,[R0] ; Write to PortD DATA register to update LED on PD3
B loop ; unconditional branch to 'loop'
ALIGN ; make sure the end of this section is aligned
END ; end of file
how can i Modify this sample code so Port D's pin 1, pin 3, and pin 5 output 3.3V. Also make Port D's pin 2 an input.
thank you
Explanation / Answer
To configure the Port pin as Output pin
1. Set corresponding port pin bit in Direction register (GPIO_PORTD_DIR_R)
2. Disable altenate function in GPIO_PORTD_AFSEL_R i.e clear corresponding port pin bit
3. Enable digital port in GPIO_PORTD_DEN_R i.e set corresponding port pin bit
To configure as input port pin
1. Clear corresponding port pin bit in Direction register (GPIO_PORTD_DIR_R)
2. Disable altenate function in GPIO_PORTD_AFSEL_R i.e clear corresponding port pin bit
3. Enable digital port in GPIO_PORTD_DEN_R i.e set corresponding port pin bit
Modified code:
PORTD PIN 1, 3 and 5 as output pin and generate logic high i.e. 3.3V
PORTD PIN 2 as input
; GPIO.s
; Runs on LM4F120 and TM4C123
; Implements a NOT gate described in class
; PD3 is an output to LED, Positive logic
; PD0 is an input from switch, Positive logic
; Switch pressed causes LED to go OFF and
; release causes LED to go ON.
; **** To run this example in Simulator
; make sure and copy the C0DLL.dll file
;(in the folder where this [GPIO.s]file is)
; to your Keil ARM/Bin folder;
;; Note that running the simulator gives 4 warnings
;; Click OK and continue
GPIO_PORTD_DATA_R EQU 0x400073FC
GPIO_PORTD_DIR_R EQU 0x40007400
GPIO_PORTD_AFSEL_R EQU 0x40007420
GPIO_PORTD_DEN_R EQU 0x4000751C
SYSCTL_RCGCGPIO_R EQU 0x400FE608
AREA |.text|, CODE, READONLY, ALIGN=2
THUMB
EXPORT Start
GPIO_Init
; 1) activate clock for Port D
LDR R1, =SYSCTL_RCGCGPIO_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x08 ; R0 = R0|0x08
STR R0, [R1] ; [R1] = R0
NOP
NOP
NOP
NOP ; allow time to finish activating
;3) set direction register
LDR R1, =GPIO_PORTD_DIR_R ; R1 = &GPIO_PORTD_DIR_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x2A ; R0 = R0|0x2A (make PD1 PD3 PD5 as output 101010 = 0x2A)
BIC R0, R0, #0x04 ; R0 = R0 & NOT(0x04) (make PD2 input 100 = 0x04)
STR R0, [R1] ; [R1] = R0
;4) regular port functions
LDR R1, =GPIO_PORTD_AFSEL_R ; R1 = &GPIO_PORTD_AFSEL_R
LDR R0, [R1] ; R0 = [R1]
BIC R0, R0, #0x2E ; R0 = R0&~0x2E (disable alt funct on PD1, PD3, PD5, PD2 101110 = 0x2E)
STR R0, [R1] ; [R1] = R0
;5) enable digital port
LDR R1, =GPIO_PORTD_DEN_R ; R1 = &GPIO_PORTD_DEN_R
LDR R0, [R1] ; R0 = [R1]
ORR R0, R0, #0x2E ; R0 = R0|0x2E (enable digital I/O on PD1, PD3, PD5, PD2)
STR R0, [R1] ; [R1] = R0
BX LR
Start
BL GPIO_Init
LDR R0, =GPIO_PORTD_DATA_R
loop
LDR R1,[R0]
ORR R1, #0x2A ; Write Logic 1 to output 3.3V on PD1, PD3 and PD5
STR R1,[R0] ; Write to PortD DATA register to update LED on PD3
B loop ; unconditional branch to 'loop'
ALIGN ; make sure the end of this section is aligned
END ; end of file
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.