; 汽车防盗器报警声 ;频率分两个0.1s第一个 ;0.1S频率从1.8K-3.5K匀速增加第二个0.1S频率从3.5K-1.8K匀速减少, ;程序复位后,按S2喇叭叫两声,按S3喇叭叫15秒,中途可按S5停止. ;========================================================= LIST P=16F84A,R=DEC __CONFIG B'11111111110001';_CP_OFF&_WDT_OFF&_PWRITE_ON&_XT_OSC RTCC EQU 01H ;定义各寄存器 PC EQU 02H STATUS EQU 03H C EQU 0 RP0 EQU 5 ;---------------------- PORTA EQU 05H PORTB EQU 06H TRISA EQU 5H TRISB EQU 6H ;----------------------- SOUNDDELAY1 EQU 10H ;声音频率变化计数器,从1.8~3.55KHZ FRE_COUNT EQU 11H ;同一频率的重复次数保存地址 FRE_REPEAT EQU 12H SOUND_TEMP EQU 13H TEMP EQU 14H ;暂存寄存器 S_LOOP EQU 46 ;93-47=46 S_MAX EQU 93 ;最低频率1.8K 93*3=280US*2 S_MIN EQU 47 ;最高频率3.55K 47*3=140*2 S_REPEAT EQU 4 ;同一频率重复次数 ;----------------------RA KEY1 EQU 3 KEY2 EQU 4 ;----------------------RB KEY3 EQU 0 KEY4 EQU 1 ;-------------------- ORG 0000H MAIN CLRF PORTA CLRF PORTB ;初始化IO口 BSF STATUS,RP0 MOVLW 0011000B MOVWF TRISA MOVLW 00000011B MOVWF TRISB BCF STATUS,RP0 LOOP BTFSS PORTA,KEY1 ;扫描按键 GOTO SET_1 BTFSS PORTA,KEY2 GOTO SET_2 GOTO LOOP ;-------------------------------------------- SET_1 BTFSC PORTA,KEY1 ;去抖动 GOTO LOOP CALL SOUNDDELAY BTFSC PORTA,KEY1 ;按S2叫两声 GOTO LOOP CALL SOUND200MS CALL SOUND200MS GOTO LOOP ;-------------------------------------------- SET_2 BTFSC PORTA,KEY2 ;去抖动 GOTO LOOP CALL SOUNDDELAY BTFSC PORTA,KEY2 ;按S3叫15秒 GOTO LOOP CALL SOUND15S GOTO LOOP ;- - ---------------------------------------- SOUND200MS MOVLW S_LOOP MOVWF FRE_COUNT ;46=93-47 SOUND_LH_LP MOVLW S_REPEAT ;同一频率重复次数送FRE_REPEAT MOVWF FRE_REPEAT MOVFW FRE_COUNT ADDLW S_MIN ;计数值加最小值 MOVWF TEMP REPEAT0_LP MOVFW TEMP BSF PORTA,0 CALL SOUNDDELAY0 ;廷时W*3US BCF PORTA,0 MOVFW TEMP CALL SOUNDDELAY0 DECFSZ FRE_REPEAT,1 ;每四次减频率计数一次 GOTO REPEAT0_LP DECFSZ FRE_COUNT,1 GOTO SOUND_LH_LP SOUND_HL MOVLW S_LOOP MOVWF FRE_COUNT ;46=93-47 SOUND_HL_LP MOVLW S_REPEAT ;同一频率重复次数送FRE_REPEAT MOVWF FRE_REPEAT MOVFW FRE_COUNT SUBLW S_MAX ;最大值减计数值 MOVWF TEMP REPEAT1_LP MOVFW TEMP BSF PORTA,0 CALL SOUNDDELAY0 ;廷时W*3US BCF PORTA,0 MOVFW TEMP CALL SOUNDDELAY0 DECFSZ FRE_REPEAT,1;四次减频率计数一次 GOTO REPEAT1_LP DECFSZ FRE_COUNT,1 GOTO SOUND_HL_LP SOUND_END RETLW 0 ;------------------------------ SOUNDDELAY: ;廷时255*3US+2US MOVLW 255 SOUNDDELAY0 MOVWF SOUNDDELAY1 ;廷时W*3US+1US SOUNDDELAYUS_1 DECFSZ SOUNDDELAY1,1 GOTO SOUNDDELAYUS_1 RETLW 0 ;--------------------- SOUND15S ;报警15秒 MOVLW 73 MOVWF SOUND_TEMP SOUND1S_LP CALL SOUND200MS BTFSS PORTB,KEY4 ;按S5退出 RETLW 0 DECFSZ SOUND_TEMP,1 GOTO SOUND1S_LP RETLW 0 ;------------------------ END |
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/) | Powered by Discuz! X3.2 |