Producing 33ms real-time interrupt

The onboard timer/counter, 8254 is used to produce periodic interrupt. The counter channel0 is loaded with 0000 by monitor program. Input clock to the 8254 is 2MHz from clock out pin of the 8085. This makes approx. 2MHz/65536 = 30.52Hz pulse output. The pulse signal is tied to RST 7.5 interrupt pin. When the MASK bit for RST 7.5 is cleared and the instruction EI was executed, the CPU will jump to address 003CH. We can put many subprograms and let them be executed with multiple of 33ms period.

In the application that controlled by time trigger, such periodic interrupt can be used as the real-time tasks running. The diagram shows the sequence of task execution controlled by 33ms. In realtime application, the periodic period may be called tick.

The program below makes the onboard LED blinking at two rates. Main code sets the RST 7.5 enable flag and repeat jump waiting for interrupt.


                ; MTK-85 8085 Microprocessor Training Kit
; exp3.asm
; producing 33ms realtime interrupt
; using 8254 to produce 30.52Hz interrupt signal at RST7.5
; The 8254 counter0 was loaded with 0000 by system monitor.
; The input clock to the 8254 is 2MHz, the OUT0 then produces
; 2MHz/65536 = 30.52Hz interrupt at RST7.5!
; 33ms periodic interrupt

0000 CPU "8085.TBL" ;CPU TABLE

0000 = gpio equ 0
0001 = led1_mask equ 00000001b
0002 = led2_mask equ 00000010b

803C org 803ch ; interrupt vector of RST7.5 (relocated from 003CH)
803C C30781 jmp service_rst7.5

8100 org 8100h

8100 3E0B start: mvi a,1011b ; enable rst7.5
8102 30 sim ; set interrupt mask register
8103 FB ei ; enable interrupt

8104 C30481 jmp $ ; jump here

; enter service routine for RST 7.5 every 33ms

8107 service_rst7.5:

8107 CD1581 call task1
810A CD2F81 call task2
810D CD4981 call task3
8110 CD5181 call task4
8113 FB ei
8114 C9 ret

; task1 toggles bit0 every 15 ticks

8115 3A0090 task1: lda timer1
8118 C6FF adi -1
811A C22B81 jnz exit1

811D 3E0F mvi a,15
811F 320090 sta timer1

8122 3A0290 lda led
8125 EE01 xri led1_mask
8127 320290 sta led
812A C9 ret

812B 320090 exit1: sta timer1
812E C9 ret

; task2 toggles bit1 every 5 ticks

812F 3A0190 task2: lda timer2
8132 C6FF adi -1
8134 C24581 jnz exit2

8137 3E05 mvi a,5
8139 320190 sta timer2

813C 3A0290 lda led
813F EE02 xri led2_mask
8141 320290 sta led
8144 C9 ret

8145 320190 exit2: sta timer2
8148 C9 ret

; task3 write led to gpio every 1 tick

8149 3A0290 task3: lda led
814C E603 ani 00000011b ; send out only two bits
814E D300 out gpio
8150 C9 ret

8151 00 task4: nop
8152 C9 ret

9000 org 9000h

9000 timer1 dfs 1
9001 timer2 dfs 1
9002 led dfs 1

0000 end
See the sample code running from video file below.
Click to download demo of program running (Quicktime MP4 file, 1MB)

Written by Wichit Sirichote,
Last updated: May 4, 2007.