ht82k74e Holtek Semiconductor Inc., ht82k74e Datasheet - Page 24

no-image

ht82k74e

Manufacturer Part Number
ht82k74e
Description
27mhz Keyboard/ Mouse Tx 8-bit Mcu
Manufacturer
Holtek Semiconductor Inc.
Datasheet
Timer Program Example
This program example shows how the Timer/Event Counter registers are setup, along with how the interrupts are en-
abled and managed. Note how the Timer/Event Counter is turned on, by setting bit 4 of the Timer Control Register. The
Timer/Event Counter can be turned off in a similar way by clearing the same bit. This example program sets the
Timer/Event Counter to be in the timer mode, which uses the internal system clock as the clock source.
org 04h
reti
org 008h
jmp tmrint
:
org 20h
;internal Timer/Event Counter interrupt routine
tmrint:
:
; Timer/Event Counter main program placed here
:
reti
:
:
begin:
;setup Timer registers
mov a,09bh
mov tmrl,a;
mov a, 0aah
mov tmrh,a
mov a,080h
mov tmrc,a
; setup interrupt register
mov a,005h
mov intc,a
set tmrc.4
Interrupts
Interrupts are an important part of any microcontroller
system. When an internal function such as a
Timer/Event Counter overflow, their corresponding in-
terrupt will enforce a temporary suspension of the main
program allowing the microcontroller to direct attention
to their respective needs. This device contains a single
internal Timer/Event counter interrupt.
Interrupt Register
Overall interrupt control, which means interrupt enabling
and request flag setting, is controlled by a single inter-
rupt control register, which is located in the Data Mem-
ory. By controlling the appropriate enable bits in this
register the interrupt can be enabled or disabled. Also
when an interrupt occurs, the request flag will be set by
the microcontroller. The global enable flag if cleared to
zero will disable all interrupts.
Interrupt Operation
A Timer/Event Counter overflow, will generate an inter-
rupt request by setting its corresponding request flag, if
its interrupt enable bit is set. When this happens, the
Program Counter, which stores the address of the next
instruction to be executed, will be transferred onto the
stack. The Program Counter will then be loaded with a
new address which will be the value of the correspond-
Rev. 1.00
; Timer/Event Counter interrupt vector
; jump here when Timer overflows
; main program
; setup Timer low register
; load low register first
; setup timer high register
; setup Timer control register
; timer mode is used
; enable master interrupt and timer interrupt
; start Timer/Event Counter - note mode bits must be previously setup
24
ing interrupt vector. The microcontroller will then fetch
its next instruction from this interrupt vector. The instruc-
tion at this vector will usually be a JMP statement which
will jump to another section of program which is known
as the interrupt service routine. Here is located the code
to control the appropriate interrupt. The interrupt service
routine must be terminated with a RETI statement,
which retrieves the original Program Counter address
from the stack and allows the microcontroller to continue
with normal execution at the point where the interrupt
occurred.
Once an interrupt subroutine is serviced, other inter-
rupts will be blocked, as the EMI bit will be cleared auto-
matically. This will prevent any further interrupt nesting
from occurring. However, if other interrupt requests oc-
cur during this interval, although the interrupt will not be
immediately serviced, the request flag will still be re-
corded. If an interrupt requires immediate servicing
while the program is already in another interrupt service
routine, the EMI bit should be set after entering the rou-
tine, to allow interrupt nesting. If the stack is full, the in-
terrupt request will not be acknowledged, even if the
related interrupt is enabled, until the Stack Pointer is
decremented. If immediate service is desired, the stack
must be prevented from becoming full.
HT82K74E/HT82K74EE
December 15, 2009

Related parts for ht82k74e