Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;################################################################################
- ;# #
- ;# Exercise: #
- ;# Microcontroller Laboratory Exercise with ZILOG DEVELOPER STUDIO 3.68 and #
- ;# Z8 CCP Emulator (Z86CCP01ZEM) #
- ;# #
- ;# Task: #
- ;# Clock-Program #
- ;# The Program uses Timer1 as a simple clock and show the hundredths, seconds #
- ;# and hours on Port 0, Port 1 and Port 2 as binary number. #
- ;# The timer is set to continues mode (bit D0=1) and the clock source is the #
- ;# internal source clock. Each time when the Timer/Counter and the prescaler #
- ;# both reach the end end-of-count (of every 1/100 second- hundredth), #
- ;# an interrupt request IRQ5 is generated. #
- ;################################################################################
- VECTOR IRQ0 = IRQ_DUMMY ;The Interrupt vectors
- VECTOR IRQ1 = IRQ_DUMMY
- VECTOR IRQ2 = IRQ_DUMMY
- VECTOR IRQ3 = IRQ_DUMMY
- VECTOR IRQ4 = T0_IRQ ;neuer IRQ
- VECTOR IRQ5 = T1_IRQ ;ISR for Timer-Interrupt begins by
- init:
- HOUR: .equ r12
- MINUTE: .equ r13
- SECOND: .equ r14
- HUNDREDTH: .equ r15
- STACK: .equ %EF ;Work. Register Group 1, Work. Register F
- ld SPL,#STACK ;load the Stack Pointer Low Byte (SPL = control register at address FF)
- ld RP,#0Fh ;Select ERB Bank F, working register group 0 for access
- ld 0Bh,#00010011B ;CLOCK MODE SWITCHING, select
- ;D0 = 1 divide by 16, D1 = SCLK/TCLK = XTAL
- nop ;When changing either clock mode selection bits D1 or D0 in the Stop Mode Recovery register(address 0Bh = SMR),
- nop ;it is recommended that two No Operation instructions (NOP’s) immediately follow that change
- ld RP,#00h ;Select the Standard Register File for access (ERB Bank 0, working register group 0)
- clr p2m ;Defines port 2 pins to be outputs
- ld p3m,#00000001B ;Set Port2 as Push-Pull
- di ;Disable all Interrupts
- clr irq ;Clear all interrupts
- ld imr,#10100000b ;Enable Timer1_IRQ
- ld p01m,#00000100B ;Init Port 1 mode as outputs (that is P00-03 is output, internal stack-D2 set to 1,P10-17 is output, P04-07 is output, Normal Memory Timing-bit D5 set to 0)
- ei
- ld pre1,#11001011b ;Prescaler=50, internal clock source (D1 set to 1), (Timer 1 set to continues Count Mode N (bit D0 set to 1))
- ld t1,#200 ;200 is equal to 1/100 second at 8 MHz clock
- or tmr,#11001100b ;load and start timer1 (bits D2 and D3 set to 1), Internal Clock Out (bits D7D6=11)
- ld SECOND,#0 ;Reset the Clock
- ld MINUTE,#0
- ld HOUR,#0
- ld HUNDREDTH,#0
- start:
- ld p0,HUNDREDTH ;Show the hundredths on Port 0 as binary number (Now the LEDs display the hundredths)
- ld p1,SECOND ;The LEDs show now the Seconds
- ld p2,MINUTE ;
- jp start ;as long as there are no Interrupts, this loop will repeat
- T0_IRQ:
- iret ;Zählen von
- T1_IRQ: ;Start the Interrupt-Service-Routine
- ;disable T1
- inc HUNDREDTH ;1/100 Second increment
- cp HUNDREDTH,#100 ;a whole second?
- jp ne,T1_IRQ_EXIT ;no
- clr HUNDREDTH ;yes
- inc SECOND ;Seconds increment
- cp SECOND,#60 ;a whole Minute?
- jp ne,T1_IRQ_EXIT ;no
- clr SECOND ;yes
- inc MINUTE ;Minutes increment
- cp MINUTE,#60 ;a whole hour?
- jp ne,T1_IRQ_EXIT ;no
- clr MINUTE ;yes
- inc HOUR ;an hour increment
- T1_IRQ_EXIT:
- ;enable T0
- iret ;Return from the Interrupt-Service-Routine
- IRQ_DUMMY:
- ;enable T1
- iret ;ISR-Dummy, in case any other interrupt is entered
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement