home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
08
/
vansick
/
listing4.asc
< prev
next >
Wrap
Text File
|
1990-11-10
|
1KB
|
64 lines
#include "hc05c8.h"
#include "general.h"
int hrs, mts, sec; /* global variables */
long count=1000;
struct bothbytes /* 16 bit int structure */
{
int hi;
int lo;
};
union isboth /* and union */
{
long l;
struct bothbytes b;
};
union isboth time_comp_count;
registera ac;
void main(void)
{
int key;
TCR.OCIE = 1; /* enable output compare interrupt */
CLI(); /* enable all interrupts */
FOREVER
{
if(sec==60) /* do clock things each minute */
{
sec=0;
if(++mts==60)
{
mts=0;
if(++hrs==13)
hrs=1;
}
}
WAIT(); /* wait here to save the energy */
}
}
void __TIMER(void) /* time interrupt service routine */
{
/* the program gets here every millisecond */
time_comp_count.b.hi = TCHI;
ac =TSR; /* Clear the tof bit */
time_comp_count.b.lo = TCLO;
time_comp_count.l += 500; /* 500 counts per millisecond */
OCHI = time_comp_count.b.hi;
ac = TSR; /* Clear ocf bit */
OCLO = time_comp_count.b.lo;
if(--count)
return ;
else
{
sec++; /* here every second */
count=1000;/* reset count to 1 second */
}
}