Hardware Reference
In-Depth Information
movb #$90,TSCR1 ; enable TCNT and fast timer flag clear
bset TIOS,OC0 ; select OC0 function
movb #$03,TSCR2 ; set prescaler to TCNT to 8
bclr DDRT,$80 ; configure PT7 for input
; configure PA function: enable PA, select event-counting mode, rising edge
; of PAI signal increments the PACNT counter, enable PAOV interrupt
movb
#$52,PACTL
cli
; enable PAOV interrupt
ldd
TCNT
sec_loop addd
#60000
std
TC0
brclr
TFLG1,C0F,*
; wait for 20 ms here
ldd
TC0
dec
oc_cnt
bne
sec_loop
movb
#0,PACTL
; disable PA function
sei
; disable interrupt
ldd
PACNT
std
frequency 1 2
ldd
paov_cnt
std
frequency
swi
paov_isr
movb
#PAOVF,PAFLG
; clear the PAOVF flag
ldx
paov_cnt
; increment PACNT overflow
inx
; count by 1
stx
paov_cnt
;
end
The C language version of the program is as follows:
#include “c:\cwHCS12\include\hcs12.h”
unsigned long int frequency;
unsigned int paov_cnt;
void main (void)
{
int oc_cnt;
PACNT
5 0;
frequency 5 0;
paov_cnt 5 0;
TSCR1 5 0x90;
// enable TCNT and fast flag clear
TIOS 5 OC0;
// select OC0 function
TSCR2 5 0x03;
// set prescale factor to 8
PACTL 5 0x52;
// enable PA function, enable PAOV interrupt
DDRT & 5 0x7F;
// configure the PT7 pin for input
asm(“cli”);
// enable interrupt globally
oc_cnt
5 50;
TC0
5 TCNT 1 60000u;
while (oc_cnt) {
while(!(TFLG1 & C0F));
TC0 5 TC0 1 60000u;
Search WWH ::




Custom Search