Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. ;
  2. ; Ex3.asm ---- Example program 3 for DRAGON12 board, Rev. E (c)2004, EVBplus.com
  3. ; Written by Wayne Chu
  4. ;
  5. ; Function: Displays the word 'HELP' on the 7-segment LED display,
  6. ; the 7-segment is multiplexed at 1ms per digit fresh rate,
  7. ; 250Hz fresh rate for 4 digits.
  8. ;
  9. #include reg9s12.h ; include register equates
  10. ;
  11.  
  12. ;
  13. DB6 equ $40
  14. DIG0: equ 8 ; PP3
  15. DIG1: equ 4 ; PP2
  16. DIG2: equ 2 ; PP1
  17. DIG3: equ 1 ; PP0
  18.  
  19. TB1MS: equ 24000 ; 1ms time base of 24,000 instruction cycles
  20. ; 24,000 x 1/24MHz = 1ms at 24 MHz bus speed
  21.  
  22. REGBLK: equ $0000
  23. STACK: equ $2000
  24. ;
  25. org $1000
  26. ;
  27.  
  28. select: rmb 1
  29. d1ms_flag: rmb 1
  30. disp_data: rmb 4
  31. disptn: rmb 4
  32.  
  33.  
  34.  
  35. org $1020
  36. offset: dw #0
  37. store: dw #0
  38.  
  39. ;
  40. ; Segment conversion table:
  41. ;
  42. ; Binary number: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  43. ; Converted to 7-segment char: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  44. ;
  45. ; Binary number: $10,$11,$12,$13,$14,$15,$16,$17
  46. ; Converted to 7-segment char: G H h J L n o o
  47. ;
  48. ; Binary number: $18,$19,$1A,$1B,$1C,$1D,$1E,$1F,$20
  49. ; Converted to 7-segment char: P r t U u y _ -- Blank
  50. ;
  51.  
  52. org $2000
  53. ;
  54. jmp start
  55. segm_ptrn: ; segment pattern
  56. fcb $3f,$06,$5b,$4f,$66,$6d,$7d,$07 ; 0-7
  57. ; 0, 1, 2, 3, 4, 5, 6, 7
  58. fcb $7f,$6f,$77,$7c,$39,$5e,$79,$71 ; 8-$0f
  59. ; 8, 9, A, b, C, d, E, F
  60. fcb $3d,$76,$74,$1e,$38,$54,$63,$5c ; 10-17
  61. ; G, H, h, J L n o o
  62. fcb $73,$50,$78,$3e,$1c,$6e,$08,$40 ; 18-1f
  63. ; P, r, t, U, u Y - -
  64. fcb $00,$01,$48,$41,$09,$49 ; 20-23
  65. ; blk, -, =, =, =, =
  66. ;
  67. seven_segment:
  68. pshx
  69. pshb
  70. ldx #segm_ptrn
  71. psha
  72. anda #$3f
  73. tab
  74. abx
  75. ldaa 0,x ; get segment
  76. pulb
  77. andb #$80 ; add DP
  78. aba
  79. pulb
  80. pulx
  81. rts
  82.  
  83. start:
  84. lds #STACK
  85.  
  86. ldx #REGBLK
  87. ldaa #$ff ; turn off 7-segment display
  88. staa ptp,x ; portp = 11111111
  89.  
  90. staa ptj,x ; make PJ1 high to disable LEDs
  91. staa ddrb,x ; portb = output
  92. staa ddrp,x ; portp = output
  93. staa ddrj,x ; make port J an output port
  94.  
  95. ldaa #$80
  96. staa tscr,x ; enable timer
  97. ldaa #DB6
  98. staa tios,x ; select t6 as an output compare
  99. staa tmsk1,x
  100.  
  101. cli
  102.  
  103.  
  104.  
  105. ldaa #$00
  106. staa ddrh,x ;porth = input
  107.  
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Do math in this section
  110.  
  111.  
  112.  
  113. ldx #store ; load x with the address of "store"
  114. ldy #9 ; load index register with the number 4
  115. ;we use this as our counter for our loop
  116. ldaa 0,x ;load accumlator A with the contents of
  117. ;the memory location at x
  118. ldab #1 ;ldab with the number 1
  119. loop
  120. aba
  121. inx
  122. inx
  123. staa 0,x
  124. ldab -2,x
  125. dbne y loop ; decrement y on bit not equal
  126. end
  127.  
  128.  
  129.  
  130. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;End math
  131.  
  132.  
  133. begin:
  134.  
  135. ;;;;;
  136. ;Algorithim for moving data into the right memory locations go here
  137.  
  138. ldx store
  139. ldab offset
  140. abx
  141.  
  142.  
  143. ldaa 0,x
  144. asla
  145. asla
  146. asla
  147. asla
  148. staa disp_data
  149.  
  150. ldaa 1,x
  151. anda $0F
  152. staa disp_data+1
  153.  
  154. ldaa 0,x
  155. asla
  156. asla
  157. asla
  158. asla
  159. staa disp_data+2
  160.  
  161. ldaa 1,x
  162. anda $0F
  163. staa disp_data+3
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. ;disptn drives digit 1
  171. ;disptn+1 drives digit 2
  172. ;disptn+2 drives digit 3
  173. ;dispth+3 drives digit 4
  174.  
  175. ;Once your bytes are in these locations
  176. ;the program jumps to the right subroutines and displays the data.
  177. ;you will probably have to manipulate the bits in the registers before
  178. ;storing them to these locations.
  179.  
  180.  
  181.  
  182.  
  183.  
  184. ldx #disp_data
  185. jsr move
  186. jsr sel_digit
  187. ;
  188. wait: tst d1ms_flag
  189. beq wait
  190. clr d1ms_flag
  191.  
  192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193. ;Button pressing and checking stuff goes here;
  194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  195.  
  196.  
  197. jmp begin
  198.  
  199.  
  200.  
  201. ;
  202. ; this routine moves 4 bytes of data into disptn (display pattern)
  203. ; and converts the pattern to 7-segment code.
  204. ; @ enter, x points the source address
  205. ;
  206. move: ldy #disptn
  207. mnext: ldaa 0,x
  208. jsr seven_segment ; convert Accu A to segment pattern, bit 7= DP
  209. staa 0,y
  210. inx
  211. iny
  212. cpy #disptn+4
  213. bne mnext
  214. rts
  215. ;
  216. ; multiplexing display one digit at a time
  217. ;
  218. sel_digit:
  219. ldx #REGBLK
  220. inc select
  221. ldab select
  222. andb #3
  223. tstb
  224. beq digit3
  225. decb
  226. beq digit2
  227. decb
  228. beq digit1
  229. ;
  230. digit0:
  231. ldaa disptn+3
  232. staa portb,x
  233. bclr ptp,x,DIG0 ; turn on digit 0
  234. bset ptp,x,DIG1 ; turn off all other digits
  235. bset ptp,x,DIG2
  236. bset ptp,x,DIG3
  237. rts
  238. digit1:
  239. ldaa disptn+2
  240. staa portb,x
  241.  
  242. bset ptp,x,DIG0
  243. bclr ptp,x,DIG1 ; turn on digit 1
  244. bset ptp,x,DIG2 ; turn off all other digits
  245. bset ptp,x,DIG3
  246. rts
  247. digit2:
  248. ldaa disptn+1
  249. staa portb,x
  250.  
  251. bset ptp,x,DIG0
  252. bset ptp,x,DIG1
  253. bclr ptp,x,DIG2 ; turn on digit 2
  254. bset ptp,x,DIG3 ; turn off all other digits
  255. rts
  256. digit3:
  257. ldaa disptn
  258. staa portb,x
  259.  
  260. bset ptp,x,DIG0
  261. bset ptp,x,DIG1
  262. bset ptp,x,DIG2
  263. bclr ptp,x,DIG3 ; turn on digit 3
  264. rts
  265. timer6:
  266. ldx #REGBLK
  267. ; in an interrupt servicing routine the x register will be saved automatically
  268. ; the rti instruction will pop the x register off stack.
  269.  
  270. inc d1ms_flag
  271. ldd #TB1MS ; reload the count for 1 ms time base
  272. addd tc6,x
  273. std tc6,x
  274. ldaa #DB6
  275. staa tflg1,x ; clear flag
  276. rti
  277.  
  278. org $3E62
  279. fdb timer6
  280.  
  281. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement