用PIC單片機(jī)實(shí)現(xiàn)音樂播放的實(shí)例程序
INTZ:
PUSH ; Push ;中斷服務(wù)程序
BTFSC PIR1,TMR2IF ;測試TMR2中斷標(biāo)志位
b INT_TMR2 ;
BTFSC INTCON,TOIF ;測試TMR0中斷標(biāo)志位
GOTO INT_TMR0
IntRet:
POP ; Pop
RETFIE
;**************************************************
INT_TMR2:
BCF PIR1,TMR2IF ;清TMR2中斷標(biāo)志位
movf TmrBak,w
movwf TMR2
CPL BeepOut
BeeperEnd:
b IntRet
;**************************************************
INT_TMR0: ;定時0中斷
BCF INTCON,TOIF ; clear INTF
MOVLW .255-.38 ;10ms
MOVWF TMR0
;====================
decfsz T100ms,f
b int_tmr0_ret
movlw CSTIME100MS
movwf T100ms
bsf Sflag,Fg_100ms
;=====================
int_tmr0_ret:
b IntRet
;**************************************************
PlayPsWhisle:
bsf Fg,FgBeep
clrf BeepCnt
movlw .0
movwf BeepMode
movlw CSTIME100MS
movwf T100ms
retlw 0
;**************************************************
PlayPsOk:
bsf Fg,FgBeep
clrf BeepCnt
movlw .1
movwf BeepMode
movlw CSTIME100MS
movwf T100ms
retlw 0
;**************************************************
PlayPsHang:
bsf Fg,FgBeep
clrf BeepCnt
movlw .2
movwf BeepMode
movlw CSTIME100MS
movwf T100ms
retlw 0
;**************************************************
PlayPsWelcom:
bsf Fg,FgBeep
clrf BeepCnt
movlw .3
movwf BeepMode
movlw CSTIME100MS
movwf T100ms
retlw 0
;**************************************************
;音樂播放程序
;BeepMode=0 : psWhisle
;BeepMode=1 : psOk
;BeepMode=2 : psHang
;BeepMode=3 : psWelcom
;**************************************************
BeepFor:
btfss Sflag,Fg_100ms
b BeepForEnd
bcf Sflag,Fg_100ms
btfss Sflag,FgBeep
b BeepForEnd
MOVLW B'00000101' ;開TMR2 1:4分頻
MOVWF T2CON
movf BeepMode,w
b BeepModeJmp
psWhisle:
call WhisleTab
b BeepPlay
psOk:
call OkTab
b BeepPlay
psHang:
call HangTab
b BeepPlay
psWelcom:
call WelcomTab
b BeepPlay
BeepPlay:
incf BeepCnt,f
movwf TmrBak
movf TmrBak,f
btfsc status,z
b BeepOff
movlw .1
xorwf TmrBak,w
btfsc status,z
b BeepStop
b BeepForEnd
BeepOff:
clrf BeepCnt
bcf Sflag,FgBeep
bcf BeepOut
bcf T2CON,TMR2ON
b BeepForEnd
BeepStop:
bcf T2CON,TMR2ON ;stop
bcf BeepOut
BeepForEnd:
retlw 0
;**************************************************
END
本文引用地址:http://butianyuan.cn/article/172783.htm
評論