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 EQU $3000 ;reserve a memory byte for tenth of seconds
  17. seconds EQU $3001 ;reserve a memory byte for seconds
  18. tens EQU $3002
  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 #256+0 ;Point to second line (256) + first column (0)
  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 movb PORTA, $3100 ;Load Accumulator A with the values of Port A
  58. ldaa $3100
  59. ANDA #%10000000 ;Mask with $80 to watch only PA7
  60. bne Loop ;If it is still high, loop.
  61. Debounc cmpb #20 ;Wait 20ms to ensure proper debouncing
  62. beq Clock ;When debounced, start the clock
  63. dbl ldx #0 ;1ms loop
  64. dex ;
  65. cpx #10000 ;
  66. beq dbl ;
  67. incb ;Increment debounce counter
  68. bra Debounc ;
  69.  
  70. ****************************************************************************
  71. * The code following this is all run after the button is pushed initially *
  72. * but before it starts the stopwatch part of the program *
  73. ****************************************************************************
  74.  
  75.  
  76. Clock movb PORTA, $3100 ;Load Accumulator A with the values of Port A
  77. ldaa $3100
  78. ANDA #%10000000 ;Is it still pushed?
  79. bne Clock ;If not, check again
  80.  
  81.  
  82.  
  83. ldx #256+0 ;Point to second line (256) + first column (0)
  84. ldaa #LGOTO ;
  85. jsr LCD ;Point to first character, second line
  86.  
  87. ldab tens ;load b with tens counter
  88. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  89. jsr LCD ;do it
  90.  
  91. ldab seconds ;load b with seconds counter
  92. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  93. jsr LCD ;do it
  94.  
  95. ldab #':' ;Load B with a colon to be output
  96. ldaa #LWRCHR ;Output colon to the screen
  97. jsr LCD ;Do it
  98.  
  99. ldab tenths ;load b with tenths counter
  100. ldaa #LWRDEC ;get ready to print tenths to fourth character, second row
  101. jsr LCD ;do it
  102.  
  103.  
  104. ldd #99 ;If so, get ready to delay 100ms
  105. jsr DelayN ;Delay 100ms
  106. ldaa tenths ;Check the tenths counter
  107. cmpa #9 ;Is it ten?
  108. beq secondi ;If so, branch to seconds incrementer
  109.  
  110. tenthsi ldaa tenths ;Increment tenths counter
  111. inca ;
  112. staa tenths ;
  113. bra Clock ;Output and check button status
  114.  
  115. secondi clra
  116. staa tenths ;clear tenths counter
  117. ldaa seconds
  118. cmpa #9 ;Is seconds 10?
  119. beq tensi ;If so, branch to tens incrementer
  120. ldaa seconds ;
  121. inca ;Otherwise, increment seconds
  122. staa seconds ;
  123. bra Clock ;Output and check button status
  124.  
  125. tensi clra ;Clear seconds
  126. staa seconds ;
  127. ldaa tens ;
  128. inca ;Increment tens
  129. staa tens ;
  130. bra Clock ;Output and check button status
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. quit ldx #Exit
  138. jsr PUTS
  139. swi ;return to monitor on EVB
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. PUTS ldab 0,x ;get 1 char from string
  149. beq PSDONE ;done if terminating null
  150. jsr PUTCHAR ;output this char
  151. inx ;advance X to next char
  152. bra PUTS ;continue
  153. PSDONE rts ;done, return to caller
  154.  
  155. ; single character (in B) output routine
  156. PUTCHAR pshx ;save caller's X
  157. ldx VPUTCHAR ;fetch address of monitor rtn
  158. jsr 0,X ;call monitor rtn.
  159. pulx ;restore caller's X
  160. rts
  161.  
  162. DelayN bsr Delay1 ;go delay 1 millisecond
  163. dbne D,DelayN ;dec 'N' & continue till zero
  164. rts
  165.  
  166. * Delay1: delay 1 millisecond via software,
  167. * assumes F=24 MHz (and no interrupts)
  168. * all registers preserved for caller
  169.  
  170. Delay1 pshx ;2~ preserve registers used here
  171. ldx #5997 ;2~ iterations of Dloop for 1ms.
  172. Dloop dex ;1~ ]
  173. bne Dloop ;3~ ] 5997 * 4~ = 23988~
  174. pulx ;3~ recover used registers
  175. rts ;5~ 23988 + 12 = 24000~ = 1ms.
  176.  
  177. ; constant data definitions (FCB,FDB,FCC)...
  178. Title FCC "Ultimate Watch"
  179. FCB 0
  180. Greet FCC "Welcome to the stopwatch program. Press and hold the button to start the clock."
  181. FCB 0
  182. Exit FCC "Thanks, have a good day."
  183. FCB CR,CR,CR, 0
  184. ******************************************************************
  185.  
  186.  
  187.  
  188. #include 'LCDdriver.asm'
  189. ; tell assembler end of assembly source code
  190. END
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty