打印
[PIC®/AVR®/dsPIC®产品]

pic单片机警报声源程序

[复制链接]
297|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lzmm|  楼主 | 2023-5-26 09:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1脚为电源端接5V电源,8脚接地, 4脚为控制端,暂不用.2,6,7脚为警音
        控制端,按下S1、S2、S3可发出不同的警音
       5脚为音频输出端,当停止音频输出时,该脚置低;
电路原理图如下:
#include<p12f629.inc>       ;
#include <pic12f629.inc>
    __config 0x3F4C ;_CPC_ON & _CPU_ON & _CPP_ON & _PWRTE_OFF & _WDT_ON & _FOSC_HS ; 0x3F4C

; RAM-Variable

CSR1         equ 0x20
CSR2        equ 0x21
STATUS_TEMP equ 0x2C
PCL_TEMP equ 0x2D
DE_TIME1 equ 0x22
DE_TIME0 equ 0x23
DE_TIME2 equ 0x24
DE_TIME3 equ 0x25
TIME_TMP0 equ 0x26
TIME_TMP1 equ 0x27
SOUND_D_TIME0 equ 0x28
SOUND_D_TIME1 equ 0x29
DE_TMEP0 equ 0x2A
DE_TMEP1 equ 0x2B
CON_SOUND equ 0x55
SOUND_B_TIME0 equ 0x56
SOUND_B_TIME1 equ 0x57
SOUND_D_TIME2 equ 0x58
CON_A_STAY equ 0x59
TR0_TIME equ 0x5A
SOUND_C_TIME1 equ 0x5B
SOUND_D_TIME3 equ 0x5C
SOUND_C_TIME0 equ 0x5D
W_TEMP equ 0x5E

; Program

    Org 0x0000

;   Reset-Vector
    GOTO MAIN

    Org 0x0004

;   Interrupt-Vector
    MOVWF W_TEMP
    SWAPF STATUS,W
    BCF STATUS,RP0      
    MOVWF STATUS_TEMP
    MOVF PCLATH,W      
    MOVWF PCL_TEMP
    GOTO Interrupt_0
Interrupt_0
    BTFSC INTCON,T0IF
    BTFSS INTCON,T0IE
    GOTO Interrupt_exit
    MOVF TR0_TIME,W
    ADDWF TMR0,F         
    MOVLW 0x04
    BCF INTCON,T0IF
    BSF CON_SOUND,2
        XORWF GPIO,F
    CLRWDT
Interrupt_exit
    MOVF PCL_TEMP,W
    MOVWF PCLATH         
    SWAPF STATUS_TEMP,W
    MOVWF STATUS
    SWAPF W_TEMP,F
    SWAPF W_TEMP,W
    RETFIE
;*****************************************
RAM_00
    MOVLW 0x49
    MOVWF CSR1
    MOVLW 0x21
    MOVWF CSR2
MAIN_RAM
    INCF CSR2,F
    MOVF CSR2,W
    MOVWF FSR
    CLRF INDF
    DECFSZ CSR1,F
    GOTO MAIN_RAM     
    CLRF CSR2
    RETURN

MAIN
    CALL RAM_00

    BSF STATUS,RP0      
    ;CALL LADR_0x03FF
    ;MOVWF SFR_0x10      
    CLRF STATUS
    MOVLW 0xA7
    CLRF SOUND_B_TIME0
    CLRF SOUND_B_TIME1
    CLRF SOUND_D_TIME2
    CLRF CON_A_STAY
    CLRF TR0_TIME
    CLRF SOUND_C_TIME1
    MOVWF SOUND_D_TIME3
    MOVLW 0xFE
    MOVWF SOUND_C_TIME0
    CLRF STATUS

    MOVLW 0x58
    MOVWF TIME_TMP0
    MOVLW 0x02
    MOVWF TIME_TMP1
    ;CALL DELAY_0
    MOVLW 0x07
    MOVWF CMCON ;SFR_0x19       ; !!Warning: SFR_0x19 is Unimplemented
    MOVLW 0x81
    BSF STATUS,RP0      
    MOVWF TMR0         
    MOVLW 0x3B  ;0x3B
    MOVWF GPIO  ;PORTA         
    BCF STATUS,RP0      
    CLRF GPIO  ;PORTA         
    BSF INTCON,GIE
    CLRF GPIO   ;PORTA         
    GOTO SEARCH_KEY

WHILE_0
    BTFSS CON_SOUND,5
    GOTO WHILE_1
    BCF CON_SOUND,0
    CALL LADR_0x0154

SEARCH_KEY
    CLRWDT
    BCF STATUS,RP0      
    BTFSC GPIO  ,4        ;BTFSC GPIO  ,4   ;PORTA,4         
    GOTO SOUND_A_0
    BTFSC   GPIO,5      
    GOTO SOUND_B_0
    BTFSC GPIO,0   ;PORTA,0      
    GOTO SOUND_C_0
    BTFSC GPIO,1  ;  PORTA,1      
    GOTO SOUND_D_0
    BTFSS GPIO   ,1   ;PORTA,1      
    GOTO WHILE_0

   


WHILE_1

    CLRF GPIO   ;PORTA         
    MOVLW 0xA7
    BCF INTCON,T0IE
    BCF CON_SOUND,5
    BCF CON_SOUND,0
    MOVWF SOUND_D_TIME3
    BCF GPIO,2   ;   PORTA,2         
    GOTO SEARCH_KEY


;********************************
SOUND_A_0
    BTFSC CON_SOUND,0
    GOTO SOUND_A_1
    BSF INTCON,T0IE
    BSF CON_SOUND,0
    BCF CON_SOUND,5
SOUND_A_1
    CALL SOUND_A_2
    GOTO SEARCH_KEY

SOUND_A_2
    BSF STATUS,RP0      
    MOVF TMR0,W         
    XORLW 0x81
    BTFSC STATUS,Z
    GOTO SOUND_A_3
    MOVLW 0x81
    MOVWF TMR0           
SOUND_A_3
    BCF STATUS,RP0      
    BTFSS CON_SOUND,2
    RETURN
    BCF CON_SOUND,2
    INCFSZ CON_A_STAY,F
    GOTO SOUND_A_5
SOUND_A_EXIT
    MOVLW 0x3B
    MOVWF TR0_TIME
    RETURN

SOUND_A_5
    MOVLW 0x02
    SUBWF CON_A_STAY,W
    BTFSC STATUS,C
    GOTO SOUND_A_6
SOUND_A_51
    MOVLW 0x76
    MOVWF TR0_TIME
    RETURN
SOUND_A_6
    MOVLW 0x03
    SUBWF CON_A_STAY,W
    BTFSC STATUS,C
    GOTO SOUND_A_7
SOUND_A_61
    MOVLW 0x8F
    MOVWF TR0_TIME
    RETURN
SOUND_A_7
    MOVLW 0x04
    SUBWF CON_A_STAY,W
    BTFSC STATUS,C
    GOTO SOUND_A_8
SOUND_A_71
    MOVLW 0x94
    MOVWF TR0_TIME
    RETURN
SOUND_A_8
    MOVLW 0x05
    SUBWF CON_A_STAY,W
    BTFSC STATUS,C
    GOTO SOUND_A_9
SOUND_A_81
    MOVLW 0xA3
    MOVWF TR0_TIME
    RETURN
SOUND_A_9
    MOVLW 0x06
    SUBWF CON_A_STAY,W
    BTFSS STATUS,C
    GOTO SOUND_A_81
    MOVLW 0x07
    SUBWF CON_A_STAY,W
    BTFSS STATUS,C
    GOTO SOUND_A_71
    MOVLW 0x08
    SUBWF CON_A_STAY,W
    BTFSS STATUS,C
    GOTO SOUND_A_61
    MOVLW 0x09
    SUBWF CON_A_STAY,W
    BTFSS STATUS,C
    GOTO SOUND_A_51
    CLRF CON_A_STAY
    GOTO SOUND_A_EXIT



;********************************
SOUND_B_0
    BTFSC CON_SOUND,0
    GOTO SOUND_B_1
    BSF INTCON,T0IE
    BSF CON_SOUND,0
    BCF CON_SOUND,5
    CLRF SOUND_B_TIME0
    CLRF SOUND_B_TIME1
SOUND_B_1
    CALL SOUND_B_2
    GOTO SEARCH_KEY


SOUND_B_2
    BSF STATUS,RP0      
    MOVF TMR0,W         
    XORLW 0x81
    BTFSC STATUS,Z
    GOTO SOUND_B_3
    MOVLW 0x81
    MOVWF TMR0           
SOUND_B_3
    BCF STATUS,RP0      
    BTFSS CON_SOUND,1
    GOTO SOUND_B_5
    MOVLW 0x66
    MOVWF TR0_TIME
    BTFSS CON_SOUND,2
    RETURN
    BCF CON_SOUND,2
    INCF SOUND_B_TIME0,F
    BTFSC STATUS,Z
    INCF SOUND_B_TIME1,F
    DECF SOUND_B_TIME1,W
    MOVLW 0x90
SOUND_B_4
    BTFSC STATUS,Z
    XORWF SOUND_B_TIME0,W
    BTFSS STATUS,Z
    RETURN
    MOVLW 0x02
    CLRF SOUND_B_TIME0
    CLRF SOUND_B_TIME1
        XORWF CON_SOUND,F
    RETURN
SOUND_B_5
    MOVLW 0x85


使用特权

评论回复
沙发
pzsh| | 2023-9-18 20:22 | 只看该作者
汇编语言,厉害

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

401

主题

8818

帖子

11

粉丝