Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.40 KB | None | 0 0
  1. ;*********************************************************************
  2. ;* McMaster University *
  3. ;* 2DP4 Microcontrollers *
  4. ;* Lab Section 0X *
  5. ;* First Name Last Name MACID ####### *
  6. ;* First Name Last Name MACID ####### *
  7. ;*********************************************************************
  8. ;*********************************************************************
  9. ;* Title of your Code *
  10. ;* Brief Description of your Code *
  11. ;* *
  12. ;* *
  13. ;*********************************************************************
  14. ;*****************************************************************
  15. ;* This is code supplied to students for 2DP4 Lab #2 *
  16. ;* -T. Doyle *
  17. ;*****************************************************************
  18.  
  19. ; export symbols
  20. XDEF Entry, _Startup ; export 'Entry' symbol
  21. ABSENTRY Entry ; for absolute assembly: mark this as application entry point
  22.  
  23.  
  24.  
  25. ; Include derivative-specific definitions
  26. INCLUDE 'derivative.inc'
  27.  
  28. ROMStart EQU $0400 ; absolute address to place my code/constant data
  29.  
  30. ; variable/data section
  31.  
  32. ORG RAMStart
  33. ; Insert here your data definition.
  34.  
  35.  
  36. ; code section
  37. ORG ROMStart
  38. _Startup
  39. Entry
  40. ;================================================================
  41. ; This portion of code signals to the programmer that the program
  42. ; has begun.
  43. ;================================================================
  44. LDAA #$01
  45. STAA DDRJ ; Configure PortJ's LSb as output
  46. STAA PTJ ; turn on uC LED (PJb0) to show "I'm alive!"
  47.  
  48. ;================================================================
  49. ; Configure PortAD [PT1AD] as gernal purpose I/O
  50. ; For ths lab, we will set inputs on b3-b0 and outputs b7-b4.
  51. ; Note the lab doesn't require output bits, but by moving your
  52. ; read-in bits to the output bits, it is an easy check to see if
  53. ; your code is receiving the expected data.
  54. ;================================================================
  55. LDD #$000F
  56. STD ATDDIEN ;Configure PT1AD3-PT1AD0 as digital Input for toggle switches. (Default is analog for ADC)
  57. STAB PER1AD ;Enable internal pull up resistors to avoid indeterminate state when not connected
  58.  
  59. LDAA #$F0
  60. STAA DDR1AD ; set b7-b4 as digital output pins
  61. ; set b3-b0 as digital input pins
  62.  
  63. LOOP LDAA PTI1AD ; load A with toggle switch values (read from PortAD Input Buffer)
  64. LSLA ; move b3-b0 to b4-b1
  65. LSLA ; move b4-b1 to b5-b2
  66. LSLA ; move b5-b2 to b6-b3
  67. LSLA ; move b6-b3 to b7-b4
  68. STAA PT1AD ; save input switch values to output pins/LEDS
  69.  
  70. CMPA #%00000000
  71. BEQ X0
  72.  
  73. CMPA #%00001000
  74. BEQ X1
  75.  
  76. CMPA #%00001100
  77. BEQ X2
  78.  
  79. CMPA #%00001110
  80. BEQ X3
  81.  
  82. CMPA #%00001111
  83. BEQ X4
  84.  
  85.  
  86. X0 JMP XF
  87. X1 JMP XX
  88. X2 JMP XXX
  89. X3 JMP XXXX
  90. X4 JMP XXXXX
  91.  
  92. ;The following segment is a 8 E cycle loop
  93. XF LDY #0 ; 10 * 0.5s * 0.5s
  94. LOOPON_OUT LDX #0 ; 50.000us in 50ms (0.05s)
  95. LOOPON_IN nop ; 1 E cycle
  96. nop
  97. nop
  98. nop
  99. nop
  100. dbne x,LOOPON_IN ; 3 E cycles
  101. dbne y,LOOPON_OUT ; 3 E cycles
  102.  
  103. ;This segment will turn OFF the EsduinoXtreme's onboard LED
  104. LDAB #$00
  105. STAB PTJ
  106.  
  107. ;The following segment is a 8 E cycle loop
  108. LDY #10 ; 10 * 0.5s * 0.5s
  109. LOOPOFF_OUT LDX #40625 ; 50.000us in 50ms (0.05s)
  110. LOOPOFF_IN nop ; 1 E cycle
  111. nop
  112. nop
  113. nop
  114. nop
  115. dbne x,LOOPOFF_IN ; 3 E cycles
  116. dbne y,LOOPOFF_OUT ; 3 E cycles
  117.  
  118. XX LDY #2.5 ; 20 * 0.5s * 0.5s
  119. LOOPON_OUT1 LDX #40625 ; 50.000us in 50ms (0.05s)
  120. LOOPON_IN1 nop ; 1 E cycle
  121. nop
  122. nop
  123. nop
  124. nop
  125. dbne x,LOOPON_IN ; 3 E cycles
  126. dbne y,LOOPON_OUT ; 3 E cycles
  127.  
  128. ;This segment will turn OFF the EsduinoXtreme's onboard LED
  129. LDAB #$00
  130. STAB PTJ
  131.  
  132. ;The following segment is a 8 E cycle loop
  133. LDY #7.5 ; 10 * 0.5s * 0.5s
  134. LOOPOFF_OUT1 LDX #40625 ; 50.000us in 50ms (0.05s)
  135. LOOPOFF_IN1 nop ; 1 E cycle
  136. nop
  137. nop
  138. nop
  139. nop
  140. dbne x,LOOPOFF_IN ; 3 E cycles
  141. dbne y,LOOPOFF_OUT ; 3 E cycles
  142.  
  143. XXX LDY #5 ; 20 * 0.5s * 0.5s
  144. LOOPON_OUT2 LDX #40625 ; 50.000us in 50ms (0.05s)
  145. LOOPON_IN2 nop ; 1 E cycle
  146. nop
  147. nop
  148. nop
  149. nop
  150. dbne x,LOOPON_IN ; 3 E cycles
  151. dbne y,LOOPON_OUT ; 3 E cycles
  152.  
  153. ;This segment will turn OFF the EsduinoXtreme's onboard LED
  154. LDAB #$00
  155. STAB PTJ
  156.  
  157. ;The following segment is a 8 E cycle loop
  158. LDY #5 ; 10 * 0.5s * 0.5s
  159. LOOPOFF_OUT2 LDX #40625 ; 50.000us in 50ms (0.05s)
  160. LOOPOFF_IN2 nop ; 1 E cycle
  161. nop
  162. nop
  163. nop
  164. nop
  165. dbne x,LOOPOFF_IN ; 3 E cycles
  166. dbne y,LOOPOFF_OUT ; 3 E cycles
  167.  
  168.  
  169. XXXX LDY #7.5 ; 20 * 0.5s * 0.5s
  170. LOOPON_OUT3 LDX #40625 ; 50.000us in 50ms (0.05s)
  171. LOOPON_IN3 nop ; 1 E cycle
  172. nop
  173. nop
  174. nop
  175. nop
  176. dbne x,LOOPON_IN ; 3 E cycles
  177. dbne y,LOOPON_OUT ; 3 E cycles
  178.  
  179. ;This segment will turn OFF the EsduinoXtreme's onboard LED
  180. LDAB #$00
  181. STAB PTJ
  182.  
  183. ;The following segment is a 8 E cycle loop
  184. LDY #2.5 ; 10 * 0.5s * 0.5s
  185. LOOPOFF_OUT3 LDX #40625 ; 50.000us in 50ms (0.05s)
  186. LOOPOFF_IN3 nop ; 1 E cycle
  187. nop
  188. nop
  189. nop
  190. nop
  191. dbne x,LOOPOFF_IN ; 3 E cycles
  192. dbne y,LOOPOFF_OUT ; 3 E cycles
  193.  
  194. XXXXX LDY #10 ; 20 * 0.5s * 0.5s
  195. LOOPON_OUT4 LDX #40625 ; 50.000us in 50ms (0.05s)
  196. LOOPON_IN4 nop ; 1 E cycle
  197. nop
  198. nop
  199. nop
  200. nop
  201. dbne x,LOOPON_IN ; 3 E cycles
  202. dbne y,LOOPON_OUT ; 3 E cycles
  203.  
  204. ;This segment will turn OFF the EsduinoXtreme's onboard LED
  205. LDAB #$00
  206. STAB PTJ
  207.  
  208. ;The following segment is a 8 E cycle loop
  209. LDY #0 ; 10 * 0.5s * 0.5s
  210. LOOPOFF_OUT4 LDX #0 ; 50.000us in 50ms (0.05s)
  211. LOOPOFF_IN4 nop ; 1 E cycle
  212. nop
  213. nop
  214. nop
  215. nop
  216. dbne x,LOOPOFF_IN ; 3 E cycles
  217. dbne y,LOOPOFF_OUT ; 3 E cycles
  218.  
  219. BRA LOOP ; forever
  220.  
  221. ;**************************************************************
  222. ;* Interrupt Vectors *
  223. ;**************************************************************
  224. ORG $FFFE
  225. DC.W Entry ; Reset Vector
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement