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 />

lib_80186 segment public ’code’<br />

assume cs:lib_80186, ds:data<br />

public _set_time<br />

_set_time proc far<br />

push bp ;save caller’s bp<br />

mov bp, sp ;get current top of stack<br />

hour equ word ptr[bp+6] ;get parameters off stack<br />

minute equ word ptr[bp+8]<br />

second equ word ptr[bp+10]<br />

T2Compare equ word ptr[bp+12]<br />

push ax ;save registers used<br />

push dx<br />

push si<br />

push ds<br />

xor ax, ax ;set interrupt vector<br />

mov ds, ax<br />

mov si, 4*timer_2_int<br />

mov word ptr ds:[si], offset<br />

timer_2_interrupt_routine<br />

inc si<br />

inc si<br />

mov ds:[si], cs<br />

pop ds<br />

mov ax, hour ;set time<br />

mov _hour, al<br />

mov ax, minute<br />

mov _minute, al<br />

mov ax, second<br />

mov _second, al<br />

mov _msec, 0<br />

mov dx, T2CNT ;clear Count register<br />

xor ax, ax<br />

out dx, al<br />

mov dx, T2CMPA ;set maximum count value<br />

mov ax, T2Compare ;see note in header above<br />

out dx, al<br />

mov dx, T2CON ;set up the control word:<br />

mov ax, 0E001H ;enable counting,<br />

out dx, al ;generate interrupt on MC,<br />

;continuous counting<br />

mov dx, TCUCON ;set up interrupt controller<br />

xor ax, ax ;unmask highest priority interrupt<br />

out dx, al<br />

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

9-19

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

Saved successfully!

Ooh no, something went wrong!