⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alarm.txt

📁 电话报警系统的51单片机程序
💻 TXT
📖 第 1 页 / 共 4 页
字号:
我这有个次方面的程序,大家可参考!


   ORG  0000H
   LJMP main
   org 000bh
   ljmp time0
   org 001bh
   ljmp time1
  
           ORG 0013H
           lJMP INTPT1  
  
    ORG 0020H
                                
           provision_3    bit p1.0
           mute           bit p1.1
           p_warning      bit p1.2
           p_relax        bit p1.3
           p_guard        bit p1.4
           provision_1    bit p1.5
           provision_2    bit p1.6                     
           switch         bit p1.7
           ON_LINE        BIT p2.0
           dtmf_ce        bit p2.1
           seg_dat        bit p2.2
           seg_clk        bit p2.3
           dtmf_clk       bit p2.4
           dtmf_dat       bit p2.5
           p_record       bit p2.6
           p_play         bit p2.7
           p_int0         bit p3.2
           p_int1         bit p3.3
           p_localwarning bit p3.4
           p_beep         bit p3.5  
           SDA            bit P3.6
           SCL            bit P3.7
    leavehand      bit 12h
    right          bit 11h  
           relax_flag     bit 10H
           LED7           bit 0EH
           LED6           bit 0DH
           LED5           bit 0CH
           LED4           bit 0BH        ;play
           LED3           bit 0AH        ;warning
           LED2           bit 09H        ;preset
           LED1           bit 08H        ;guard
           ACK            BIT 07H      ;应答标志位变量
  
           a_flag          bit 00h
           time_out1       bit 01h 
           firstflag1      bit 02h 
           time_out        bit 03h 
           valid1          bit 04h
           keyflag         bit 05h
           valid           bit 06h

           BITBUF          EQU 21H
           addresspoint    equ 31h  ;已存电话个数 
           position        equ 53h  ;IIC中电话的位置
    max             equ 05h  ;能最多存的个数        ;?????????????????????????
    length_pw       equ 04h  ;密码长度        4
    times_pw        equ 01h  ;最多输入次数     3 
    count2          equ 60h  ;5a~5d 为密码缓存
    count1          equ 61h
                         MTD             EQU 63H
                         MRD             EQU 62H

main:
   CPL P3.6
   CLR EA 
   MOV TMOD,#11H
   mov ip,#0ah           ;定时器  0优先级最高
   mov scon,#10h         ;方式0
   setb ex1              ;设防
     mov th0,#3ch         ;10MS
     mov tl0,#0b0h
     mov th1,#3ch          ;100ms
     mov tl1,#0b0h
   clr  IT1 
   SETB ET0
   setb et1
                        CLR ES

    mov p0,#0ffh   
    mov p1,#0ffh   
    mov p2,#7eh   
    mov p3,#0efh   
   
   MOV A,#00H
   MOV B,A 
   MOV R0,#00H
CLR_RAM:
   MOV @R0,A
   INC R0
   CJNE R0,#80H,CLR_RAM

                        setb firstflag1

    mov sp,#65h   
                        mov position,#40h
   mov addresspoint,#01h       ;电话个数
   MOV 3AH,#00H  ;电话表指针
                        MOV 37H,#01H
   mov 54h,#0ffh
   mov 55h,#10h
   mov 56h,#10h
   mov 57h,#10h
   mov 58h,#10h
   
   mov 59h,#00h  

                               JnB switch,RD_VALID000     ;跳线
          MOV 30H,#16
          LCALL delay5ms
          JnB switch,RD_VALID000
          MOV 30H,#16
          LCALL delay5ms
          JnB switch,RD_VALID000
          lcall clrEEPR0M
RD_VALID000:
                               lcall rd_valid      ;////// 读取valid \\                               
    setb ea

;============================ 关显示 ==============================
MAIN1:           CPL P3.6
   mov a,#10h 
   lcall disp_seg 

   jb relax_flag,relax1 

                 MOV 21H,#0FFH
   CLR LED1
                 MOV A,21H
   mov sbuf,a
                 jnb ti,$
                        clr ti
relax1: 
   mov 30h,#40
   lcall delay5ms

   SETB EA       
                 MOV 37H,#01h
   mov 3fh,#01h
                 nop
   nop
   nop
   nop

      lcall save_valid

     jNB p_relax,NEXT111 ;撤防 
     MOV 30H,#10
     LCALL delay5ms
     JNB p_relax,NEXT111
     MOV 30H,#10
     LCALL delay5ms
     JNB p_relax,NEXT111
     lcall handfree
     clr ex1
     setb relax_flag 
        MOV 21H,#0FFH
     mov a,21H
     mov sbuf,a
     jnb ti,$
     clr ti

NEXT111:
     jNB p_guard,NEXT110   ;设防
     MOV 30H,#10
     LCALL delay5ms
     JNB p_guard,NEXT110 
     MOV 30H,#10
     LCALL delay5ms
     JNB p_guard,NEXT110
      lcall beep
     setb ex1
     clr  relax_flag
NEXT110:     

            jNB p_warning,NEXT1   ;响铃?      
     MOV 30H,#10
     LCALL delay5ms
     JNB p_warning,NEXT1 
     MOV 30H,#10
     LCALL delay5ms
     JNB p_warning,NEXT1
     SETB ie1       ;进入中断1;-----------------------------
        nop
     nop

;=====================================================================================
NEXT1:                         JnB switch,store_no      ;跳线
          MOV 30H,#16
          LCALL delay5ms
          JnB switch,store_no
          MOV 30H,#16
          LCALL delay5ms
          JnB switch,store_no
          lcall clrEEPR0M

store_no:

                              lcall findkey
                              jnb keyflag,main22
;=======================================================
                              jnb valid,enter0
                              jnb valid1,next4 ;受限用户
             
enter0:
                              mov a,54h              ; 键值保存于54H

         cjne a,#0ah,enter

         jnb time_out1,enter1

         clr valid1
                              lcall beeplong
                              nop
                              nop
                              nop
         lcall beeplong
         clr time_out1 
main22:

    ljmp main1             ;退出密嘛状态  
enter1:        

           
    lcall getpw                                    
         nop
         nop

         ljmp main1
enter:       
    
                              CJNE A,#0CH,next2         ;store        
                              jnb firstflag1,modify  

                              Lcall STORE
         nop
         nop


                              ljmp main1

modify:  

         lcall L91  
                              setb ea
                              nop
                              nop

                                LJMP MAIN1
NEXT2: 
   CJNE A,#0BH,NEXT4   ;RECOR

                        LCALL RECORD
   nop
                        nop
 
                        LJMP MAIN1

NEXT3:

NEXT4:
                            CJNE A,#0DH,NEXT5    ;SCAN_UP

                              LCALL scan_up

                            mov a,#10h 
         lcall disp_seg 
                              MOV 21H,#0FFH
                        CLR LED1
                              MOV A,21H
                      mov sbuf,a
                       jnb ti,$
                            clr ti
                                
                     nop
                            nop

                             LJMP MAIN1

NEXT5:
                            CJNE A,#0FH,next6     ;PLAY

                              setb ea
                              LCALL PLAY
         nop
                              nop
MAIN222:

                                LJMP MAIN1
next6:            
         JNB valid,main222
                    jb  valid1,main222

         lcall testpw

                              LJMP MAIN1
;-------------------------------------------------
getpw:        


         clr right 
                              mov count1,#00
                              mov position,#5ah
                          
         mov 58h,#0fh
                              mov 57h,#10h
                              mov 56h,#10h
                              mov 55h,#10h
                              mov 54h,#0ffh 
         mov 59h,#00h
         lcall beep             ;????????????????????
                              
p92:
         setb ea   
                              clr time_out
         mov 7eh,#0
         mov 7fh,#0
         setb tr0
p92_1:
         lcall disp                   ;显示
                              lcall findkey
                              
                              jb keyflag,p61
                              jb time_out,p92_3  
           ljmp p92_1
p92_3:  
                              clr time_out                     
                              ljmp getpw_end

p61: 
                              clr tr0                         
                              clr c 
                              mov a,54h                
           subb a,#0ah
           jnc p_101 
          
                              mov a,position          
                              cjne a,#5eh,save_buffle0

                              ljmp getpw
save_buffle0:
                              mov r0,position        ;键值是09a之间
                              mov @r0,54h
                              inc position
          inc count1
         mov a,count1
         cjne a,#length_pw,p92
         setb right
                              ljmp p92                 
                                                         
p_101: 
                              mov a,54h
         clr c
                              subb a,#0ah
                              jz p_a
         mov 54h,#0ffh
         ljmp p92
p_a:
         mov position,#5ah
         mov count1,#0
                              
         inc count2
         jb right,p_3
         mov a,count2
         clr c
         subb a,#times_pw
         jz getpw_end
                              ljmp getpw 
p_3:                          clr right
         setb valid                   ;有密码
         setb valid1                  ;正处于密码状态 
                              lcall beep

           mov r6,#00       ;将缓存中的数存?;r6中存放页面首地址 
                              
wt_iic0:          
                              mov r0,position
                              mov a,@r0
                              mov 36h,a
wt_iic00:                   
                              mov a,36h
                              clr ea
                                MOV MTD,A                               
                     
          lcall IWRNBYTE                    
    NOP                             
       mov MRD,#51h
 LCALL  IRDNBYTE
       MOV A,MRD
         clr c
         subb a,36h                      ;保存r0
         jnz wt_iic00
                              inc r6
                              inc position
         mov a,position
         cjne a,#5eh,wt_iic0
                              setb ea
         mov position,#5ah
cmp:
                              mov r0,position
                              mov a,@r0
         clr c
         subb a,#0
         jnz getpw_end
          inc position
         mov a,position
         cjne a,#5eh,cmp

         clr valid 

getpw_end:
                 mov count2,#00
   mov a,#10h 
                      lcall disp_seg 
 
    setb ea 
                              ret  
;======================= 密码验证 ============================
testpw:                      
         clr ea
           mov r6,#00      ;将缓存中的数存?;r6中存放页面首地址 
         mov 36h,#24h
re_rd:
                         
       mov MRD,#51h
 LCALL  IRDNBYTE
 MOV A,MRD
         mov 3ch,a
         clr c
         subb a,#0ah
         jnc re_rd
         mov a,3ch
         mov r0,36h
         mov @r0,a
         inc 36h
         inc r6
         cjne r6,#04,re_rd
         setb ea
reapt:
         clr right 
                              mov count1,#00
                              mov position,#5ah

         mov 58h,#12h
                              mov 57h,#10h
                              mov 56h,#10h
                              mov 55h,#10h
         mov 59h,#00h
                              mov 54h,#0ffh
                              
tp92:
         setb ea   
                              clr time_out
               mov 7eh,#0
         mov 7fh,#0
         setb tr0
tp92_1:
         lcall disp                   ;显示
                              lcall findkey
                              
                              jb keyflag,tp61
                              jb time_out,tp92_3  
           ljmp tp92_1
tp92_3:  
                              clr time_out                     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -