Advertisement
Guest User

Untitled

a guest
Apr 28th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.48 KB | None | 0 0
  1.     AREA    GPIO, CODE, READWRITE    
  2.     EXPORT lab4
  3.     IMPORT read_from_push_btns
  4.     IMPORT illuminate_RGB_LED
  5.     IMPORT illuminate_LEDs
  6.     IMPORT write_to_7_segs
  7.     IMPORT read_character
  8.     IMPORT output_character
  9.     IMPORT output_string
  10.     IMPORT read_string
  11.     IMPORT div_and_mod
  12.    
  13. PIODATA EQU 0x8 ; Offset to parallel I/O data register
  14.    
  15. prompt = "Welcome to lab #4  ",0       ; Text to be sent to PuTTy
  16. 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
  17. instruction_LEDs = "Type the number to be displayed, in lowercase hex, can be between 0 and f \n\r", 0
  18. instruction_buttons = "Press buttons corresponding to '1' bits and hold them down, then press SpaceBar while holding \n\r", 0
  19. instruction_hex = "Type number of desired display (0,1,2,3), followed by digit to display\n\r", 0
  20. instruction_RGBLED = "Type the character corresponding to the desired color (r|g|b|y|p|w)", 0
  21. result = "The value entered is: ", 0
  22.  
  23.     ALIGN
  24.        
  25. lab4
  26.     STMFD SP!,{lr}  ; Store register lr on stack
  27.    
  28.  
  29.     MOV r0, #0x6F                   ;
  30.     BL illuminate_RGB_LED           ; Turn RGB LED off
  31.    
  32.     MOV r0, #0x0                    ;
  33.     BL illuminate_LEDs              ; Turn off LEDs
  34. loop
  35.     ; Display menu and read user selection
  36.     LDR r4, =menu
  37.     BL output_string
  38.     BL read_character
  39.  
  40.     ; Branch to correct code section
  41.     CMP r0, #0x31
  42.     BEQ LEDs
  43.     CMP r0, #0x32
  44.     BEQ buttons
  45.     CMP r0, #0x33
  46.     BEQ hex_on_seven_segs
  47.     CMP r0, #0x34
  48.     BEQ RGBLED
  49.     CMP r0, #0x35
  50.     BEQ done
  51.  
  52.     ; Subroutine handling LED function
  53. LEDs
  54.     ; Display instructions and read input
  55.     LDR r4, =instruction_LEDs
  56.     BL output_string
  57.     BL read_character
  58.     CMP r0, #0x39
  59.     SUBGT r0, r0, #87
  60.  
  61.     ; display number on LEDs
  62.     BL illuminate_LEDs
  63.     B loop
  64.  
  65.  
  66.     ; Subroutine handling buttons function
  67. buttons
  68.     ; Display instructions
  69.     LDR r4, =instruction_buttons
  70.     BL output_string
  71.     BL read_from_push_btns
  72.    
  73.     B loop
  74.  
  75.     ; Subroutine handling displaying hex digit on 7 segs
  76. hex_on_seven_segs
  77.     ; Display instructions and read input
  78.     LDR r4, =instruction_hex
  79.     BL output_string
  80.     BL read_character
  81.     MOV r1, r0
  82.     BL read_character
  83.     BL write_to_7_segs
  84.     B loop
  85.  
  86.  
  87.     ; Subroutine handling RGBLED function
  88. RGBLED
  89.     ; Display instructions and read input
  90.     LDR r4, =instruction_RGBLED
  91.     BL output_string
  92.     BL read_character
  93.     BL illuminate_RGB_LED
  94.     B loop
  95.  
  96.  
  97.  
  98. done
  99.     LDMFD SP!, {lr} ; Restore register lr from stack
  100.     BX LR
  101.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement