list p=16F628A, b=8, c= 102, n=71, t=on, st=off, f=inhx32
;******************************************************************
;* *
;* Filename: Burst Test.asm *
;* Author: Mike McLaren, K8LH (k8lh_at_arrl.net) *
;* Date: 27-Oct-07 (last revision 27-Oct-07) *
;* *
;* *
;* *
;* MPLab: 7.40 (tabs=8) *
;* MPAsm: 5.03 *
;* *
;******************************************************************
#include <p16f628A.inc>
errorlevel -302
__config _PWRTE_ON&_LVP_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT&_MCLRE_OFF
;
TMRH equ 0x20 ;
;******************************************************************
;* Reset Vector *
;******************************************************************
org 0x0000
Reset
clrf STATUS ; |B0
clrf PORTA ; |B0
clrf PORTB ; |B0
goto Main ; |B0
;******************************************************************
;* Subroutines *
;******************************************************************
;
; setup PWM -> 572 usec period (1748.25 Hz) using a 4 MHz clock
;
InitPWM
movlw b'00000010' ; '000000010' |B0
; '-0000---' postscaler 1:1
; '-----0--' timer 2 off
; '------01' prescaler 1:4
movwf T2CON ; produces 4 usec 'ticks' |B0
clrf CCPR1L ; 0% duty cycle (tone off) |B0
bsf STATUS,RP0 ; select bank 1 |B1
movlw d'143'-1 ; 143 4-usec 'ticks' |B1
movwf PR2 ; 572 usec period (1748.25 Hz) |B1
bcf TRISB,3 ; make RB3/CCP1 pin output |B1
bcf STATUS,RP0 ; select bank 0 |B0
movlw b'00001100' ; '----1100' |B0
movwf CCP1CON ; put CCP module in PWM mode |B0
bsf T2CON,TMR2ON ; turn on TMR2 |B0
return ; |B0
;******************************************************************
; *
; DelayUS(16..262159), 4-MHz Mike McLaren, K8LH, Jun'07 *
; *
; requires the use of constant operands known at assembly time! *
; *
; 12 words, 1 RAM variable, 14-bit core *
; ^^^^^^^^^^^ *
; the macro produces 4 instructions; *
; *
DelayUS macro delay ; parameter range 16..262159
movlw high((delay-16)/4)+1
movwf TMRH
movlw low ((delay-16)/4)
call DelayLo-(delay%4)
endm
;
Delay.16F
nop ; entry point for delay%4 == 3 |B0
nop ; entry point for delay%4 == 2 |B0
nop ; entry point for delay%4 == 1 |B0
DelayLo addlw -1 ; subtract 4 cycle loop time |B0
skpnc ; borrow? yes, skip, else |B0
goto DelayLo ; do another loop |B0
nop ; |B0
DelayHi addlw -1 ; subtract 4 cycle loop time |B0
decfsz TMRH,F ; done? yes, skip, else |B0
goto DelayLo ; do another loop |B0
goto $+1 ; burn off 2 cycles |B0
return ; |B0
;******************************************************************
;* Main program *
;******************************************************************
Main movlw h'07' ; |B0
movwf CMCON ; turn comparator off |B0
bsf STATUS,RP0 ; bank 1 |B1
clrf TRISA ; PORTA all outputs |B1
clrf TRISB ; PORTB all outputs |B1
bcf STATUS,RP0 ; bank 0 |B0
;
; initialize PWM module for 1750 Hz Period
;
call InitPWM ; |B0
;
; test 1750 Hz tone
;
Test movlw d'71' ; approx 50% duty cycle |B0
movwf CCPR1L ; turn tone on |B0
DelayUS(250000) ; 1/4 second delay |B0
clrf CCPR1L ; turn off tone (0% duty cycle) |B0
DelayUS(250000) ; 1/4 second delay |B0
goto Test ; loop forever |B0
;******************************************************************
end