File "oc3.c"
Full Path: /home/analogde/www/68hc11/oc3.c
File size: 1.69 KB
MIME-type: text/x-c
Charset: utf-8
55d
HTTP/1.1 200 OK
Date: Sat, 18 Jun 2005 20:19:27 GMT
Server: Apache/1.3.26 (Unix) Debian GNU/Linux mod_perl/1.26 mod_ssl/2.8.9 OpenSSL/0.9.6g PHP/4.1.2
Last-Modified: Wed, 08 Jan 2003 19:42:52 GMT
ETag: "95c9be-55d-3e1c7f3c"
Accept-Ranges: bytes
Content-Length: 1373
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/x-csrc
// File **********OC3.C***********
// Periodic Interrupt using TOC3
// Output on TC3/OC3
// Last modified 1/21/02 by Jonathan W. Valvano
// Copyright 2002 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu
// You may use, edit, run or distribute this file
// as long as the above copyright notice remains
unsigned short static volatile Count;
unsigned short static Period;
void (*CallBack)(void); // call back function
#define RATE 2000
#pragma interrupt_handler TOC3handler()
void TOC3handler(void){ // executes at 1000 Hz
TFLG1 = 0x08; // acknowledge OC3
Count++;
TC3 = TC3+RATE; // 1 ms
if(Count==Period){
Count = 0;
(*CallBack)(); // execute call back process
}
}
#pragma abs_address:0xffe8
void (*OC3_vector[])() = { TOC3handler };
#pragma end_abs_address
void Start(unsigned short thePeriod, void(*fp)(void)){
asm(" sei"); // make ritual atomic
Period = thePeriod;
CallBack = fp;
Count = 0;
TIOS |= 0x08;
0
// activate TC3 as output compare
DDRT |= 0x08; // TC3 is an output
TSCR = 0x80; // activate timer
TMSK2 = 0x32; // clock at 2Mhz
TMSK1 |= 0x08; // arm OC3
TFLG1 = 0x08; // initially clear C3F
TCTL2 |= 0x40; // TC3 set on next interrupt
TC3 = TCNT+50; // first interrupt right away
asm(" cli");
}