Guest User

Untitled

a guest
Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. ; University of Illinois at Chicago, Dept. of Electrical and Computer Engineering
  2. ; ECE 367 -Microprocessor-Based Design
  3. ; Three Bit Counter
  4. ; Version 2, Aug 27, 2011
  5. ; By Robert A. Becker
  6.  
  7. ; PAY ATTENTION TO THE ALIGNMENT BELOW
  8. ; Labels start in the first column (left most column = colunm 1)
  9. ; OP CODES are at column 9
  10. ; COMMENTS follow a ";" symbol
  11. ; Blank lines are allowed (Makes the code more readable)
  12.  
  13. ; Define symbolic constants
  14. PortT EQU $240 ;Define Register Locations
  15. DDRT EQU $242
  16. INITRG EQU $11
  17. INITRM EQU $10
  18. CLKSEL EQU $39
  19. PLLCTL EQU $3A
  20. CRGFLG EQU $37
  21. SYNR EQU $34
  22. REFDV EQU $35
  23. COPCTL EQU $3C
  24. TSCR1 EQU $46
  25. TSCR2 EQU $4D
  26. TIOS EQU $40
  27. TCNT EQU $44
  28. PortM EQU $250
  29. DDRM EQU $252
  30. SAVE EQU $60 ;created a variable to save my increment register because delay sub routine changes it.
  31. TENSAVE EQU $5020
  32. TC0 EQU $50
  33. TFLG1 EQU $4E
  34. ;
  35. ; The ORG statment below would normally be followed by variable definitions
  36. ; There are no variables needed for this project.
  37. ; THIS IS THE BEGINNING SETUP CODE
  38. ;
  39. ORG $3800 ; Beginning of RAM for Variables
  40. ;
  41. ; The main code begins here. Note the START Label
  42. ;
  43. ORG $4000 ; Beginning of Flash EEPROM
  44. START LDS #$3FCE ; Top of the Stack
  45. SEI ; Turn Off Interrupts
  46. MOVB #$00, INITRG ; I/O and Control Registers Start at $0000
  47. MOVB #$39, INITRM ; RAM ends at $3FFF
  48. ;
  49. ; We Need To Set Up The PLL So that the E-Clock = 24MHz
  50. ;
  51. BCLR CLKSEL,$80 ; disengage PLL from system
  52. BSET PLLCTL,$40 ; turn on PLL
  53. MOVB #$2,SYNR ; set PLL multiplier
  54. MOVB #$0,REFDV ; set PLL divider
  55. NOP ; No OP
  56. NOP ; NO OP
  57. PLP BRCLR CRGFLG,$08,PLP ; while (!(crg.crgflg.bit.lock==1))
  58. BSET CLKSEL,$80 ; engage PLL
  59. ;
  60. ;
  61. ;
  62. CLI ; Turn ON Interrupts
  63. ;
  64. ; End of setup code. You will always need the above setup code for every experiment
  65. ;
  66. ;
  67. ;
  68. ;
  69. ;
  70. ;
  71. ;
  72. ;
  73. ;
  74. ;
  75. ;
  76. ;
  77. ;START CODING HERE____________________________________________________
  78.  
  79. LDAA #$FF ; Make PortT Outbound
  80. STAA DDRT
  81. LDAA #$FB ; make pm2 inbound but rest outbound
  82. STAA DDRM
  83.  
  84. LDAA #$3f
  85. STAA PortT
  86. LDAA #$03
  87. STAA PortM
  88. LDAA #$00
  89. STAA TENSAVE
  90. STAA PortM
  91.  
  92.  
  93. THIS:
  94.  
  95. BRSET SAVE, #$0A, TEN ; Branch to 'TEN' if save variable is incremented all the way to $10
  96. LDAB #$00
  97.  
  98. HERE: BRSET PortM, #$04, HERE ; Branch if PM2 is SET (1) to HERE
  99. ;
  100.  
  101. ; JSR DELAY
  102.  
  103. JSR DISPLAY
  104. BRA HERE
  105. BRA *
  106. ; LDAB #$00 ;initialize acc B to 0 to begin count in table
  107. ; JSR DISPLAY ;jump to sub routine 'display'
  108. ;THIS: ;loop branch statement takes you here
  109. JSR DELAY
  110.  
  111. ;
  112. ; We use some built-in timer functions to create an accurate delay
  113. ;
  114. ;
  115. ;
  116. ;
  117. ;
  118. ;
  119. ;
  120. ;
  121. ;
  122. ;
  123. ;
  124. ;------------------------------------------------
  125. ;GIVEN DELAY SUBROUTINE
  126.  
  127.  
  128. DELAY PSHA ; Save accumulator A on the stack
  129. LDY #03 ; We will repeat this subroutine 3 times
  130. MOVB #$90,TSCR1 ; enable TCNT & fast flags clear
  131. MOVB #$06,TSCR2 ; configure prescale factor to 64
  132. MOVB #$01,TIOS ; enable OC0
  133. LDD TCNT ; Get current TCNT value
  134. AGAIN ADDD #37500 ; start an output compare operation
  135. STD TC0 ; with 100 ms time delay
  136. WAIT BRCLR TFLG1,$01,WAIT ; Wait for TCNT to catch up
  137. LDD TC0 ; Get the value in TC0
  138. DBNE Y,AGAIN ; 5 X 100ms = 1 sec
  139. PULA ; Pull A
  140. RTS ;
  141.  
  142. ;___________________________________________________________
  143. ;
  144. ;
  145. ;
  146. ;
  147. ;
  148. ;
  149. ;
  150. ;
  151. ;
  152. ;
  153. ;
  154. ;
  155. ;
  156. ;_____________________________________________________________
  157. ;displaylab3
  158. DISPLAY:
  159.  
  160. LDAA #$00
  161. STAA PortM, Y
  162.  
  163. LDAB SAVE
  164.  
  165. LDX #TABLE ;load table into x
  166. LDAA B,X ;load b'th element of table into a
  167. STAA PortT,Y ;display a in port t
  168. INCB ;increment b for next run through loop
  169. LDAA #$01 ;load bth element of table into a
  170. STAA PortM,Y ;display a in port m
  171. ;
  172. STAB SAVE ;save b in variable save before delay
  173. ;
  174. JSR DELAY ;Keep display on for a second with current uin digit
  175. JSR DELAY
  176.  
  177. LDAB SAVE ;transfer variable back into incrementing accumulator
  178.  
  179.  
  180. BRSET SAVE, #$0A, THIS ; Branch to 'this' if save variable is incremented all the way to $10,
  181. RTS
  182. ;__________________________________________________________________________
  183.  
  184.  
  185. TEN
  186. LDAA #$00
  187. STAA PortM, Y
  188. LDAB TENSAVE
  189.  
  190. LDX #TABLE
  191. LDAA B, X
  192. STAA PortT, Y
  193. INCB
  194. STAB TENSAVE
  195. LDAA #$02
  196. STAA PortM, Y
  197.  
  198. LDAB #$00
  199. STAB SAVE
  200.  
  201. RTS
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209. ; End of counter code
  210.  
  211. ;DISPLAY
  212. ;DISPLAY:
  213. ; LDX #TABLE ;load table into x
  214. ; LDAA B,X ;load b'th element of table into a
  215. ; STAA PortT,Y ;display a in port t
  216. ; INCB ;increment b for next run through loop
  217. ; LDAA B,X ;load bth element of table into a
  218. ; STAA PortM,Y ;display a in port m
  219. ;
  220. ; STAB SAVE ;save b in variable save before delay
  221. ;
  222. ; JSR DELAY ;Keep display on for a second with current uin digit
  223. ; JSR DELAY
  224.  
  225. ; LDAB SAVE ;transfer variable back into incrementing accumulator
  226. ;
  227. ; LDAA #$00
  228. ; STAA PortT,Y ;turn display off at the end of the program
  229. ; STAA PortM,Y ;turn port m display off for break between uin units
  230. ;
  231. ;STAB SAVE
  232.  
  233. ;JSR DELAY ;Keep off for half second
  234.  
  235. ;LDAB SAVE
  236.  
  237. ; INCB; ;increment b again to get to next table entry
  238.  
  239. ; STAB SAVE
  240.  
  241. ; BRSET SAVE, #$12, THIS ; Branch to 'this' if save variable is incremented all the way to $12,
  242.  
  243. ; JSR DISPLAY ;back to the top of the loop
  244. ;table for uin
  245. ORG $5000 ;memory location of table
  246. TABLE: DC.B $06, $5b, $4f, $66, $6d, $7D, $07, $7F, $67, $3f
  247. ;define table
  248.  
  249. ; Define Power-On Reset Interrupt Vector
  250.  
  251. ; AGAIN - OP CODES are at column 9
  252.  
  253. ORG $FFFE ; $FFFE, $FFFF = Power-On Reset Int. Vector Location
  254. FDB START ; Specify instruction to execute on power up
  255.  
  256. ; End of Interrupt code
  257.  
  258. END ; (Optional) End of source code
Add Comment
Please, Sign In to add comment