From: kilian@cray.com (Alan Kilian)
Subject: Re: 68HC11 Output Compare example
Organization: Cray Research, Inc.
Date: 26 Sep 92 11:58:23 CDT

I don't have an example for a MC68HC11 but I do have one for a HC16.
They use the same GPT subsystem so it should tell you what you
need to know to run the HC11.
                                -Alan
*
*       Alan Kilian   
*       Example from Robot platform driver
*
*       Title : HC16 Output Compare example
*
*       File Name : ocexamp.asm
*
*       Description : This program demonstrates the Output Compare function
*                     of the General-Purpose-Times (GPT) subsystem of the
*                     XC68HC16Z1 
*
*       History : 03/09/92  Created (pwm.asm).
*                 09/26/92  ocexamp.asm edited from pwm.asm.
*
*       Note : This program is written for the M68HC16Z1EVB.
****************************************************************************
 
 
        INCLUDE '..\INCLUDE\EQUATES.ASM' EQUates for common register addr
        INCLUDE '..\INCLUDE\ORG00000.ASM'  ;initialize reset vector
 
        ORG     $0200           ;start program after interrupt vectors
 
*****   Initialization Routines *****
        INCLUDE '..\INCLUDE\INITSYS.ASM'   ;initially set EK=F, XK=0, YK=0, ZK=0
                                           ;set sys clock at 16.78 MHz, no COP
        INCLUDE '..\INCLUDE\INITRAM.ASM'   ;Setup RAMBAL,RAMBAH and Stack
 
        JSR     SET_INT         ;Setup interrupt vector for OC2
        JSR     SET_INTC        ;Set the interrupt configuration
 
TIME
        LDD     #$8000          ;OC2 value
        STD     TOC2
        STD     PINGTIM         ;PINGTIM holds the time of the outgoing pulse
        STD     PINGRTE         ;PINGRTE holds the rate of the pings
        ANDP    #$FF1F          ;Enable all interrupts
 
DEAD    
        BRA     DEAD            ;The OC2 interrupt will jump to OC2INT
 
 
OC2INT  BCLR    TFLG1,#$10      ;We get here when TCNT == PINGTIM
        LDD     TCNT            ;What time is it NOW?
        ADDD    PINGRTE         ;What time is the next pulse to go out?
        STD     TOC2            ;Tell GPT to send a pulse then
        STD     PINGTIM         ;Remember when the pulse went out
        RTI
 
SET_INT
        PSHM    D               ;Be nice to others
        LDAB    #$00            ;Get to the correct memory block
        TBEK                    ;By setting the EK register
        LDD     #OC2INT         ;Output Compare #2 interrupt handler address
        STD     $010A           ;A magic address that holds OC2's interrupt
        LDAB    #$0F            ;Get back to program memory
        TBEK                    ;By setting EK
        PULM    D               ;Pick up your trash
        RTS
 
* Setup the Interrupt configuration register of the GPT
SET_INTC
        PSHM    D               ;Be nice to others
        LDD     #$0580          ;PAB:0 IRL:5 VBA:8
        STD     ICR
        LDD     #$0088          ;stop:0 frz:0 stopp:0 incp:0 supv:1 iarb:8
        STD     GPTMCR
        LDD     #$1783          ;int on IC1,IC2,IC3,OC2 and tof. prescale = /32
        STD     TMSK1
        LDD     #$011A          ;OC2 toggle the OC2 output 
        STD     TCTL1           ;Capture falling edge IC1,IC2. Rising edge IC3
        PULM    D               ;Pick up your trash
        RTS
 
PINGTIM EQU     $0318           ;Save TWO bytes for ping start time
PINGRTE EQU     $031A           ;Save TWO bytes for ping rate time

-- 
 -Alan Kilian           kilian@cray.com 612.683.5499 (Work) 612.721.3990 (Home)
  Cray Research, Inc.   655 F Lone Oak Drive, Eagan  MN, 55121 
                        "It's based on actual math". -Dilbert
Newsgroups: sci.electronics