 |
Benjo U. Tirol, author
and former editor in chief of the Electronics Enthusiasts magazine,
send in this series of article detailing how to set the z8mulator to work on the
training experiments discussed in his very popular book Learning
Microcontrollers thru Experiments (published by Alexan Foundation,
available on Alexan outlets and the National Bookstore). Our profound thanks for his
generous and invaluable support! - e-Gizmo Mechatronix Central. |
Using e-Gizmos
Z8MULATOR for Learning Microcontrollers thru Experiments -
Part II
The next three lessons
in the book Learning Microcontrollers thru Experiments
can be easily
modified to work with the Z8MULATOR simply by disabling and adding some
instructions. These are summarized below:
·
Disable
register instruction that modify register p01.
·
Start your
program at address 100ch as recommended.
·
Begin the
interrupt service routines with the POP RP instruction to retrieve the
register pointer.
Here also some important
things to watch out for:
o
Speed
difference - The Z8mulators crystal is 15.433MHz, which is almost twice
as fast as the Z86CCP00ZEMs. Therefore, you should expect everything to
run much faster.
o
In case
your circuit appears to latch up, particularly when using switches,
connect a small ceramic capacitor across the p31 to p33 inputs and ground
(if you are using TM-123).
Lesson 3 illustrates the
easiest way of using switches to control the output ports. Lesson 4 shows
two possible ways of modifying the switch response to safeguard against
switch bounce or accidental switching. Lesson 5 describes one method of
using the switches as interrupt sources. The modified instructions are in
red.
LESSON 3. USING SWITCHES
TO CONTROL I/O PORTS
.org 00h
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.org 100ch
di ; interrupts are disabled
ld spl, #80h ; stack pointer is initialized to 80h
;ld p01m, #04h ; port 0 as output
ld p2m, #00h ; port 2 as output
ld p3m, #01h ; set up for digital inputs and port 2
; with
push-pull outputs
srp #10h ; stack register pointer for r0 to r15 begins at 10h
;
MAIN LOOP
ld p2, #77h ; light 0 to indicate power on
start:
tm p3, #00000010b ; test if S1 (p31) is high
jr nz, skip ; jump to skip if high
ld p2, #24h ; light 7-segment
jr start
skip:
ld p2, #77h ; keep display 0
jr start
.end
LESSON
4a. MODIFYING THE SWITCH RESPONSE ON THE TM-2
.org 00h
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.org 100ch
di ; interrupts are disabled
ld spl, #80h ; stack pointer is initialized to 80h
;ld p01m, #04h ; port 0 as output
ld p2m, #00h ; port 2 as output
ld p3m, #01h ; set up for digital inputs
; and
port 2 = push-pull outputs
srp #10h ; stack register pointer for r0 to r15 begins at 10h
;
MAIN LOOP
ld p2, #77h ; light 0 to indicate power on
start:
tm p3, #00000010b ; test if S1 (p31) is high
jr nz, skip ; jump to skip if high
lop:
tm p3, #00000010b ; test if S1 (p31) is still down
jr z, lop ; loop until S1 is released
ld p2, #24h ; light 7-segment
call delay ; show 1 for a few seconds
jr start
skip:
ld p2, #77h ; keep display 0
jr start
;
----------------------------- DELAY ROUTINE -----------------------------
delay:
ld r0, #05h ; initialize count down timer
loop1:
ld r1, #00h ; initialize count down timer
loop2:
ld r2, #00h ; initialize count down timer
loop3:
djnz r2, loop3 ; decrement and loop back until r2 is zero
djnz r1, loop2 ; decrement and loop back until r1 is zero
djnz r0, loop1 ; decrement and loop back until r0 is zero
ret ; return to main loop
.end
LESSON
4b. MODIFYING THE SWITCH RESPONSE ON THE TM-2
.org
00h
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.org 100ch
di ; interrupts are disabled
ld spl, #80h ; stack pointer is initialized to 80h
;ld p01m, #04h ; port 0 as output
ld p2m, #00h ; port 2 as output
ld p3m, #01h ; set up for digital inputs and
; port 2
= push-pull outputs
srp #10h ; stack register pointer for r0 to r15 begins at 10h
;
MAIN LOOP
ld p2, #77h ; light 0 to indicate power on
start:
tm p3, #00000010b ; test if S1 (p31) is high
jr nz, skip ; jump to skip if high
call delay2 ; delay response
tm p3, #00000010b ; test if S1 (p31) is high
jr nz, skip ; jump to skip if high
;lop: tm p3, #00000010b ; test if S1 (p31) is still down
; jr z, lop ; loop until S1 is released
ld p2, #24h ; light 7-segment
call delay ; show 1 for a few seconds
jr start
skip:
ld p2, #77h ; keep display 0
jr start
;
----------------------------- DELAY ROUTINES
-----------------------------
delay:
ld r0, #05h ; initialize count down timer
loop1:
ld r1, #00h ; initialize count down timer
loop2:
ld r2, #00h ; initialize count down timer
loop3:
djnz r2, loop3 ; decrement and loop back until r2 is zero
djnz r1, loop2 ; decrement and loop back until r1 is zero
djnz r0, loop1 ; decrement and loop back until r0 is zero
delay2:
ld r0, #00h ; (try changing the
value)
loop1b:
ld r1, #00h ; initialize count
down timer
loop2b:
djnz r1, loop2b ; decrement and loop
back until r1 is zero
djnz r0, loop1b ; decrement and loop back until r0 is zero
ret ; return to main loop
.end
LESSON 5. MODIFYING THE
SWITCH RESPONSE ON THE TM-2
.org 00h ; origin at 00h
.word IRQ0 ; Falling Edge S3
.word IRQ1 ; Falling Edge S2
.word IRQ2 ; Falling Edge S1
.word 0 ;
.word 0 ;
.word 0 ;
.org 100ch ; software begins at 100ch
;
-----------------Initialize ports and other functions ------------
di ; disable interrupts
ld spl, #80h ; set stack pointer
srp #10h ; standard register address
;ld p01m,#00000101b ; p0 are inputs
ld p2m, #00h ; p2 are outputs
ld p3m, #01h ; digital mode/p2's output are push-pull
ld imr, #00000111b ; set interrupt mask register for IRQ0 to IRQ2
clr irq ; clear impending interrupt
clr ipr ; no priorities
;
------------------------------Main Routine ------------------------
ld p2, #80h ; light up 7-segment dot to indicate power on
ei
start:
jr start ; wait for interrupts
;
------------------------------- Interrupt Routines --------------------
IRQ0:
pop rp
ld p2, #77h ; load digit 0
iret
IRQ1:
pop rp
ld p2, #24h ; load digit 1
iret
IRQ2:
pop rp
ld p2, #5dh ; load digit 2
iret
.end
Back to: Using e-Gizmos
Z8MULATOR for Learning Microcontrollers thru Experiments - Part I Go to:
Using e-Gizmos
Z8MULATOR for Learning Microcontrollers thru Experiments - Part III
|