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