03.01.2015 Views

80C186EC/80C188EC Microprocessor User's Manual

80C186EC/80C188EC Microprocessor User's Manual

80C186EC/80C188EC Microprocessor User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TIMER/COUNTER UNIT<br />

$mod186<br />

name example_80186_family_timer_code<br />

;FUNCTION: This function sets up the timer and interrupt controller<br />

; to cause the timer to generate an interrupt every<br />

; 10 milliseconds and to service interrupts to<br />

; implement a real time clock.<br />

;<br />

; Timer 2 is used in this example because no input or<br />

; output signals are required.<br />

;<br />

;SYNTAX: extern void far set_time(hour, minute, second, T2Compare)<br />

;<br />

;INPUTS: hour - hour to set time to.<br />

; minute - minute to set time to.<br />

; second - second to set time to.<br />

; T2Compare - T2CMPA value (see note below)<br />

;<br />

;OUTPUTS: None<br />

;NOTE: Parameters are passed on the stack as required by<br />

; high-level languages<br />

;<br />

; For a CLKOUT of 16Mhz,<br />

;<br />

; f(timer2) = 16Mhz/4<br />

; = 4Mhz<br />

; = 0.25us for T2CMPA = 1<br />

;<br />

; T2CMPA(10ms) = 10ms/0.25us<br />

; = 10e-3/0.25e-6<br />

; = 40000<br />

;substitute register offsets<br />

T2CON equ xxxxh ;Timer 2 Control register<br />

T2CMPA equ xxxxh ;Timer 2 Compare register<br />

T2CNT equ xxxxh ;Timer 2 Counter register<br />

TCUCON equ xxxxh ;Int. Control register<br />

EOI equ xxxxh ;End Of Interrupt register<br />

INTSTS equ xxxxh ;Interrupt Status register<br />

timer_2_int equ 19 ;timer 2:vector type 19<br />

data segment public ’data’<br />

public<br />

_hour, _minute, _second, _msec<br />

data ends<br />

_hour db <br />

_minute db <br />

_second db <br />

_msec db <br />

Example 9-1. Configuring a Real-Time Clock<br />

9-18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!