Example 92. configuring a square-wave generator – Intel 80C188XL User Manual

Page 250

Advertising
background image

9-21

TIMER/COUNTER UNIT

Example 9-2. Configuring a Square-Wave Generator

$mod186
name

example_timer1_square_wave_code

;FUNCTION:

This function generates a square wave of given

;

frequency and duty cycle on Timer 1 output pin.

;
; SYNTAX:

extern void far clock(int mark, int space)

;
; INPUTS:

mark - This is the mark (1) time.

;

space - This is the space (0) time.

;
;

The register compare value for a given time can be

;

easily calculated from the formula below.

;
;

CompareValue = (req_pulse_width*f)/4

;
; OUTPUTS:

None

;
; NOTE:

Parameters are passed on the stack as required by

;

high-level Languages

T1CMPA

equ xxxxH

;substitute register offsets

T1CMPB

equ xxxxH

T1CNT

equ xxxxH

T1CON

equ xxxxH

lib_80186

segment public ’code’

assume

cs:lib_80186

public

_clock

_clock

proc far

push

bp

;save caller’s bp

mov

bp, sp

;get current top of stack

_space

equ word ptr[bp+6]

;get parameters off the stack

_mark

equ word ptr[bp+8]

push

ax

;save registers that will be

push

bx

;modified

push

dx

mov

dx, T1CMPA

;set mark time

mov

ax, _mark

out

dx, al

mov

dx, T1CMPB

;set space time

mov

ax, _space

out

dx, al

mov

dx, T1CNT

;Clear Timer 1 Counter

xor

ax, ax

out

dx, al

mov

dx, T1CON

;start Timer 1

mov ax,

C003H

out dx,

al

Advertising
This manual is related to the following products: