Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
list p=16F628A, b=8, c= 102, n=71, t=on, st=off, f=inhx32
;******************************************************************
;* *
;* Filename: Tone Burst.asm *
;* Author: Mike McLaren, K8LH (k8lh_at_arrl.net) *
;* Date: 08-Jul-08 (last revision 08-Jul-08) *
;* *
;* 1750 Hz Tone Burst Experiment *
;* *
;* MPLab: 8.01 (tabs=8) *
;* MPAsm: 5.15 *
;* *
;******************************************************************
#include <p16f628A.inc>
errorlevel -302
radix dec
__config _PWRTE_ON&_LVP_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT&_MCLRE_OFF
;
TMRH equ 0x20 ;
clock equ 4 ; user clock frequency in MHz
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ usecs*1000 ; cycles/millisecond multiplier
;
DelayCy macro pDelay ; cycles (Tcy), minimum 16
movlw high((pDelay-16)/4)+1
movwf TMRH
movlw low ((pDelay-16)/4)
call DelayLo-(pDelay%4)
endm
;******************************************************************
;* Reset Vector *
;******************************************************************
org 0x0000
Reset
clrf STATUS ; |B0
clrf PORTA ; |B0
clrf PORTB ; |B0
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
burst
bsf PORTA,0 ; continuous 1748.25 Hz on RA0
DelayCy(286*usecs-1) ;
bcf PORTA,0 ;
DelayCy(286*usecs-3) ;
goto burst ;
;******************************************************************
Delay.16
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 ;
;******************************************************************
end
movlw b'000000[COLOR=Red]10[/COLOR]' ; '000000[COLOR=Red]10[/COLOR]' |B0
; '-0000---' postscaler 1:1
; '-----0--' timer 2 off
; '------[COLOR=Black][COLOR=Blue]01[/COLOR]' [COLOR=Blue]prescaler 1:4
[COLOR=Black]movwf T2CON ; produces 4 usec 'ticks' |B0[/COLOR]
[/COLOR][/COLOR]
I received a private message yesterday from the original poster asking for help.Mike, why have you suddenly replied to a thread that ended last December?.