Hardware Reference
In-Depth Information
Example 8.15
Write a program to measure the duration of an unknown signal connected to the PAI pin.
Solution: The assembly program that implements the previous algorithm is as follows:
#include “c:\miniide\hcs12.inc”
org
$1000
paovCnt ds.b
1
; use to keep track of the PACNT overflow count
pw
ds.b
3
; hold the signal pulse width
org
$1500
movw
#paovISR,UserPAccOvf
; set up PAOV interrupt vector
ldd #0
std PACNT ; let PACNT count up from 0
clr paovCnt ; initialize PACNT overflow count to 0
movb #$0,TSCR2 ; set TCNT timer prescaler to 1
; configure PA function: enable PA, select gated-time—accumulator mode, high level
; of the PAI signal enables PACNT counter, enable PAOV interrupt
movb
#$62,PACTL
bclr
DDRT,$80
; configure PAI pin for input
cli
; enable PAOV interrupt
brclr
PAFLG,PAIF,*
; wait for the arrival of the falling edge of PAI
movb
#0,PACTL
; disable PA function
sei
; disable interrupt
ldd
PACNT
std
pw
ldaa
paovCnt
staa
pw
swi
paovISR
movb
#PAOVF,PAFLG
; clear PAOVF flag
inc
paovCnt
; increment PACNT overflow count by 1
end
The C language version of the program for the CodeWarrior C compiler is as follows:
#include “c:\cwHCS12\include\hcs12.h”
unsigned int paovCnt;
long unsigned int pw;
void main(void)
{
PACNT 5 0;
// let PACNT count up from 0
TSCR1 5 0x90;
// enable TCNT and fast timer flag clear
paovCnt 5 0;
pw 5 0;
TSCR2 5 0x00; // set TCNT prescaler to 1
DDRT 5 0x00; // configure all timer port pins for input
// configure PA function: enable PA, select gated-time-accumulator mode, high level
// of PAI enables PACNT to count, enable PAOV interrupt
PACTL 5 0x62;
asm(“cli”);
Search WWH ::




Custom Search