PIC單片機(jī)汽車防盜器報(bào)警聲(防盜器)
;汽車防盜器報(bào)警聲
;頻率分兩個(gè)0.1s第一個(gè)
;0.1S頻率從1.8K-3.5K勻速增加第二個(gè)0.1S頻率從3.5K-1.8K勻速減少,
;程序復(fù)位后,按S2喇叭叫兩聲,按S3喇叭叫15秒,中途可按S5停止.
;=========================================================
LISTP=16F84A,R=DEC
__CONFIGB11111111110001;_CP_OFF&_WDT_OFF&_PWRITE_ON&_XT_OSC
RTCCEQU01H;定義各寄存器
PCEQU02H
STATUSEQU03H
CEQU0
RP0EQU5
;----------------------
PORTAEQU05H
PORTBEQU06H
TRISAEQU5H
TRISBEQU6H
;-----------------------
SOUNDDELAY1EQU10H;聲音頻率變化計(jì)數(shù)器,從1.8~3.55KHz
FRE_COUNTEQU11H;同一頻率的重復(fù)次數(shù)保存地址
FRE_REPEATEQU12H
SOUND_TEMPEQU13H
TEMPEQU14H;暫存寄存器
S_LOOPEQU46;93-47=46
S_MAXEQU93;最低頻率1.8K93*3=280US*2
S_MINEQU47;最高頻率3.55K47*3=140*2
S_REPEATEQU4;同一頻率重復(fù)次數(shù)
;----------------------RA
KEY1EQU3
KEY2EQU4
;----------------------RB
KEY3EQU0
KEY4EQU1
;--------------------
ORG0000H
MAIN
CLRFPORTA
CLRFPORTB;初始化IO口
BSFSTATUS,RP0
MOV LW0011000B
MOV WFTRISA
MOV LW00000011B
MOV WFTRISB
BCFSTATUS,RP0
LOOP
BTFSSPORTA,KEY1;掃描按鍵
GOTOSET_1
BTFSSPORTA,KEY2
GOTOSET_2
GOTOLOOP
;--------------------------------------------
SET_1
BTFSCPORTA,KEY1;去抖動(dòng)
GOTOLOOP
CALLSOUNDDELAY
BTFSCPORTA,KEY1;按S2叫兩聲
GOTOLOOP
CALLSOUND200MS
CALLSOUND200MS
GOTOLOOP
;--------------------------------------------
SET_2
BTFSCPORTA,KEY2;去抖動(dòng)
GOTOLOOP
CALLSOUNDDELAY
BTFSCPORTA,KEY2;按S3叫15秒
GOTOLOOP
CALLSOUND15S
GOTOLOOP
;------------------------------------------
SOUND200MS
MOV LWS_LOOP
MOV WFFRE_COUNT;46=93-47
SOUND_LH_LP
MOV LWS_REPEAT;同一頻率重復(fù)次數(shù)送FRE_REPEAT
MOV WFFRE_REPEAT
MOV FWFRE_COUNT
ADDLWS_MIN;計(jì)數(shù)值加最小值
MOV WFTEMP
REPEAT0_LP
MOV FWTEMP
BSFPORTA,0
CALLSOUNDDELAY0;廷時(shí)W*3US
BCFPORTA,0
MOV FWTEMP
CALLSOUNDDELAY0
DECFSZFRE_REPEAT,1;每四次減頻率計(jì)數(shù)一次
GOTOREPEAT0_LP
DECFSZFRE_COUNT,1
GOTOSOUND_LH_LP
SOUND_HL
MOV LWS_LOOP
MOV WFFRE_COUNT;46=93-47
SOUND_HL_LP
MOV LWS_REPEAT;同一頻率重復(fù)次數(shù)送FRE_REPEAT
MOV WFFRE_REPEAT
MOV FWFRE_COUNT
SUBLWS_MAX;最大值減計(jì)數(shù)值
MOV WFTEMP
REPEAT1_LP
MOV FWTEMP
BSFPORTA,0
CALLSOUNDDELAY0;廷時(shí)W*3US
BCFPORTA,0
MOV FWTEMP
CALLSOUNDDELAY0
DECFSZFRE_REPEAT,1;四次減頻率計(jì)數(shù)一次
GOTOREPEAT1_LP
DECFSZFRE_COUNT,1
GOTOSOUND_HL_LP
SOUND_END
RETLW0
;------------------------------
SOUNDDELAY:;廷時(shí)255*3US+2US
MOV LW255
SOUNDDELAY0
MOV WFSOUNDDELAY1;廷時(shí)W*3US+1US
SOUNDDELAYUS_1
DECFSZSOUNDDELAY1,1
GOTOSOUNDDELAYUS_1
RETLW0
;---------------------
SOUND15S;報(bào)警15秒
MOV LW73
MOV WFSOUND_TEMP
SOUND1S_LP
CALLSOUND200MS;
BTFSSPORTB,KEY4;按S5退出
RETLW0
DECFSZSOUND_TEMP,1
GOTOSOUND1S_LP
RETLW0
;------------------------
END