;*****
;Generates a BEEP via the pizeo buzzer. neet!
;*****
beep
;	Wait	10 Millisec, 0		; Delay a wee bit

	Bank1	
	movlw d'150'		; when TMR2 = 103 = end of Period, high-pitched
	movwf PR2
	Bank0

	movlw	d'5'
	movwf	Piezo_Cntr
	bsf	T2CON, 2		; Enable timer, starts PWM output
	return

;*****
;Produces a long beep, error code.
;*****
error_beep
;	Wait	10 Millisec, 0		; Delay a wee bit

	Bank1	
	movlw	d'100'		; when TMR2 = 50 = end of Period, low-pitched
	movwf	PR2
	Bank0

	movlw	d'15'
	movwf	Piezo_Cntr
	bsf	T2CON, 2
	return


init_piezo
	; Set tmr2 period.
	Bank1	
	movlw	d'150'		; when TMR2 = 103 = end of Period, high-pitched
	movwf	PR2
	Bank0

	movlw	b'00110011'	; set bits 9 - 2
	movwf	CCPR1L
	bsf	CCP1CON,CCP1X	; set bit 1 = 1
	bsf	CCP1CON,CCP1Y	; set bit 0 = 1

	Bank1			; Make the pin an output.
	movlw	b'11111011'
	andwf	TRISC, F
	Bank0

	movlw	b'00000011'	; TMR2 = off (2), prescale = 1:16 (1,0)
	movwf	T2CON


	;Configure the CCP1 module for PWM
	movf	CCP1CON,W
	andlw	b'00110000'  ; mask all but previously set Duty Cycle bits
	iorlw 	b'00001111'  ; and enable PWM mode
	movwf 	CCP1CON

	Bank0
	return
