User`s manual

PK2100
Software Reference s 5-7
uint DMASnapShot( byte channel,
uint *counter )
This function reads the number of pulses that a DMA channel (0 or 1)
has counted. A DMA counter is initialized with one of the two
preceding functions. The function returns 0 if a DMA channel is
counting too fast to allow for stable reading of the count value. If the
function reads a stable count value, it returns 1 and sets the parameter
count. Note that DMA interrupts will still occur when the DMA
channel counts down from its loaded value even if the counts cannot
be read.
For example,
main(){
unsigned count, oldcount;
oldcount = 0;
DMA0Count( 100 ); // count 100 pulses
while( !DMA0FLAG ){ // not finished
if( DMASnapShot(0,&count) ){ // is it stable?
if( oldcount != count ){
oldcount = count;
printf( DMA counted %u\n, count );
}
}
}
printf( finished counting\n );
}
The program DMACOUNT.C in the subdirectory SAMPLES\CPLC
illustrates the use of these DMA functions.
Battery-Backed Clock
The battery-backed clock, Toshiba part number TC8250, retains the time
and date with a resolution of one second, and an accuracy of about one
second per day. It automatically accounts for leap year.
The following structure is used to hold the time and date:
struct tm {
char tm_sec; // 0-59
char tm_min; // 0-59
char tm_hour; // 0-23
char tm_mday; // 1-31
char tm_mon; // 1-12
char tm_year; // 00-150 (1900-2050)
char tm_wday; // 0-6 where 0 means Sunday
};