Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AREA GPIO, CODE, READWRITE
- EXPORT lab4
- IMPORT read_from_push_btns
- IMPORT illuminate_RGB_LED
- IMPORT illuminate_LEDs
- IMPORT write_to_7_segs
- IMPORT read_character
- IMPORT output_character
- IMPORT output_string
- IMPORT read_string
- IMPORT div_and_mod
- PIODATA EQU 0x8 ; Offset to parallel I/O data register
- prompt = "Welcome to lab #4 ",0 ; Text to be sent to PuTTy
- menu = "Choose what to do: \n\r1: Display 4-bit binary value on LEDs\n\r2: Input 4-bit binary value using push buttons\n\r3: Display single hex digit on 7-segment display\n\r4: Illuminate RGB LED with a color \n\r5: Quit \n\r\n\r\n\r", 0
- instruction_LEDs = "Type the number to be displayed, in lowercase hex, can be between 0 and f \n\r", 0
- instruction_buttons = "Press buttons corresponding to '1' bits and hold them down, then press SpaceBar while holding \n\r", 0
- instruction_hex = "Type number of desired display (0,1,2,3), followed by digit to display\n\r", 0
- instruction_RGBLED = "Type the character corresponding to the desired color (r|g|b|y|p|w)", 0
- result = "The value entered is: ", 0
- ALIGN
- lab4
- STMFD SP!,{lr} ; Store register lr on stack
- MOV r0, #0x6F ;
- BL illuminate_RGB_LED ; Turn RGB LED off
- MOV r0, #0x0 ;
- BL illuminate_LEDs ; Turn off LEDs
- loop
- ; Display menu and read user selection
- LDR r4, =menu
- BL output_string
- BL read_character
- ; Branch to correct code section
- CMP r0, #0x31
- BEQ LEDs
- CMP r0, #0x32
- BEQ buttons
- CMP r0, #0x33
- BEQ hex_on_seven_segs
- CMP r0, #0x34
- BEQ RGBLED
- CMP r0, #0x35
- BEQ done
- ; Subroutine handling LED function
- LEDs
- ; Display instructions and read input
- LDR r4, =instruction_LEDs
- BL output_string
- BL read_character
- CMP r0, #0x39
- SUBGT r0, r0, #87
- ; display number on LEDs
- BL illuminate_LEDs
- B loop
- ; Subroutine handling buttons function
- buttons
- ; Display instructions
- LDR r4, =instruction_buttons
- BL output_string
- BL read_from_push_btns
- B loop
- ; Subroutine handling displaying hex digit on 7 segs
- hex_on_seven_segs
- ; Display instructions and read input
- LDR r4, =instruction_hex
- BL output_string
- BL read_character
- MOV r1, r0
- BL read_character
- BL write_to_7_segs
- B loop
- ; Subroutine handling RGBLED function
- RGBLED
- ; Display instructions and read input
- LDR r4, =instruction_RGBLED
- BL output_string
- BL read_character
- BL illuminate_RGB_LED
- B loop
- done
- LDMFD SP!, {lr} ; Restore register lr from stack
- BX LR
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement