 |
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-Gizmo’s
Z8MULATOR for Learning Microcontrollers thru Experiments -
Part III
In this third
installment and hopefully the last, we’ll consider more lessons from the
book Learning Micrcontrollers Thru Experiments.
Lesson 6 is almost
identical to lesson 5 except that this time, the relay connected to port
P00 is toggled on and off using S1 to S3 as interrupt switches.
Unfortunately, the Z8mulator uses port P0 for its operation; therefore, as
a substitute we’ll use ports P34, P35, and P36 instead of ports P00, P01,
and P02. This is illustrated in Figure 1 and
outlined below:
Z86E04/08
P07 P06 P05 P04 P03
P02 P01 P00
Z86MULATOR
P37 P36 P35 P34
P33 P32 P31 P30
As usual, the modified
or additional instructions are in red.
LESSON 6. SWITCHING
TM-2’s RELAY ON AND OFF
.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,#00000100b ; p0 are outputs
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
;or p0, #00000001b
; turn on relay (S3)
or p3,#00010000b
iret
IRQ1:
pop rp
;and p0, #11111110b
; turn off the relay (S2)
and p3,#11101111b
iret
IRQ2:
pop rp
;xor p0, #00000001b ; toggle the
relay (S1)
xor p3,#00010000b
iret
.end
Lesson 7 is very
interesting because it introduces the operation of the Z8’s internal
timers T0 and T1. The internal timers for the Z8CCP00ZEM and the Z8MULATOR
are almost the same. However, there are some minor differences.
The lessons in the book,
Learning Microcontrollers Thru Experiments, simulates the E04/E08
MCU. The Z8MULATOR, aside from its ability to simulate the E04/E08, is
essentially is a system in itself. It is a Z86E40-based MCU controller
board. Its internal timers allow more options. The default settings are,
however, the same. So, for now, we won’t modify the settings to allow its
timers to operate much like the E04/E08’s.
LESSON 7. USING TM-1’s
INTERNAL COUNTERS T0 & T1
.org 00h ; origin at 00h
.word 0
.word 0
.word 0
.word 0
.word IRQT0 ; Interrupt service routine for t0
.word IRQT1 ; Interrupt service routine for t1
.org 100ch
;
---------------------SET UP REGISTERS --------------------
di ; disable interrupts
ld spl,#80h ; initialize stack pointer
srp #10h ; stack register pointer
;ld p01m,#04h ; p0 are outputs
ld p2m,#00h ; p2 are outputs
ld p3m,#01h ; digital mode/p2's are push-pull
ld pre0,#01h ; modulo 64/continuous mode
clr t0 ; clear t0 register
; (not really needed)
ld pre1,#02h ; modulo 64/single pass/internal tin
clr t1 ; clear t1 register
ld imr,#30h ; 0011 0000 -- enables IRQ4 & IRQ5
clr irq ; clear impending interrupts
clr ipr ; clear interrupt priority register
;-----------------------INITIALIZE VARIABLES-----------------
ld r9,#19h ; initialize r9 to minimum
ld t0,#00h ; t0 should always be greater than t1
ld
tmr,#00000011b ; enable & load t0
ld t1,r9 ; load current value of r9--the on period
;
----------------------------MAIN LOOP----------------------
ei ; enable interrupts
start:
jr start ; run continuously
;--------------------------INT ROUTINES-----------------------
IRQT0:
pop rp
ld
p2, #0ffh ; t0 period
or tmr,#00001100b ; IRQ of t0 loads and sets t1
iret
IRQT1:
pop rp
ld p2, #00h ; t1 period
iret
.end
Lesson 8 is practically
identical to the previous lessons in terms of modifying the software. So
we’ll jump to Lesson 9 which illustrates the use of a lookup table using
the instruction ldc and ldci. Only the first part of the
part of the program in Lesson 9 is included here because the
modifications are identical.
LESSON 9. USING LOOKUP
TABLE FOR DISPLAYING DIGITS ON THE 7-SEGMENT DISPLAY
.org 00h ; origin at 00h
.word 0 ;
.word 0 ;
.word 0 ;
.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, #05b ; p0 are inputs
ld p2m, #00h ; p2 are outputs
ld p3m, #01h ; digital mode/p2’s output are push-pull
ld imr, #00h ; clear interrupt mask register
clr irq ; clear impending interrupt
clr ipr ; clear priority register
;clr r14
ld r14,#>table ; this loads the high byte
address of the table
res:
ld r15,#<table ; this loads the low byte
address of the table
start:
ldc r5, @rr14 ; contents of address specified by rr14 is
loaded
ld p2, r5 ; output to p2
call delay
incw rr14 ; address is incremented
;----------------test if the output is already “9”-------------
cp p2, #11010000b ; #2fh
jr ne, start
jr res
;---------------------------------delay -----------------------------
delay:
ld r8,#05h
loop3:
ld r6,#0ffh ; initialize count down timer
loop1:
ld r7, #0ffh ; initialize count down timer
loop2:
djnz r7, loop2 ; decrement and loop back until r1 is zero
djnz r6, loop1 ; decrement and loop back until r0 is zero
djnz r8,loop3
ret ; return to main loop
table:
.byte 77h, 24h, 5dh, 6dh, 2eh, 6bh, 7ah, 25h, 7fh, 2fh
.end
Notice that unlike the
previous lessons, more lines were changed in this exercise. The reason is
that the clr r14 instruction of the original program assumes that
the high byte of the table address is zero and the lower byte is equal to
the address of the ‘table’ itself. Since the whole program no longer
starts at 0ch, the low and high byte addresses of the table should be
specified. Also since the clock runs at a higher speed, additional delay
instructions were added; otherwise the display would be too fast to read.
The rest of the programs
in the rest of the lessons also follow the same rules so as to allow them
to be used with the Z8MULATOR module. So we’ll leave the rest of the
modifications up to you. Also, as a last note, the author wishes to
acknowledge Prof. Luis Sison of the UP Department of Electrical
Engineering for his contributions (Lessons 11 and 15) in the book
Learning Microcontrollers Thru Experiments.
Back to: Using e-Gizmo’s
Z8MULATOR for Learning Microcontrollers thru Experiments - Part I
Back to: Using e-Gizmo’s
Z8MULATOR for Learning Microcontrollers thru Experiments - Part II
|