Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. ;*-------------------------------------------------------------------
  2. ;* Name: lab_4_program.s
  3. ;* Purpose: A sample style for lab-4
  4. ;* Term: Winter 2013
  5. ;*-------------------------------------------------------------------
  6. THUMB ; Declare THUMB instruction set
  7. AREA My_code, CODE, READONLY ;
  8. EXPORT __MAIN ; Label __MAIN is used externally
  9.  
  10. ENTRY
  11.  
  12. __MAIN
  13. LDR R10, = ISER0
  14. LDR R1, [R10]
  15. ORR R1, R1, #0x200000 ; setting bit 21 of ISER0
  16. STR R1, [R10] ; store the value into ISER0 to enable EINT3
  17. MOV R6, #0x1 ; R6 is getting set a as a flag, 1 when not pressed, 0 when pressed
  18. LDR R10, = IO2IntEnf
  19. LDR R1, [R10]
  20. ORR R1, R1, #0x400
  21. STR R1, [R10]
  22. ; falling edge because that's when the button is pressed, raising edge doesn't record this
  23.  
  24. ; The following lines are similar to previous labs.
  25. ; They just turn off all LEDs
  26. LDR R10, =LED_BASE_ADR ; R10 is a pointer to the base address for the LEDs
  27. MOV R3, #0xB0000000 ; Turn off three LEDs on port 1
  28. STR R3, [r10, #0x20]
  29. MOV R3, #0x0000007C
  30. STR R3, [R10, #0x40] ; Turn off five LEDs on port 2
  31.  
  32.  
  33. ; This line is very important in your main program
  34. ; Initializes R11 to a 16-bit non-zero value and NOTHING else can write to R11 !!
  35. MOV R11, #0xABCD ; Init the random number generator with a non-zero number
  36. BL RNG
  37. ; going to use R12 and so on
  38. MOV R2, R11
  39. AND R2, R2, #0x7 ; Take last 3 bits of R11 (#0x7 = 111 in binary)
  40. ADD R2, R2, #2 ; AND to store last 3 bits of R11 in R5
  41. AND R3, R11, #0x10 ; Take 4th bit of R11
  42. LSR R3, R3, #4 ; Shift it to make the bit LSB for adding
  43. ADD R2, R2, R3 ; After adding, R5 has random number between 2-10
  44. MOV R3, #10000
  45. MUL R2, R2, R3 ; Multiply R5 by 10000
  46. ADD R0, R2, #0 ; Store into R0 for delay decrementer
  47. MOV R9, #0x007D
  48. MOVT R9, #0x0 ; Takes 0.1 ms (approx) to subtract to 0
  49. MUL R0, R9, R0 ; R0 now has a number that takes between 2-10 seconds to subtract to 0
  50. BL LED_ALT
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. ;
  58. ; Your main program can appear here
  59. ;
  60.  
  61. ; 4C4B4 for 0.25 second
  62. ; try not to use R6
  63. ; 4FFFFF83 for turning all of them on
  64. ; need some work
  65. LED_ALT STMFD R13!, {R1-R12, R14}
  66. MOV R4, #0xC4B4
  67. MOVT R4, #0x0004
  68. MOV R5, R0 ; copy over the value of R0
  69. MOV R0, R4 ; calls the .25 delay
  70. BL DELAY ; call DELAY
  71. SUBS R5, R5, R4
  72. ADD R0, R5, #0
  73. BL LED_OFF
  74. ; for lighting the second four (left side)
  75. MOV R3, #0xFFFB
  76. MOVT R3, #0x4FFF
  77. STR R3, [R10, #0x20]
  78. STR R3, [R10, #0x40]
  79. MOV R4, #0xC4B4
  80. MOVT R4, #0x0004
  81. MOV R5, R0 ; copy over the value of R0
  82. MOV R0, R4 ; calls the .25 delay
  83. BL DELAY ; call DELAY
  84. SUBS R5, R5, R4
  85. ADD R0, R5, #0
  86. BL LED_OFF
  87. ; for lighting the first four (right side)
  88. MOV R3, #0x00000004
  89. STR R3, [R10, #0x40]
  90. BLT LED_ALT
  91. LDMFD R13!, {R1-R12, R15}
  92.  
  93. LED_OFF STMFD R13!, {R3, R14}
  94. MOV R3, #0xB0000000 ; Turn off three LEDs on port 1
  95. STR R3, [R10, #0x20] ; Write the necessary bits to turn off the LED on port 1
  96. MOV R3, #0x0000007C ; Move the necessary number for turning off port 2
  97. STR R3, [R10, #0x40] ; Turn off five LEDs on port 2
  98. LDMFD R13!, {R3, R15}
  99. ;*-------------------------------------------------------------------
  100. ; Subroutine RNG ... Generates a pseudo-Random Number in R11
  101. ;*-------------------------------------------------------------------
  102. ; R11 holds a random number as per the Linear feedback shift register (Fibonacci) on WikiPedia
  103. ; R11 MUST be initialized to a non-zero 16-bit value at the start of the program
  104. ; R11 can be read anywhere in the code but must only be written to by this subroutine
  105. RNG STMFD R13!,{R1-R3, R14} ; Random Number Generator
  106. AND R1, R11, #0x8000
  107. AND R2, R11, #0x2000
  108. LSL R2, #2
  109. EOR R3, R1, R2
  110. AND R1, R11, #0x1000
  111. LSL R1, #3
  112. EOR R3, R3, R1
  113. AND R1, R11, #0x0400
  114. LSL R1, #5
  115. EOR R3, R3, R1 ; The new bit to go into the LSB is present
  116. LSR R3, #15
  117. LSL R11, #1
  118. ORR R11, R11, R3
  119. LDMFD R13!,{R1-R3, R15}
  120.  
  121. ;*-------------------------------------------------------------------
  122. ; Subroutine DELAY ... Causes a delay of 1ms * R0 times
  123. ;*-------------------------------------------------------------------
  124. DELAY STMFD R13!,{R0, R14}
  125. ; MUL R9, R9, R0 ; code to generate a delay of 0.1mS * R0 times
  126. loopDelay SUBS R0, R0, #1 ; Keep subtracting until we have reached 0
  127. BNE loopDelay
  128. ;
  129. exitDelay LDMFD R13!,{R0, R15}
  130.  
  131. ; The Interrupt Service Routine MUST be in the startup file for simulation
  132. ; to work correctly. Add it where there is the label "EINT3_IRQHandler
  133. ;
  134. ;*-------------------------------------------------------------------
  135. ; Interrupt Service Routine (ISR) for EINT3_IRQHandler
  136. ;*-------------------------------------------------------------------
  137. ; This ISR handles the interrupt triggered when the INT0 push-button is pressed
  138. ; with the assumption that the interrupt activation is done in the main program
  139. EINT3_IRQHandler
  140. ;STMFD ... ; Use this command if you need it
  141. ;
  142. ; Code that handles the interrupt
  143. ;
  144. ;LDMFD ... ; Use this command if you used STMFD (otherwise use BX LR)
  145. MOV R6, #0x00 ; clearing the interrupt
  146. LDR R10, =IO2IntEnf
  147. LDR R1, [R10]
  148. EOR R1, R1, #0X400
  149. STR R1, [R10]
  150. BX LR
  151.  
  152.  
  153. ;*-------------------------------------------------------------------
  154. ; Below is a list of useful registers with their respective memory addresses.
  155. ;*-------------------------------------------------------------------
  156. LED_BASE_ADR EQU 0x2009c000 ; Base address of the memory that controls the LEDs
  157. PINSEL3 EQU 0x4002C00C ; Pin Select Register 3 for P1[31:16]
  158. PINSEL4 EQU 0x4002C010 ; Pin Select Register 4 for P2[15:0]
  159. FIO1DIR EQU 0x2009C020 ; Fast Input Output Direction Register for Port 1
  160. FIO2DIR EQU 0x2009C040 ; Fast Input Output Direction Register for Port 2
  161. FIO1SET EQU 0x2009C038 ; Fast Input Output Set Register for Port 1
  162. FIO2SET EQU 0x2009C058 ; Fast Input Output Set Register for Port 2
  163. FIO1CLR EQU 0x2009C03C ; Fast Input Output Clear Register for Port 1
  164. FIO2CLR EQU 0x2009C05C ; Fast Input Output Clear Register for Port 2
  165. IO2IntEnf EQU 0x400280B4 ; GPIO Interrupt Enable for port 2 Falling Edge
  166. ISER0 EQU 0xE000E100 ; Interrupt Set-Enable Register 0
  167.  
  168. ALIGN
  169.  
  170. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement