PROCESSOR 16f84A
#include "P16F84A.inc"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
Cblock 0x0C ;RAM strating address
PRESCbeep
Beep_TEMP1 ;Belongs to macro "BEEP"
Beep_TEMP2
Beep_TEMP3
HIcnt ;Auxiliary variable for macro pausems
LOcnt
LOOPcnt
endc
#define BEEPport PORTA,3 ;Port and pin beeper is located at
#define BEEPtris TRISA,3
ORG 0x00 ;Reset vector
goto Main
ORG 0x04 ; Interrupt vector
goto Main ;no intertupt routine
BEEP MACRO FREQ, DURATION
MOVLW FREQ
MOVWF BEEP_TEMP1
MOVLW DURATION
CALL BEEPSUB
ENDM
BEEPINIT MACRO
BCF BEEPPORT
BSF STATUS, RP0
BCF BEEPTRIS
BCF STATUS,RP0
ENDM
BEEPSUB MOVWF BEEP_TEMP2;SET THE SOUND DURATION
CLRF TMR0 ;INITIALIZE THE COUNTER
BCF BEEPPORT
BSF STATUS,RP0
BCF BEEPPORT
MOVLW PRESCBEEP ;SET PRESCALER FOR THRO
MOVWF OPTION_REG ; OPTION <- U
BCF STATUS,RP0
BEEPA
BCF INTCON,T0IF;CLEAR THRO OVERFLORA FLAG
BEEPB
BSF BEEPPORT
CALL B_WAIT ;DURATION OF LOGICAL "1"
BCF BEEPPORT
CALL B_WAIT ;DURATION OF LOGICAL "0"
BTFSS INTCON,T0IF;CHECK THRO OVERFLORA FLAG,
GOTO BEEPB ;SKIP IF SET
DECFSZ BEEP_TEMP2,1 ;IS BEEP_TEHP2 = 0 ?
GOTO BEEPA ;IF NOT, JUMP BACK TO BEEP
RETURN
B_WAIT
MOVFW BEEP_TEMP1
MOVWF BEEP_TEMP3
B_WAITA
DECFSZ BEEP_TEMP3,1
GOTO B_WAITA
RETURN
Main ;Beginning of the program
banksel TRISA
movlw b'00010111' ; initializing port A
movwf TRISA ;" ;TRISA <- 0x17
banksel PORTB
Loop
BEEPinit ;Initialising Beeper
;~~~~~~~ these have been commented to allow the program to compile ~~~~~
; button PORTA, 0,0, Playl ;Button 1
; button PORTA, 1,0, Play2 ;Button 2
; goto Loop
Playl
BEEP 0xFF, 0x02
BEEP 0x90, 0x05
BEEP 0xC0, 0x03
BEEP 0xFF, 0x03 ;First tune
goto Loop
Play2
BEEP 0xbb, 0x02
BEEP 0x87, 0x05
BEEP 0xa2, 0x03
BEEP 0x98, 0x03 ;Second tune
goto Loop
End ;End of program