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

📄 密码锁.asm

📁 一些常用的波形生成程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;*******************************************************************
;                  程序名称:电子密码锁                             *
;                  程序编写:datazyb                                *
;                  E-mail:datazyb_007@163.com                      *
;                  程序最后检查日期:2004.8.20                      *
;                  程序性质:个人作品                               *
;*******************************************************************
;程序声明:这个代码仅仅供个人使用,请不要用于商业用途!!!

;The CPU is 6M ,and I use at24c02 to save the password!
data_full_FLAG       BIT     07H
equal_flag           bit     08h
universal_counter    equ     18h
counter_1            equ     19h
counter_2            equ     1ah

   ORG 0000H
   SJMP MAIN
   ORG 000BH
   AJMP INSERS0
   ORG 001BH
   AJMP INSERS1 
;*****************************************************
;          Main program
;*****************************************************
      org  0030h
MAIN:                       
      mov  sp,#30h                               ;set the sp stack
      lcall del260ms                ;wait the power is level off!!!
      clr   error_flag              ;
      PUSH  PSW
      SETB  PSW.4
      CLR   PSW.3                                ;USE the second group registers
      MOV R0,#60H                                ;RAM's address
      MOV R1,#08H                                ;eeprom's address
      MOV R2,#8                                  ;bytes=n
      LCALL RD_BYTES                              ;Read data from  eeprom
      POP   PSW
      JB error_flag,k1                            ;if eeprom error,jump to process
       ljmp    k2
k1:   ljmp error_pro                              ;if read fail ,go to wrong process
;*************************************************************************
k2:  lcall del260ms                      ;*******wait some time ********
     push  psw                           ;Read 60h~6fh successfully! and we go on reading 70h~7fh!!!
     setb  psw.4
     clr   psw.3
     mov   r0,#70h
     mov   r1,#0f0h
     mov   r2,#8
     lcall RD_BYTES
     pop   psw
     jb    error_flag,k3
     ljmp  k4
k3:  ljmp  error_pro
k4:  LCALL DATA_0FFH_CHECK           ;Read sucessfully! and judge if all data  is 0ffh and rewrite password!
     JB   data_full_flag,k5
     ljmp k9 
k5:  ljmp  k8                           
k9:  ;check 60h~6fh data is equal to 70h~7fh data 
     lcall  data_compare
     jb     equal_flag,k10
     ljmp   k8                       ;password is not availability,and rewrite the password
;*********************************************************************************************
k10: push psw
     setb psw.4
     clr  psw.3
     mov  r0,#70h
     mov  r1,#08h
     lcall RD_BYTES
     pop  psw
     jb   error_flag,s1
     ljmp s2    
s1:  ljmp error_pro
s2:  ljmp  start                     ;read successfully! and begin to enter main programme
;*********************************************************************************************
k8:                                  ;now the eeprom is new,and I write password to eeprom                         
     CLR P3.5
     CLR P3.7
     LCALL DEL260MS
     SETB P3.5
     SETB P3.7
     LCALL DEL260MS
     CLR P3.5
     CLR P3.7
     LCALL DEL260MS
     SETB P3.5
     SETB P3.7
     LCALL DEL260MS
     CLR P3.5
     CLR P3.7
    LCALL DEL260MS
    SETB P3.5
    SETB P3.7
    LCALL DEL260MS
     MOV 70H,#1
     MOV 71H,#2
     MOV 72H,#3
     MOV 73H,#4
     MOV 74H,#5
     MOV 75H,#6
     MOV 76H,#7
     MOV 77H,#8
;***************************************
; now save the password
    lcall save_pwd
;***************************************
START: MOV TMOD,#10H
       MOV TH0,#00H
       MOV TL0,#00H
       MOV TH1,#3CH
       MOV TL1,#0B0H
       MOV IP,#08H               
       SETB EA
       SETB ET1
       SETB TR1
       MOV 56H,#64H             ;10s counter
       SETB 06H                 ;Set the flag
       MOV SP,#30H              ;set the stack
       MOV R3,#03H              ;3 time input limit		
ADDR0: MOV R0,#60H
       MOV R4,#00H
LINE0:PUSH PSW
      LCALL KEY
      POP PSW
      MOV R5,A                 ;save key_word to R5.
      CLR P3.5
      LCALL DEL100MS                  ;Key sound
      SETB P3.5
      CLR 06H                         ;Clean the flag
      CJNE R5,#0EH,ADDR1
      LCALL CLR_BUF
      SJMP ADDR0
ADDR1:CJNE R5,#0FH,POT1
      SJMP POT0
POT1: AJMP ADDR2
POT0: LCALL PWD_CHECK
      JB F0,ADDR3
      SJMP ADDR4
ADDR3:CLR P3.5                   ;OK sound
      CLR P3.4
      LCALL DEL260MS
      LCALL DEL260MS
      SETB P3.4
      SETB P3.5
;******************************************************************************
      CLR   P3.0                   ;***********open the mimasuo!!!!************
      mov   universal_counter,#8
dd_loop:
      lcall del260ms
      djnz  universal_counter,dd_loop
      setb  p3.0                   ;close mimasuo port
;*******************************************************************************
ADDR5:PUSH PSW
      LCALL KEY
      POP PSW
      MOV R5,A
      CLR P3.5                   ;Key sound
      LCALL DEL100MS              
      SETB P3.5
      CLR 06H                     ;Clean the flag
      CJNE R5,#0DH,ADDR5        
      SETB ET0
      SETB TR0
      MOV R2,#10                ;controll the chengse led blink rate!!!
      CLR P3.3                   ;open chengse led
      LCALL SET_PWD              ;set the password.
      CLR ET0
      CLR TR0
      SETB P3.3                  ;close chengse led
      AJMP START
;******************************************************
ADDR4:CLR P3.7                   ;input error!!!
      CLR P3.5
      LCALL DEL260MS
      LCALL DEL260MS
      SETB P3.7
      SETB P3.5
      DJNZ R3,ADDR0               ;judge if more than 3 times
      CLR P3.7                    ;More than three times.
      CLR P3.5
      LCALL DEL260MS
      LCALL DEL260MS
      LCALL DEL260MS
      LCALL DEL260MS              ;Delay 1S
      SETB P3.5
      SETB P3.7
      CLR EA                       ;close all interrupt !!!                
alarm:
      mov  universal_counter,#60   ;alarm !!!
ddd_loop:
      clr   beep
      clr   R_LED
      lcall del260ms
      setb  beep
      setb  R_LED
      lcall del260ms
      djnz  universal_counter,ddd_loop

;***************************************************
      MOV P3,#0FFH                ;Shut down all the outputs
      MOV PCON,#02H               ;The CPU go to sleep

;******************************************************
;    the folowing programme is to save input to RAM.
;******************************************************
ADDR2:MOV A,R5
      MOV @R0,A
      INC R0
      INC R4
      CJNE R4,#10H,L0      ;Password protect
      LJMP START
L0:   LJMP LINE0    
;  ****************************************************
;            Key_scan
;  ****************************************************
KEY:   SETB PSW.3
       MOV P1,#0FH               ;Key scan
       MOV A,P1
       ANL A,#0FH
       CJNE A,#0FH,KEY1
       SJMP KEY            
 KEY1: MOV P3,#0BFH
       LCALL DEL12
       MOV A,#0EFH
 KEY2: MOV R2,A
       MOV P1,A
       MOV A,P1
       ANL A,#0FH
       CJNE A,#0FH,KEY3
       MOV A,R2
       SETB C
       RLC A
       JC KEY2
       SJMP KEY
 KEY3: MOV B,#0FBH
 KEY4: RRC A
       INC B
       JC KEY4
       MOV A,R2
       SWAP A
 KEY5: RRC A
       INC B
       INC B
       INC B
       INC B
       JC KEY5
 KEY6: MOV A,P1
       ANL A,#0FH
       CJNE A,#0FH,KEY6
       LCALL DEL12
       MOV A,B
       RET 
;**************************************************
;               Delay10ms
;***************************************************
DEL12: MOV R6,#0AH     ;Delay10ms
LOOP1: MOV R7,#0FAH
LOOP2: DJNZ R7,LOOP2
       DJNZ R6,LOOP1
       RET
;******************************************************
;           CLR_BUF
;******************************************************
CLR_BUF: MOV R6,#08H 
         MOV R1,#60H
LOOP:    MOV @R1,#00H
         INC R1
         DJNZ R6,LOOP
        RET
;*******************************************************
;            Password check
;*******************************************************
PWD_CHECK:MOV R0,#60H
          MOV R1,#70H
          CLR C
          MOV F0,C
       CJNE R4,#08H,ADDR21
ADDR20:MOV A,@R0
       MOV 50H,@R1
       CJNE A,50H,ADDR21
       INC R0
       INC R1
       DJNZ R4,ADDR20
       SETB C
       MOV F0,C
ADDR21:NOP
       RET
;******************************************************
;           Set password
;******************************************************
SET_PWD:MOV  R3,#03H
LINE1:  MOV R0,#60H
        MOV R4,#00H
BEGIN:  PUSH PSW
        LCALL KEY
        POP PSW
        MOV R5,A
        CLR P3.5
        LCALL DEL100MS               ;Key sound
        SETB P3.5
        CLR 06H                       ;Clean the flag
        CJNE R5,#0EH,ADDR7
        LCALL CLR_BUF
        AJMP LINE1
ADDR7:  CJNE R5,#0FH,POT2
        SJMP POT3
POT2:   MOV A,R5
        MOV @R0,A
        INC R0
        INC R4
        CJNE R4,#10H,L1       ;Password protect
        RET
L1:     SJMP BEGIN
POT3:   LCALL PWD_CHECK
        JB F0,POT6
        SJMP ADDR10
POT6:   SJMP ADDR9
ADDR10: CLR P3.5
        CLR P3.7
        LCALL DEL260MS
        LCALL DEL260MS
        SETB P3.5
        SETB P3.7
        DJNZ R3,LINE1
        CLR P3.7
        CLR P3.5
        LCALL DEL260MS
        LCALL DEL260MS
        LCALL DEL260MS
        LCALL DEL260MS
        SETB P3.7
        SETB P3.5
        RET         
ADDR9:  CLR P3.4
        CLR P3.5
        LCALL DEL260MS
        LCALL DEL260MS
        LCALL DEL260MS
        LCALL DEL260MS
        SETB P3.4
        SETB P3.5
ADDR11: MOV R0,#60H
        MOV R4,#00H
L3:     PUSH PSW
        LCALL KEY
        POP PSW
        MOV R5,A
        CLR P3.5
        LCALL DEL100MS                 ;Key sound
        SETB P3.5
        CLR 06H                        ;Clean the flag
        CJNE R5,#0EH,ADDR12
        LCALL CLR_BUF
        SJMP ADDR11
ADDR12: CJNE R5,#0FH,POT4
        SJMP POT5
POT4:   MOV A,R5
        MOV @R0,A
        INC R0
        INC R4
        CJNE R4,#10H,L2
        RET              ;Password protect
L2:     SJMP L3
;************************************************************
;     save password to RAM
;***********************************************************
POT5:   MOV R1,#70H
        MOV R0,#60H
        CJNE R4,#08H,L4  ;Jump the password whether 8 bit.
ADDR14: MOV A,@R0
        MOV @R1,A
        INC R0
        INC R1
        DJNZ R4,ADDR14
ADDR15: lcall save_pwd
L4:        RET
;  ***************************************************
;       T0 INT Process
;  ***************************************************
INSERS0:
       MOV TL0,#00H
       MOV TH0,#00H
       DJNZ R2,NO
       MOV R2,#10     ;counter
       CPL P3.3       ;chengse led
NO:    RETI 
;*******************************************************
;        T1 INT Process(100ms timer)
;*******************************************************
INSERS1:
        MOV TH1,#3CH
        MOV TL1,#0B0H
        DJNZ 56H,A0
        MOV 56H,#64H
        JB 06H,A1          ;Flag
        SETB 06H
	  RETI
A1:   MOV P3,#0FFH         ;Shut down all outputs
      MOV PCON,#02H        ;The CPU go to sleep 	 
          RETI
A0:       RETI             ;Time is not enough ,and return!
;*********************************************************
;        Delay50ms
;*********************************************************
DEL50MS:MOV R6,#32H

⌨️ 快捷键说明

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