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
191
192
193
194
195
196
197
198
199
200
201
202
|
**************************************************************************
*
* Title: LED Light Blinking
*
* Objective: CMPEN 472 Homework 2 in-class-room demonstration
* program
*
* Revision: V1.0
*
* Date: Jan. 29, 2025
*
* Programmer: Jacob McDonnell
*
* Company: The Pennsylvania State University
* Department of Computer Science and Engineering
*
* Algorithm: Simple Parallel I/O use and time delay-loop demo
*
* Register Use: A: LED Light on/off state and Switch 1 on/off state
* X,Y: Delay and loop counters
*
* Memory Use: RAM Locations from $3000 for data,
* RAM Locations from $3100 for program
*
* Input: Parameters hard-coded in the program - PORTB
* Switch 1 at PORTB bit 0
* Switch 2 at PORTB bit 1
* Switch 3 at PORTB bit 2
* Switch 4 at PORTB bit 3
*
* Output: LED 1 at PORTB bit 4
* LED 2 at PORTB bit 5
* LED 3 at PORTB bit 6
* LED 4 at PORTB bit 7
*
* Observation: This program that blinks LEDs and blinking period can
* be changed with the delay loop counter value. When switch 1
* is not pressed, LEDs 1 and 4 will blink alternately for 1
* second each. When switch 1 is pressed LEDs 1, 2, 3, & 4 will
* all turn on at the same time for 1 second and turn off at the
* same time for 1 second.
*
* Note: All Homework programs MUST have comments similar
* to this Homework 2 program. So, please use those
* comment format for all your subsequent CMPEN472
* Homework programs.
*
* Adding more explanations and comments help you and
* others to understnad your program later.
*
* Comments: This program is developed and simulated using CodeWarrior
* development software and targeted for Axion
* Manufacturing's CSM-12C128 board running at 24MHz.
*
**************************************************************************
* Parameter Declearation Section
*
* Export Symbols
xdef pgstart ; export 'pgstart' symbol
absentry pgstart ; for assembly entry point
* Symbols and Macros
PORTA equ $0000 ; i/o port A addresses
DDRA equ $0002 ; data direction register for PORTA
PORTB equ $0001 ; i/o port B addresses
DDRB equ $0003 ; data direction register for PORTB
**************************************************************************
* Data Section: address used [ $3000 to $30FF ] RAM Memory
*
org $3000 ; Reserved RAM memory starting address
; for Data for CMPEN 472 class
Counter1 dc.w $0100 ; X register count number for time Delay
; inner loop for msec
Counter2 dc.w $00BF ; Y register count number for time delay
; output loop for sec
*
**************************************************************************
* Program Section: address used [ $3100 to $3FFF ] RAM Memory
*
org $3100 ; Program start address, in RAM
pgstart lds #$3100 ; initialize the stack pointer
ldaa #%11111111 ; LED 1, 2, 3, 4 at PORTB bit 4, 5, 6, 7 FOR CSM-12C128 board
staa DDRB ; set PORTB bit 4, 5, 6, 7 as Output
ldaa #%00000000
staa PORTB ; Turn off LED 1, 2, 3, 4 (all bits in PORTB, for simulation
mainLoop
ldaa PORTB
anda #%00000001 ; Read switch 1 at PORTB bit 0
bne sw1pushed ; check to see if it is pushed
sw1notpsh jsr alternate ; Jump to the alternate subroutine to alternate LED 1 and 4
bra mainLoop ; loop back to the beginning to check the switch
sw1pushed jsr allBlink ; Jump to the allBlink subroutine to blink all lights
bra mainLoop ; loop back to the beginning to check the switch
**************************************************************************
* Subroutine Section: address used [ $3100 to $3FFF ] RAM Memory
*
;*************************************************************************
; delay1sec subroutine
;
; This subroutine will delay for 1 second
;
; Input: a 16 bit count number in 'Counter2'
; Output: time delay of 1 second, cpu cycles wasted
; Registers in use: Y register as counter
; Memory locations in use: a 16bit input number at 'Counter2'
;
; Comments: This subroutine requires delayMS subroutine
;
delay1sec
pshy ; save Y to the stack
ldy Counter2 ; long delay by the value of Counter2
dly1Loop jsr delayMS ; total time delay = Y * delayMS
dey
bne dly1Loop
puly ; restore y from the stack
rts ; return
;*************************************************************************
; delayMS subroutine
;
; This subroutine causes a few msec. Delay
;
; Input: a 16bit count number in 'Counter1'
; Output: time delay, cpu cycle wasted
; Registers in use: X register, as counter
; Memory locations in use: a 16bit input number at 'Counter1'
;
; Comments: one can add more NOP instructions to lengthen the delay time.
;
delayMS
pshx ; save X to the stack
ldx Counter1 ; short Delay
dlyMSLoop nop ; total time delay = X * NOP
dex
bne dlyMSLoop
pulx ; restore X
rts ; return
;*************************************************************************
; alternate subroutine
;
; This subroutine will alternately blink LEDs 1 anf 4 for 1 second each.
;
; Input: No input all values are hardcoded
; Output: LEDs 1 and 4 blinking alternately
; Registers in use: No registers are used
; Memory locations in use: A one byte memory location associated with PORTB ($0001)
;
; Comments: This subroutine requires delay1sec subroutine.
;
alternate
bset PORTB,%10000000 ; Turn ON LED 4 at PORTB bit 7
bclr PORTB,%00010000 ; Turn off LED 1 at PORTB bit 4
jsr delay1sec ; Wait for 1 second
bclr PORTB,%10000000 ; Turn off LED 4 at PORTB bit 7
bset PORTB,%00010000 ; Turn on LED 1 at PORTB bit 4
jsr delay1sec ; Wait for 1 second
rts ; Return to the caller
;*************************************************************************
; allBlink subroutine
;
; This subroutine will blink LEDs 1, 2, 3, & 4 on for 1 second and off for
; 1 second all at the same time.
;
; Input: No input all values are hardcoded
; Output: LEDs 1, 2, 3, & 4 blinking on and off at the
; same time for 1 second
; Registers in use: No registers are used
; Memory locations in use: A one byte memory location associated with PORTB ($0001)
;
; Comments: This subroutine requires delay1sec subroutine.
;
allBlink
bset PORTB,%11110000 ; Turn ON all 4 LEDs
jsr delay1sec ; Wait for 1 second
bclr PORTB,%11110000 ; Turn off all 4 LEDs
jsr delay1sec ; Wait for 1 second
rts ; Return to the caller
*
* Add any subroutines here
*
end ; last line of the file
|