fork download
  1. TTL "LCDTest (Lab 5)"
  2.  
  3. ******************************************************************
  4. * 1) HEADER block - overall info about the program
  5. * Project name: LCDTest
  6. * Author(s): Alex and Travis
  7. * Date: 4 Oct 2012
  8. * Description: Writes 'hi' to the screen
  9. ******************************************************************
  10.  
  11. ******************************************************************
  12. CODE EQU $2000 ;where our code can begin on EVB
  13. VPUTCHAR EQU $EE86 ;send character in B to output device
  14. CR EQU $0D ;Carriage Return
  15. PORTA EQU $0000
  16. tenths RMB 1 ;reserve a memory byte for tenth of seconds
  17. seconds RMB 1 ;reserve a memory byte for seconds
  18. tens RMB 1
  19. ******************************************************************
  20.  
  21.  
  22. ******************************************************************
  23. * 4) CODE section - actual program code *
  24. * This is all set-up. Output welcome message to the terminal, *
  25. * Print "Ultimate Watch" to the LCD, and check for the initial *
  26. * Button press *
  27. ******************************************************************
  28.  
  29. ORG CODE ;tell assembler where to begin object code
  30. ;main program body follows
  31. Main ldaa #LINIT ;set accumulator to "LINIT" value 0
  32. jsr LCD ;initialize LCD
  33. ldx #Title ;load x with the string
  34. ldaa #LWRSTR ;load A with the address of the write string subroutine
  35. jsr LCD ;execute LWRSTR
  36. ldx #Greet ;Point X at the greeting message
  37. jsr PUTS ;Output the greeting message
  38.  
  39. ldx #$C0 ;Point to first character, second line
  40. ldaa #LGOTO ;
  41. jsr LCD ;Point the cursor there
  42. ldab #0 ;
  43. ldaa #LWRDEC ;
  44. jsr LCD ;Output 0
  45. jsr LCD ;Output another 0
  46. ldab #':' ;Load B with a colon to be output
  47. ldaa #LWRCHR ;Output colon to the screen
  48. jsr LCD ;Do it
  49. ldab #0 ;
  50. ldaa #LWRDEC ;
  51. jsr LCD ;Output 1 more 0
  52. clr tens ;
  53. clr seconds ;Clear each variable
  54. clr tenths ;
  55.  
  56.  
  57. Loop ldaa PORTA ;Load Accumulator A with the values of Port A
  58. ANDA #%10000000 ;Mask with $80 to watch only PA7
  59. bne Loop ;If it is still high, loop.
  60. Debounc cmpb #20 ;Wait 20ms to ensure proper debouncing
  61. beq Clock ;When debounced, start the clock
  62. dbl ldx #0 ;1ms loop
  63. dex ;
  64. cpx #10000 ;
  65. beq dbl ;
  66. incb ;Increment debounce counter
  67. bra Debounc ;
  68.  
  69. ****************************************************************************
  70. * The code following this is all run after the button is pushed initially *
  71. * but before it starts the stopwatch part of the program *
  72. ****************************************************************************
  73.  
  74.  
  75. Clock ldaa PORTA ;Check status of button
  76. ANDA #%10000000 ;Is it still pushed?
  77. bne Clock ;If not, check again
  78.  
  79. ldx #$C0 ;
  80. ldaa #LGOTO ;
  81. jsr LCD ;Point to first character, second line
  82.  
  83. ldab tens ;load b with tens counter
  84. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  85. jsr LCD ;do it
  86.  
  87. ldab seconds ;load b with seconds counter
  88. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  89. jsr LCD ;do it
  90.  
  91. ldab #':' ;Load B with a colon to be output
  92. ldaa #LWRCHR ;Output colon to the screen
  93. jsr LCD ;Do it
  94.  
  95. ldab tenths ;load b with tenths counter
  96. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  97. jsr LCD ;do it
  98.  
  99.  
  100. ldd #100 ;If so, get ready to delay 100ms
  101. jsr DelayN ;Delay 100ms
  102. ldaa tenths ;Check the tenths counter
  103. cmpa #10 ;Is it ten?
  104. beq secondi ;If so, branch to seconds incrementer
  105.  
  106. tenthsi ldaa tenths ;Increment tenths counter
  107. inca ;
  108. staa tenths ;
  109. ldab tenths ;load b with tenths counter
  110. bra Clock ;Output and check button status
  111.  
  112. secondi clra ;
  113. staa tenths ;clear tenths counter
  114. ldaa seconds
  115. cmpa #10 ;Is seconds 10?
  116. beq tensi ;If so, branch to tens incrementer
  117. ldaa seconds ;
  118. inca ;Otherwise, increment seconds
  119. staa seconds ;
  120. bra Clock ;Output and check button status
  121.  
  122. tensi clra ;Clear seconds
  123. staa seconds ;
  124. ldaa tens ;
  125. inca ;Increment tens
  126. staa tens ;
  127. bra Clock ;Output and check button status
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. quit ldx #Exit
  135. jsr PUTS
  136. swi ;return to monitor on EVB
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. PUTS ldab 0,x ;get 1 char from string
  146. beq PSDONE ;done if terminating null
  147. jsr PUTCHAR ;output this char
  148. inx ;advance X to next char
  149. bra PUTS ;continue
  150. PSDONE rts ;done, return to caller
  151.  
  152. ; single character (in B) output routine
  153. PUTCHAR pshx ;save caller's X
  154. ldx VPUTCHAR ;fetch address of monitor rtn
  155. jsr 0,X ;call monitor rtn.
  156. pulx ;restore caller's X
  157. rts
  158.  
  159. DelayN bsr Delay1 ;go delay 1 millisecond
  160. dbne D,DelayN ;dec 'N' & continue till zero
  161. rts
  162.  
  163. * Delay1: delay 1 millisecond via software,
  164. * assumes F=24 MHz (and no interrupts)
  165. * all registers preserved for caller
  166.  
  167. Delay1 pshx ;2~ preserve registers used here
  168. ldx #5997 ;2~ iterations of Dloop for 1ms.
  169. Dloop dex ;1~ ]
  170. bne Dloop ;3~ ] 5997 * 4~ = 23988~
  171. pulx ;3~ recover used registers
  172. rts ;5~ 23988 + 12 = 24000~ = 1ms.
  173.  
  174. ; constant data definitions (FCB,FDB,FCC)...
  175. Title FCC "Ultimate Watch"
  176. FCB 0
  177. Greet FCC "Welcome to the stopwatch program. Press and hold the button to start the clock."
  178. FCB 0
  179. Exit FCC "Thanks, have a good day."
  180. FCB CR,CR,CR, 0
  181. ******************************************************************
  182.  
  183.  
  184.  
  185. #include 'LCDdriver.asm'
  186. ; tell assembler end of assembly source code
  187. END
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty