BEEP_short.txt

Warning: if you clip this code into your program, look out for possible html code slipping in.

REM this is a simplified BEEP routine suited to producing audio frequencies
REM "Frequency" is relative, not absolute
REM ss 9/9/98

REM simplified BEEP routine
CONSTANT VTI_T2CON   AS INTEGER = 0x12
CONSTANT VTI_CCPR1L  AS INTEGER = 0x15
CONSTANT VTI_CCP1CON AS INTEGER = 0x17
CONSTANT VTI_PR2     AS INTEGER = 0x92
CONSTANT VTI_TRISC   AS INTEGER = 0x95
SUBROUTINE BEEP(freq AS INTEGER)
	IF freq < 10
		POKE(VTI_CCP1CON, 0)			:REM pwm off
		RETURN
	ENDIF
	POKE(VTI_T2CON, (PEEK(VTI_T2CON) AND 0xFC) OR 2):REM prescaler 1:16
	POKE(VTI_PR2, 32767/freq)			:REM set the period 1/freq
	POKE(VTI_CCPR1L, 16383/freq)			:REM set the duty cycle = 50%
	POKE(VTI_CCP1CON, 0x0C)				:REM PWM mode
	POKE(VTI_TRISC, PEEK(VTI_TRISC) AND 0xFD)	:REM config pin as output
	POKE(VTI_T2CON, PEEK(VTI_T2CON) OR 4)		:REM turn on timer 2
END

 

VestaTech Home

© 2002 Vesta Technology