; AND OR EXOR GATES USING ONBOARD SWITCHES AND LED'S
; S1 S2 AND OR EXOR
; (RED) (GREEN) (BLUE)
;0 0 0 0 0
;0 1 0 1 1
;1 0 0 1 1
;1 1 1 1 0
; *Define the GPIO Port F registers*
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
; *Define the GPIO Port B registers*
GPIO_PORTB_DATA_R EQU 0X400053FC
GPIO_PORTB_DIR_R EQU 0X40005400
GPIO_PORTB_AFSEL_R EQU 0X40005420
GPIO_PORTB_PUR_R EQU 0X40005510
GPIO_PORTB_DEN_R EQU 0X4000551C
GPIO_PORTB_LOCK_R EQU 0X40005520
GPIO_PORTB_CR_R EQU 0X40005524
GPIO_PORTB_AMSEL_R EQU 0X40005528
GPIO_PORTB_PCTL_R EQU 0X4000552C
SYSCTL_RCGC2_R EQU 0x400FE108
; *Define the code area, making it readable and aligned*
AREA |.text|, CODE, READONLY, ALIGN=2
EXPORT __main
__main
; *Initialize Port B and Port F for GPIO functionality*
BL GPIO_PortB_initialize ; *initialize Port B*
BL GPIO_PortF_initialize ; *initialize Port F*
PARENT_LOOP
; *Load the address of Port F Data Register and read the switch states*
LDR R0,=GPIO_PORTF_DATA_R
LDR R1,[R0]
; *Mask out the unused bits and check switches S1 (PF4) and S2 (PF0)*
AND R1,R1,#0x11
; *Check if switch S2 is pressed (EXOR + OR operation)*
CMP R1,#0x10
BEQ LED_1
; *Check if switch S1 is pressed (EXOR + OR operation)*
CMP R1,#0x01
BEQ LED_1
; *Check if both switches are pressed (AND + OR operation)*
CMP R1,#0x00
BEQ LED_2
; *Check if no switches are pressed, turn off LEDs*
CMP R1,#0x11
BEQ LED_OFF
; *Continue looping through the parent loop*
B PARENT_LOOP
LED_1
; *OR operation: Set the appropriate bits to turn on green and blue LEDs (GPIO Port B)*
LDR R0,=GPIO_PORTB_DATA_R
MOV R1,#0x03
STR R1,[R0]
NOP
NOP
NOP
B PARENT_LOOP
LED_2
; *XOR operation: Set the appropriate bits to turn on red and blue LEDs (GPIO Port B)*
LDR R0,=GPIO_PORTB_DATA_R
MOV R1,#0x06
STR R1,[R0]
NOP
NOP
NOP
B PARENT_LOOP
LED_OFF
; *Turn off all LEDs (set Port B to 0)*
LDR R0,=GPIO_PORTB_DATA_R
MOV R1,#0x00
STR R1,[R0]
NOP
NOP
NOP
B PARENT_LOOP
GPIO_PortF_initialize
; *Enable clock for Port F and unlock Port F configuration*
LDR R0, =SYSCTL_RCGC2_R
LDR R1, [R0]
ORR R1,R1, #0x20
STR R1, [R0]
NOP
NOP
LDR R0, =GPIO_PORTF_LOCK_R
MOV32 R1, #0x4C4F434B
STR R1, [R0]
; *Enable changes for PF4-PF0 and set input/output direction (PF4, PF0 input; PF3, PF2, PF1 output)*
LDR R0, =GPIO_PORTF_CR_R
MOV R1, #0x1F
STR R1, [R0]
LDR R0, =GPIO_PORTF_DIR_R
MOV R1, #0x0E
STR R1, [R0]
; *Enable digital function and pull-up resistors for PF4, PF0*
LDR R0, =GPIO_PORTF_DEN_R
MOV R1, #0x1F
STR R1, [R0]
LDR R0, =GPIO_PORTF_PUR_R
MOV R1, #0x11
STR R1, [R0]
; *Clear Port Control and disable analog functionality*
LDR R0, =GPIO_PORTF_PCTL_R
MOV32 R1, #0x00000000
STR R1, [R0]
LDR R0, =GPIO_PORTF_AMSEL_R
MOV R1, #0x00
STR R1, [R0]
LDR R0, =GPIO_PORTF_AFSEL_R
MOV R1, #0x00
STR R1, [R0]
BX LR
ALIGN
GPIO_PortB_initialize
; *Enable clock for Port B and unlock Port B configuration*
LDR R0, =SYSCTL_RCGC2_R
LDR R1, [R0]
ORR R1,R1, #0x02
STR R1, [R0]
NOP
NOP
LDR R0, =GPIO_PORTB_LOCK_R
MOV32 R1, #0x4C4F434B
STR R1, [R0]
; *Enable changes for PF4-PF0 and set input/output direction (PF0-PF7 output)*
LDR R0, =GPIO_PORTB_CR_R
MOV R1, #0x1F
STR R1, [R0]
LDR R0, =GPIO_PORTB_DIR_R
MOV R1, #0xFF
STR R1, [R0]
; *Enable digital function and disable pull-up resistors for Port B*
LDR R0, =GPIO_PORTB_DEN_R
MOV R1, #0x1F
STR R1, [R0]
LDR R0, =GPIO_PORTB_PUR_R
MOV R1, #0x00
STR R1, [R0]
; *Clear Port Control and disable analog functionality*
LDR R0, =GPIO_PORTB_PCTL_R
MOV32 R1, #0x00000000
STR R1, [R0]
LDR R0, =GPIO_PORTB_AMSEL_R
MOV R1, #0x00
STR R1, [R0]
LDR R0, =GPIO_PORTB_AFSEL_R
MOV R1, #0x00
STR R1, [R0]
BX LR
ALIGN
END