Кодовый замок
Скачать 2.31 Mb.
|
1 2 Описание схемы: Выше представлена функциональная схема проектируемого устройства. Устройство управляется микроконтроллером PIC16F676. Контроллер сканирует подключенную к его портам клавиатуру по определенному принципу и в случае нажатой клавиши анализирует код нажатой клавиши (который складывается из номера строки и столбца) запуская по его значению определенные процедуры. 5. Разработка рабочей программы 5.1 Текст программы #DEFINE CONFIG_REQ 1 LIST P = 16F676, F = INHX8M, W = 2, X = ON, R = DEC, MM = ON, N = 0, C = 255 INDF EQU 0X0000 TMR0 EQU 0X0001 PCL EQU 0X0002 STATUS EQU 0X0003 FSR EQU 0X0004 PORTA EQU 0X0005 PORTB EQU 0X0006 PORTC EQU 0X0007 PCLATH EQU 0X000A INTCON EQU 0X000B PIR1 EQU 0X000C TMR1L EQU 0X000E TMR1LH EQU 0X000F TMR1H EQU 0X000F T1CON EQU 0X0010 CMCON EQU 0X0019 ADRESLH EQU 0X001E ADRESH EQU 0X001E ADCON0 EQU 0X001F OPTION_REG EQU 0X0081 TRISA EQU 0X0085 TRISB EQU 0X0086 TRISC EQU 0X0087 PIE1 EQU 0X008C PCON EQU 0X008E OSCCAL EQU 0X0090 ANSEL EQU 0X0091 WPU EQU 0X0095 WPUA EQU 0X0095 IOC EQU 0X0096 IOCA EQU 0X0096 VRCON EQU 0X0099 EEDATL EQU 0X009A EEDATA EQU 0X009A EEDAT EQU 0X009A EEADR EQU 0X009B EECON1 EQU 0X009C EECON2 EQU 0X009D ADRESL EQU 0X009E ADCON1 EQU 0X009F IRP=7 RP1=6 RP0=5 NOT_TO=4 NOT_PD=3 Z=2 DC=1 C=0 GIE=7 PEIE=6 T0IE=5 INTE=4 RAIE=3 T0IF=2 INTF=1 RAIF=0 EEIF=7 ADIF=6 CMIF=3 T1IF=0 TMR1IF=0 TMR1GE=6 T1CKPS1=5 T1CKPS0=4 T1OSCEN=3 NOT_T1SYNC=2 TMR1CS=1 TMR1ON=0 COUT=6 CINV=4 CIS=3 CM2=2 CM1=1 CM0=0 ADFM=7 VCFG=6 CHS2=4 CHS1=3 CHS0=2 GO=1 NOT_DONE=1 GO_DONE=1 PP_GO_DONE=1 ADON=0 NOT_GPPU=7 NOT_RAPU=7 INTEDG=6 T0CS=5 T0SE=4 PSA=3 PS2=2 PS1=1 PS0=0 EEIE=7 ADIE=6 CMIE=3 T1IE=0 TMR1IE=0 NOT_POR=1 NOT_BOD=0 CAL5=7 CAL4=6 CAL3=5 CAL2=4 CAL1=3 CAL0=2 ANS7=7 ANS6=6 ANS5=5 ANS4=4 ANS3=3 ANS2=2 ANS1=1 ANS0=0 VREN=7 VRR=5 VR3=3 VR2=2 VR1=1 VR0=0 WRERR=3 WREN=2 PP_WREN=2 WR=1 PP_WR=1 RD=0 PP_RD=0 ADCS2=6 ADCS1=5 ADCS0=4 __MAXRAM 0XFF __BADRAM 0X06, 0X08-0X09, 0X0D, 0X11-0X18, 0X1A-0X1D, 0X60-0X7F __BADRAM 0X86, 0X88-0X89, 0X8D, 0X8F, 0X92-0X94, 0X97-0X98, 0XE0-0XFF CPD EQU 0X3EFF CPD_OFF EQU 0X3FFF CP EQU 0X3F7F CP_OFF EQU 0X3FFF BODEN EQU 0X3FFF BODEN_OFF EQU 0X3FBF MCLRE_ON EQU 0X3FFF MCLRE_OFF EQU 0X3FDF PWRTE_OFF EQU 0X3FFF PWRTE_ON EQU 0X3FEF WDT_ON EQU 0X3FFF WDT_OFF EQU 0X3FF7 LP_OSC EQU 0X3FF8 XT_OSC EQU 0X3FF9 HS_OSC EQU 0X3FFA EC_OSC EQU 0X3FFB INTRC_OSC_NOCLKOUT EQU 0X3FFC INTRC_OSC_CLKOUT EQU 0X3FFD EXTRC_OSC_NOCLKOUT EQU 0X3FFE EXTRC_OSC_CLKOUT EQU 0X3FFF #DEFINE __16F676 1 #DEFINE XTAL 4 #DEFINE _CORE 14 #DEFINE _MAXRAM 64 #DEFINE _RAM_END 64 #DEFINE _MAXMEM 1024 #DEFINE _ADC 8 #DEFINE _ADC_RES 10 #DEFINE _EEPROM 128 #DEFINE _PAGES 1 #DEFINE _BANKS 2 #DEFINE RAM_BANKS 1 #DEFINE _USART 0 #DEFINE _USB 0 #DEFINE _FLASH 0 #DEFINE _CWRITE_BLOCK 0 #DEFINE BANK0_START 32 #DEFINE BANK0_END 95 #DEFINE _SYSTEM_VARIABLE_COUNT 14 RAM_BANK = 0 CURRENT@PAGE = 0 DEST@PAGE = 0 #DEFINE LCD#TYPE 0 F@CALL MACRO DEST IF (DEST < 1) ELSE IF (DEST > $) ELSE ENDIF ENDIF CALL DEST ENDM F@JUMP MACRO DEST IF (DEST < 1) ELSE IF (DEST > $) ELSE ENDIF ENDIF GOTO DEST ENDM SET@PAGE MACRO DEST ENDM S@B MACRO VARIN IF((VARIN & 384) == 0) IF(RAM_BANK == 1) BCF 3,5 ENDIF IF(RAM_BANK == 2) BCF 3,6 ENDIF IF(RAM_BANK == 3) BCF 3,5 BCF 3,6 ENDIF RAM_BANK = 0 ENDIF IF((VARIN & 384) == 128) IF(RAM_BANK == 0) BSF 3,5 ENDIF IF(RAM_BANK == 2) BSF 3,5 BCF 3,6 ENDIF IF(RAM_BANK == 3) BCF 3,6 ENDIF RAM_BANK = 1 ENDIF IF((VARIN & 384) == 256) IF(RAM_BANK == 0) BSF 3,6 ENDIF IF(RAM_BANK == 1) BCF 3,5 BSF 3,6 ENDIF IF(RAM_BANK == 3) BCF 3,5 ENDIF RAM_BANK = 2 ENDIF ENDM R@B MACRO IF((RAM_BANK & 1) != 0) BCF 3,5 ENDIF IF((RAM_BANK & 2) != 0) BCF 3,6 ENDIF RAM_BANK = 0 ENDM JUMP MACRO PLABEL GOTO PLABEL ENDM WREG_BYTE MACRO PBYTEOUT S@B PBYTEOUT MOVWF PBYTEOUT R@B ENDM WREG_BIT MACRO PVAROUT,PBITOUT S@B PVAROUT ANDLW 1 BTFSC STATUS,2 BCF PVAROUT,PBITOUT BTFSS STATUS,2 BSF PVAROUT,PBITOUT R@B ENDM WREG_WORD MACRO PWORDOUT S@B PWORDOUT MOVWF PWORDOUT S@B PWORDOUT+1 CLRF PWORDOUT+1 R@B ENDM WREG_DWORD MACRO PDWORDOUT S@B PDWORDOUT+3 CLRF PDWORDOUT+3 S@B PDWORDOUT+2 CLRF PDWORDOUT+2 S@B PDWORDOUT+1 CLRF PDWORDOUT+1 S@B PDWORDOUT MOVWF PDWORDOUT R@B ENDM BYTE_WREG MACRO PBYTEIN S@B PBYTEIN MOVF PBYTEIN,W R@B ENDM NUM_WREG MACRO PNUMIN MOVLW (PNUMIN & 255) ENDM NUM_BYTE MACRO PNUMIN,PBYTEOUT S@B PBYTEOUT IF(PNUMIN == 0) CLRF PBYTEOUT ELSE MOVLW (PNUMIN & 255) MOVWF PBYTEOUT ENDIF R@B ENDM NUM_BIT MACRO PNUMIN,PVAROUT,PBITOUT S@B PVAROUT IF((PNUMIN & 1) == 1) BSF PVAROUT,PBITOUT ELSE BCF PVAROUT,PBITOUT ENDIF R@B ENDM NUM_WORD MACRO PNUMIN,PWORDOUT IF((PNUMIN & 255) == 0) S@B PWORDOUT CLRF PWORDOUT ELSE S@B PWORDOUT MOVLW LOW (PNUMIN) MOVWF PWORDOUT ENDIF IF(((PNUMIN >> 8) & 255) == 0) S@B PWORDOUT+1 CLRF PWORDOUT+1 ELSE S@B PWORDOUT+1 MOVLW HIGH (PNUMIN) MOVWF PWORDOUT+1 ENDIF R@B ENDM NUM_DWORD MACRO PNUMIN,PDWORDOUT IF ((PNUMIN >> 24 & 255) == 0) S@B PDWORDOUT+3 CLRF PDWORDOUT+3 ELSE S@B PDWORDOUT+3 MOVLW ((PNUMIN >> 24) & 255) MOVWF PDWORDOUT+3 ENDIF IF( ((PNUMIN >> 16) & 255) == 0) S@B PDWORDOUT+2 CLRF PDWORDOUT+2 ELSE S@B PDWORDOUT+2 MOVLW ((PNUMIN >> 16) & 255) MOVWF PDWORDOUT+2 ENDIF IF( ((PNUMIN >> 8) & 255) == 0) S@B PDWORDOUT+1 CLRF PDWORDOUT+1 ELSE S@B PDWORDOUT+1 MOVLW HIGH (PNUMIN) MOVWF PDWORDOUT+1 ENDIF IF((PNUMIN & 255) == 0) S@B PDWORDOUT CLRF PDWORDOUT ELSE S@B PDWORDOUT MOVLW LOW (PNUMIN) MOVWF PDWORDOUT ENDIF R@B ENDM BIT_WREG MACRO PVARIN,PBITIN S@B PVARIN CLRW BTFSC PVARIN,PBITIN MOVLW 1 R@B ENDM BIT_BYTE MACRO PVARIN,PBITIN,PBYTEOUT S@B PVARIN CLRW BTFSC PVARIN,PBITIN MOVLW 1 S@B PBYTEOUT MOVWF PBYTEOUT R@B ENDM BIT_BIT MACRO PVARIN,PBITIN,PVAROUT,PBITOUT IF((PVARIN & 65408) == (PVAROUT & 65408)) S@B PVAROUT BTFSC PVARIN,PBITIN BSF PVAROUT,PBITOUT BTFSS PVARIN,PBITIN BCF PVAROUT,PBITOUT ELSE S@B PVARIN CLRDC BTFSC PVARIN,PBITIN SETDC S@B PVAROUT SKPNDC BSF PVAROUT,PBITOUT SKPDC BCF PVAROUT,PBITOUT ENDIF ENDM BIT_WORD MACRO PVARIN,PBITIN,PWORDOUT S@B PWORDOUT+1 CLRF PWORDOUT+1 BIT_BYTE PVARIN,PBITIN,PWORDOUT ENDM BIT_DWORD MACRO PVARIN,PBITIN,PDWORDOUT S@B PDWORDOUT+3 CLRF PDWORDOUT+3 S@B PDWORDOUT+2 CLRF PDWORDOUT+2 S@B PDWORDOUT+1 CLRF PDWORDOUT+1 BIT_BYTE PVARIN,PBITIN,PDWORDOUT ENDM WORD_WREG MACRO PWORDIN BYTE_WREG PWORDIN ENDM WORD_BYTE MACRO PWORDIN,PBYTEOUT BYTE_BYTE PWORDIN,PBYTEOUT ENDM WORD_BIT MACRO PWORDIN,PVAROUT,PBITOUT BYTE_BIT PWORDIN, PVAROUT, PBITOUT ENDM WORD_WORD MACRO PWORDIN,PWORDOUT S@B PWORDIN+1 MOVF PWORDIN+1,W S@B PWORDOUT+1 MOVWF PWORDOUT+1 BYTE_BYTE PWORDIN,PWORDOUT ENDM WORD_DWORD MACRO PWORDIN,PDWORDOUT S@B PDWORDOUT+3 CLRF PDWORDOUT+3 S@B PDWORDOUT+2 CLRF PDWORDOUT+2 BYTE_BYTE PWORDIN+1,PDWORDOUT+1 BYTE_BYTE PWORDIN,PDWORDOUT ENDM BYTE_BYTE MACRO PBYTEIN,PBYTEOUT S@B PBYTEIN MOVF PBYTEIN,W S@B PBYTEOUT MOVWF PBYTEOUT R@B ENDM BYTE_WORD MACRO PBYTEIN,PWORDOUT S@B PWORDOUT+1 CLRF PWORDOUT+1 BYTE_BYTE PBYTEIN,PWORDOUT ENDM BYTE_DWORD MACRO PBYTEIN,PDWORDOUT S@B PDWORDOUT+3 CLRF PDWORDOUT+3 S@B PDWORDOUT+2 CLRF PDWORDOUT+2 S@B PDWORDOUT+1 CLRF PDWORDOUT+1 BYTE_BYTE PBYTEIN,PDWORDOUT ENDM BYTE_BIT MACRO PBYTEIN,PVAROUT,PBITOUT IF((PBYTEIN & 65408) == (PVAROUT & 65408)) S@B PBYTEIN BTFSC PBYTEIN,0 BSF PVAROUT,PBITOUT BTFSS PBYTEIN,0 BCF PVAROUT,PBITOUT ELSE S@B PBYTEIN RRF PBYTEIN,W S@B PVAROUT SKPNC BSF PVAROUT,PBITOUT SKPC BCF PVAROUT,PBITOUT ENDIF R@B ENDM DWORD_WREG MACRO PDWORDIN BYTE_WREG PDWORDIN ENDM DWORD_BYTE MACRO PDWORDIN,PBYTEOUT BYTE_BYTE PDWORDIN,PBYTEOUT ENDM DWORD_WORD MACRO PDWORDIN,PWORDOUT S@B PDWORDIN+1 MOVF PDWORDIN+1,W S@B PWORDOUT+1 MOVWF PWORDOUT+1 BYTE_BYTE PDWORDIN,PWORDOUT ENDM DWORD_DWORD MACRO PDWORDIN,PDWORDOUT BYTE_BYTE PDWORDIN+3,PDWORDOUT+3 BYTE_BYTE PDWORDIN+2,PDWORDOUT+2 BYTE_BYTE PDWORDIN+1,PDWORDOUT+1 BYTE_BYTE PDWORDIN,PDWORDOUT ENDM DWORD_BIT MACRO PDWORDIN,PVAROUT,PBITOUT BYTE_BIT PDWORDIN,PVAROUT,PBITOUT ENDM VARIABLE CURRENT@PAGE = 0 VARIABLE PDESTINATION@PAGE = 0 FIND@PAGE MACRO PLABELIN LOCAL CURRENT_ADDR = $ LOCAL DEST_ADDR = PLABELIN IF((CURRENT_ADDR >= 0X1800) && (CURRENT_ADDR <= 0X2000)) CURRENT@PAGE = 3 ENDIF IF((CURRENT_ADDR >= 0X1000) && (CURRENT_ADDR <= 0X1800)) CURRENT@PAGE = 2 ENDIF IF((CURRENT_ADDR >= 0X0800) && (CURRENT_ADDR <= 0X1000)) CURRENT@PAGE = 1 ENDIF IF((CURRENT_ADDR >= 0) && (CURRENT_ADDR <= 0X0800)) CURRENT@PAGE = 0 ENDIF IF((DEST_ADDR >= 0X1800) && (DEST_ADDR <= 0X2000)) PDESTINATION@PAGE = 3 ENDIF IF((DEST_ADDR >= 0X1000) && (DEST_ADDR <= 0X1800)) PDESTINATION@PAGE = 2 ENDIF IF((DEST_ADDR >= 0X0800) && (DEST_ADDR <= 0X1000)) PDESTINATION@PAGE = 1 ENDIF IF((DEST_ADDR >= 0) && (DEST_ADDR <= 0X0800)) PDESTINATION@PAGE = 0 ENDIF ENDM NUM_FSR MACRO PNUMIN NUM_BYTE PNUMIN, FSR IF (((PNUMIN >> 8) & 255) == 1) BSF STATUS,7 ELSE BCF STATUS,7 ENDIF ENDM LABEL_WORD MACRO PLABELIN,PWORDOUT MOVLW LOW (PLABELIN) S@B PWORDOUT MOVWF PWORDOUT MOVLW HIGH (PLABELIN) S@B PWORDOUT MOVWF PWORDOUT+1 R@B ENDM GEN3H = 32 GEN4 = 33 GEN4H = 34 GPR = 35 PBP#VAR0 = 36 PP0 = 37 PP0H = 38 PP1 = 39 PP1H = 40 PP3 = 41 PP3H = 42 PP6 = 43 PP6H = 44 SP#P9 = 45 KEYPASS = 46 VARIABLE KEYPASS#0=46,KEYPASS#1=47,KEYPASS#2=48 MKEY = 49 VARIABLE MKEY#0=49,MKEY#1=50,MKEY#2=51 _B#VR1 = 52 KEY = 53 SEC = 54 _I = 55 #DEFINE RAW1 PORTA,0 #DEFINE RAW2 PORTA,1 #DEFINE RAW3 PORTA,2 #DEFINE RAW4 PORTA,3 #DEFINE COL1 PORTA,4 #DEFINE COL2 PORTA,5 #DEFINE COL3 PORTC,0 #DEFINE LED1 PORTC,4 #DEFINE LED2 PORTC,5 #DEFINE LEDPOD PORTC,3 #DEFINE FLAG _B#VR1,0 #DEFINE FLAG1 _B#VR1,1 PROTON#CODE#START ORG 0 GOTO PROTON#MAIN#START T@GTB CLRF 38 T@GTW CLRF 40 T@GT MOVWF 39 MOVLW 1 T@ST MOVWF 35 MOVF 40,W SUBWF 38,W SKPZ GOTO $ + 3 MOVF 39,W SUBWF 37,W MOVLW 4 SKPNC MOVLW 1 SKPNZ MOVLW 2 ANDWF 35,W SKPZ MOVLW 1 GOTO I@NT EE@RD BSF 3,5 MOVWF 155 EE@RD@W BSF 3,5 BSF 156,PP_RD MOVF 154,W INCF 155,F GOTO I@NT EE@WR EE@WR@W BSF 3,5 MOVWF 154 BSF 156,PP_WREN MOVLW 85 MOVWF 157 MOVLW 170 MOVWF 157 BSF 156,PP_WR BTFSC 156,PP_WR GOTO $ - 1 BCF 156,PP_WREN INCF 155,F GOTO I@NT DL@MS CLRF 40 DLY@W MOVWF 39 DLY@P MOVLW 255 ADDWF 39,F SKPC ADDWF 40,F SKPC GOTO I@NT MOVLW 3 MOVWF 38 MOVLW 223 CALL DLUS@W GOTO DLY@P DL@US CLRF 38 DLUS@W ADDLW 232 MOVWF 37 COMF 38,F MOVLW 252 SKPC GOTO $ + 4 ADDWF 37,F SKPNC GOTO $ - 2 ADDWF 37,F NOP INCFSZ 38,F GOTO $ - 6 BTFSC 37,0 GOTO $ + 1 BTFSS 37,1 GOTO $ + 3 NOP GOTO $ + 1 RETURN I@NT BCF 3,7 I@NT2 BCF 3,5 BCF 3,6 RETURN PROTON#MAIN#START F2_SOF EQU $ ; ZAM_676.PRP F2_EOF EQU $ ; ZAM_676.PRP F1_SOF EQU $ ; ZAM_676.BAS F1_000009 EQU $ ; IN [ZAM_676.BAS] ALL_DIGITAL = TRUE MOVLW 7 MOVWF CMCON BSF STATUS,5 RAM_BANK = 1 CLRF ANSEL F1_000010 EQU $ ; IN [ZAM_676.BAS] INPUT PORTA.0: INPUT PORTA.1: INPUT PORTA.2: INPUT PORTA.3 BSF TRISA,0 BSF TRISA,1 BSF TRISA,2 BSF TRISA,3 F1_000011 EQU $ ; IN [ZAM_676.BAS] OUTPUT PORTA.4: OUTPUT PORTA.5: OUTPUT PORTA.6: OUTPUT PORTC BCF TRISA,4 BCF TRISA,5 BCF TRISA,6 CLRF TRISC F1_000029 EQU $ ; IN [ZAM_676.BAS] KEY = 0 BCF STATUS,5 RAM_BANK = 0 CLRF KEY F1_000030 EQU $ ; IN [ZAM_676.BAS] FLAG = 1 BSF _B#VR1,0 F1_000031 EQU $ ; IN [ZAM_676.BAS] FLAG1 = 0 BCF _B#VR1,1 F1_000032 EQU $ ; IN [ZAM_676.BAS] KEYPASS[0] = EREAD 0 MOVLW 0 CALL EE@RD MOVWF PBP#VAR0 MOVF PBP#VAR0,W MOVWF KEYPASS#0 F1_000033 EQU $ ; IN [ZAM_676.BAS] KEYPASS[1] = EREAD 1 MOVLW 1 CALL EE@RD MOVWF PBP#VAR0 MOVF PBP#VAR0,W MOVWF KEYPASS#1 F1_000034 EQU $ ; IN [ZAM_676.BAS] KEYPASS[2] = EREAD 2 MOVLW 2 CALL EE@RD MOVWF PBP#VAR0 MOVF PBP#VAR0,W MOVWF KEYPASS#2 F1_000035 EQU $ ; IN [ZAM_676.BAS] MKEY[0] =1: MKEY[1] =7: MKEY[2] =8 MOVLW 1 MOVWF MKEY#0 MOVLW 7 MOVWF MKEY#1 MOVLW 8 MOVWF MKEY#2 MAIN F1_000038 EQU $ ; IN [ZAM_676.BAS] GOSUB KLAVA CALL KLAVA F1_000039 EQU $ ; IN [ZAM_676.BAS] IF KEY = 35 THEN MOVLW 35 SUBWF KEY,W BTFSS STATUS,2 GOTO BC@LL2 F1_000040 EQU $ ; IN [ZAM_676.BAS] GOTO USTKEY GOTO USTKEY GOTO BC@LL3 BC@LL2 F1_000041 EQU $ ; IN [ZAM_676.BAS] ELSE F1_000042 EQU $ ; IN [ZAM_676.BAS] FLAG = 1 BSF _B#VR1,0 F1_000043 EQU $ ; IN [ZAM_676.BAS] GOSUB PROVERKA CALL PROVERKA F1_000044 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL3 F1_000045 EQU $ ; IN [ZAM_676.BAS] GOTO MAIN GOTO MAIN USTKEY F1_000048 EQU $ ; IN [ZAM_676.BAS] HIGH LEDPOD: HIGH LED2:KEY=0 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,3 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,5 CLRF KEY F1_000049 EQU $ ; IN [ZAM_676.BAS] DELAYMS 3000:LOW LED2:DELAYMS 1000: HIGH LED2 MOVLW 11 MOVWF PP1H MOVLW 184 CALL DLY@W BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,5 MOVLW 3 MOVWF PP1H MOVLW 232 CALL DLY@W BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,5 F1_000050 EQU $ ; IN [ZAM_676.BAS] IF FLAG = 1 THEN BTFSS _B#VR1,0 GOTO BC@LL5 F1_000051 EQU $ ; IN [ZAM_676.BAS] FOR I=0 TO 2 CLRF _I FR@LB7 MOVLW 3 SUBWF _I,W BTFSC STATUS,0 GOTO NX@LB8 F1_000052 EQU $ ; IN [ZAM_676.BAS] WHILE KEY = 0 BC@LL8 MOVF KEY,F BTFSS STATUS,2 GOTO BC@LL9 F1_000053 EQU $ ; IN [ZAM_676.BAS] GOSUB KLAVA CALL KLAVA F1_000054 EQU $ ; IN [ZAM_676.BAS] DELAYMS 200 MOVLW 200 CALL DL@MS F1_000055 EQU $ ; IN [ZAM_676.BAS] WEND GOTO BC@LL8 BC@LL9 F1_000056 EQU $ ; IN [ZAM_676.BAS] EWRITE I ,[ KEY ] MOVF _I,W BSF STATUS,5 RAM_BANK = 1 MOVWF EEADR BCF STATUS,5 RAM_BANK = 0 MOVF KEY,W CALL EE@WR F1_000057 EQU $ ; IN [ZAM_676.BAS] LOW LED2: DELAYMS 100: HIGH LED2 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,5 MOVLW 100 CALL DL@MS BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,5 F1_000058 EQU $ ; IN [ZAM_676.BAS] KEYPASS[I] = KEY MOVF _I,W ADDLW KEYPASS MOVWF FSR MOVF KEY,W MOVWF INDF F1_000059 EQU $ ; IN [ZAM_676.BAS] KEY = 0 CLRF KEY F1_000060 EQU $ ; IN [ZAM_676.BAS] NEXT I INCF _I,F BTFSS STATUS,2 GOTO FR@LB7 NX@LB8 F1_000061 EQU $ ; IN [ZAM_676.BAS] DELAYMS 1000 MOVLW 3 MOVWF PP1H MOVLW 232 CALL DLY@W F1_000062 EQU $ ; IN [ZAM_676.BAS] FLAG = 0 BCF _B#VR1,0 F1_000063 EQU $ ; IN [ZAM_676.BAS] LOW LED2: LOW LEDPOD BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,5 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,3 F1_000064 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL5 F1_000065 EQU $ ; IN [ZAM_676.BAS] GOTO MAIN GOTO MAIN PROVERKA F1_000068 EQU $ ; IN [ZAM_676.BAS] FLAG1 = 0: SEC=0:I = 0 BCF _B#VR1,1 CLRF SEC CLRF _I F1_000069 EQU $ ; IN [ZAM_676.BAS] FOR I=0 TO 2 CLRF _I FR@LB11 MOVLW 3 SUBWF _I,W BTFSC STATUS,0 GOTO NX@LB12 F1_000070 EQU $ ; IN [ZAM_676.BAS] WHILE KEY = 0 BC@LL12 MOVF KEY,F BTFSS STATUS,2 GOTO BC@LL13 F1_000071 EQU $ ; IN [ZAM_676.BAS] GOSUB KLAVA CALL KLAVA F1_000072 EQU $ ; IN [ZAM_676.BAS] DELAYMS 200 MOVLW 200 CALL DL@MS F1_000073 EQU $ ; IN [ZAM_676.BAS] SEC=SEC+1 INCF SEC,F F1_000074 EQU $ ; IN [ZAM_676.BAS] IF I>0 AND SEC>30 THEN MOVF _I,W MOVWF PP0 MOVLW 0 CALL T@GTB MOVWF SP#P9 MOVF SEC,W MOVWF PP0 MOVLW 30 CALL T@GTB ANDWF SP#P9,F BTFSC STATUS,2 GOTO BC@LL15 F1_000075 EQU $ ; IN [ZAM_676.BAS] HIGH LED2: DELAYMS 100: LOW LED2: LOW LEDPOD :I = 0 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,5 MOVLW 100 CALL DL@MS BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,5 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,3 CLRF _I F1_000076 EQU $ ; IN [ZAM_676.BAS] GOTO MAIN GOTO MAIN F1_000077 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL15 F1_000078 EQU $ ; IN [ZAM_676.BAS] WEND GOTO BC@LL12 BC@LL13 F1_000080 EQU $ ; IN [ZAM_676.BAS] HIGH LEDPOD BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,3 F1_000081 EQU $ ; IN [ZAM_676.BAS] IF FLAG1 = 0 THEN BTFSC _B#VR1,1 GOTO BC@LL17 F1_000082 EQU $ ; IN [ZAM_676.BAS] IF KEYPASS[I] <> KEY AND MKEY[I]<>KEY THEN MOVF _I,W ADDLW KEYPASS MOVWF FSR MOVF INDF,W MOVWF PBP#VAR0 MOVF PBP#VAR0,W SUBWF KEY,W BTFSS STATUS,2 MOVLW 1 MOVWF SP#P9 MOVF _I,W ADDLW MKEY MOVWF FSR MOVF INDF,W MOVWF PBP#VAR0 MOVF PBP#VAR0,W SUBWF KEY,W BTFSS STATUS,2 MOVLW 1 ANDWF SP#P9,F BTFSC STATUS,2 GOTO BC@LL19 F1_000083 EQU $ ; IN [ZAM_676.BAS] FLAG1 = 1 BSF _B#VR1,1 F1_000084 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL19 F1_000085 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL17 F1_000086 EQU $ ; IN [ZAM_676.BAS] KEY = 0 CLRF KEY F1_000087 EQU $ ; IN [ZAM_676.BAS] HIGH LED2: DELAYMS 100: LOW LED2 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,5 MOVLW 100 CALL DL@MS BSF STATUS,5 RAM_BANK = 1 BCF TRISC,5 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,5 F1_000088 EQU $ ; IN [ZAM_676.BAS] NEXT I INCF _I,F BTFSS STATUS,2 GOTO FR@LB11 NX@LB12 F1_000089 EQU $ ; IN [ZAM_676.BAS] IF FLAG1 = 0 THEN BTFSC _B#VR1,1 GOTO BC@LL21 F1_000090 EQU $ ; IN [ZAM_676.BAS] LOW LEDPOD BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,3 F1_000091 EQU $ ; IN [ZAM_676.BAS] HIGH LED1 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,4 BCF STATUS,5 RAM_BANK = 0 BSF PORTC,4 F1_000092 EQU $ ; IN [ZAM_676.BAS] DELAYMS 2000 MOVLW 7 MOVWF PP1H MOVLW 208 CALL DLY@W F1_000093 EQU $ ; IN [ZAM_676.BAS] LOW LED1 BSF STATUS,5 RAM_BANK = 1 BCF TRISC,4 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,4 F1_000095 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL21 F1_000096 EQU $ ; IN [ZAM_676.BAS] LOW LEDPOD BSF STATUS,5 RAM_BANK = 1 BCF TRISC,3 BCF STATUS,5 RAM_BANK = 0 BCF PORTC,3 F1_000097 EQU $ ; IN [ZAM_676.BAS] RETURN RETURN KLAVA F1_000100 EQU $ ; IN [ZAM_676.BAS] KEY = 0 CLRF KEY F1_000101 EQU $ ; IN [ZAM_676.BAS] COL1 = 1 BSF PORTA,4 F1_000102 EQU $ ; IN [ZAM_676.BAS] IF RAW1 = 1 THEN BTFSS PORTA,0 GOTO BC@LL23 F1_000103 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000104 EQU $ ; IN [ZAM_676.BAS] KEY = 1 MOVLW 1 MOVWF KEY F1_000105 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL23 F1_000106 EQU $ ; IN [ZAM_676.BAS] IF RAW2 = 1 THEN BTFSS PORTA,1 GOTO BC@LL25 F1_000107 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000108 EQU $ ; IN [ZAM_676.BAS] KEY = 4 MOVLW 4 MOVWF KEY F1_000109 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL25 F1_000110 EQU $ ; IN [ZAM_676.BAS] IF RAW3 = 1 THEN BTFSS PORTA,2 GOTO BC@LL27 F1_000111 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000112 EQU $ ; IN [ZAM_676.BAS] KEY = 7 MOVLW 7 MOVWF KEY F1_000113 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL27 F1_000114 EQU $ ; IN [ZAM_676.BAS] IF RAW4 = 1 THEN BTFSS PORTA,3 GOTO BC@LL29 F1_000115 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000116 EQU $ ; IN [ZAM_676.BAS] KEY = 42 MOVLW 42 MOVWF KEY F1_000117 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL29 F1_000118 EQU $ ; IN [ZAM_676.BAS] COL1 = 0 BCF PORTA,4 F1_000119 EQU $ ; IN [ZAM_676.BAS] COL2 = 1 BSF PORTA,5 F1_000120 EQU $ ; IN [ZAM_676.BAS] IF RAW1 = 1 THEN BTFSS PORTA,0 GOTO BC@LL31 F1_000121 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000122 EQU $ ; IN [ZAM_676.BAS] KEY = 2 MOVLW 2 MOVWF KEY F1_000123 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL31 F1_000124 EQU $ ; IN [ZAM_676.BAS] IF RAW2 = 1 THEN BTFSS PORTA,1 GOTO BC@LL33 F1_000125 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000126 EQU $ ; IN [ZAM_676.BAS] KEY = 5 MOVLW 5 MOVWF KEY F1_000127 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL33 F1_000128 EQU $ ; IN [ZAM_676.BAS] IF RAW3 = 1 THEN BTFSS PORTA,2 GOTO BC@LL35 F1_000129 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000130 EQU $ ; IN [ZAM_676.BAS] KEY = 8 MOVLW 8 MOVWF KEY F1_000131 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL35 F1_000132 EQU $ ; IN [ZAM_676.BAS] IF RAW4 = 1 THEN BTFSS PORTA,3 GOTO BC@LL37 F1_000133 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000134 EQU $ ; IN [ZAM_676.BAS] KEY = 10 MOVLW 10 MOVWF KEY F1_000135 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL37 F1_000136 EQU $ ; IN [ZAM_676.BAS] COL2 = 0 BCF PORTA,5 F1_000137 EQU $ ; IN [ZAM_676.BAS] COL3 = 1 BSF PORTC,0 F1_000138 EQU $ ; IN [ZAM_676.BAS] IF RAW1 = 1 THEN BTFSS PORTA,0 GOTO BC@LL39 F1_000139 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000140 EQU $ ; IN [ZAM_676.BAS] KEY = 3 MOVLW 3 MOVWF KEY F1_000141 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL39 F1_000142 EQU $ ; IN [ZAM_676.BAS] IF RAW2 = 1 THEN BTFSS PORTA,1 GOTO BC@LL41 F1_000143 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000144 EQU $ ; IN [ZAM_676.BAS] KEY = 6 MOVLW 6 MOVWF KEY F1_000145 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL41 F1_000146 EQU $ ; IN [ZAM_676.BAS] IF RAW3 = 1 THEN BTFSS PORTA,2 GOTO BC@LL43 F1_000147 EQU $ ; IN [ZAM_676.BAS] DELAYMS 100 MOVLW 100 CALL DL@MS F1_000148 EQU $ ; IN [ZAM_676.BAS] KEY = 9 MOVLW 9 MOVWF KEY F1_000149 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL43 F1_000150 EQU $ ; IN [ZAM_676.BAS] IF RAW4 = 1 THEN BTFSS PORTA,3 GOTO BC@LL45 F1_000151 EQU $ ; IN [ZAM_676.BAS] DELAYMS 200 MOVLW 200 CALL DL@MS F1_000152 EQU $ ; IN [ZAM_676.BAS] IF RAW4 = 1 THEN BTFSS PORTA,3 GOTO BC@LL47 F1_000153 EQU $ ; IN [ZAM_676.BAS] DELAYMS 500 MOVLW 1 MOVWF PP1H MOVLW 244 CALL DLY@W F1_000154 EQU $ ; IN [ZAM_676.BAS] KEY = 35 MOVLW 35 MOVWF KEY F1_000155 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL47 F1_000156 EQU $ ; IN [ZAM_676.BAS] ENDIF BC@LL45 F1_000157 EQU $ ; IN [ZAM_676.BAS] COL3 = 0 BCF PORTC,0 F1_000158 EQU $ ; IN [ZAM_676.BAS] RETURN RETURN F1_EOF EQU $ ; ZAM_676.BAS PB@LB49 GOTO PB@LB49 __EOF __CONFIG CPD_OFF&CP_OFF&BODEN&MCLRE_OFF&PWRTE_OFF&WDT_OFF&INTRC_OSC_NOCLKOUT END 5.2 Моделирование Для моделирования описанного кодового замка была использована программа разработки электрических схем Proteus 7 Professional. Для того чтобы смоделировать наше устройство потребовались следующие компоненты Proteus:
После правильного соединения элементов между собой и их настойки, устанавливаем файл прошивки (ZAM_676.hex) к контроллеру в его свойствах. Теперь можно пытаться симулировать работу собранного устройства. 6. Заключение В данной работе была осуществлена разработка кодового замка. В ходе выполнения работы был проведён анализ задачи, на основе которого были сформулированы требования к конечной системе. На основе требований была построена структурная схема. На основании структурной схемы были подобраны соответствующие устройства для реализации функций, возложенных на элементы системы. Исходя из экономических и эксплуатационных соображений, для данного устройства был выбран микроконтроллер PIC16F676. Особенностью данного замка является наличие световой индикации, оповещающей владельца о правильности ввода кода. Далее, с использованием выбранных устройств была построена функциональная схема. Разработка завершилась составлением блок-схемы алгоритма и написанием исходного кода программы для микроконтроллера. При выполнении данного курсового проекта были получены новые и закреплены старые знания в области микроконтроллеров, разработки программ на языке высокого уровня, моделировании схем устройств. 7. Список литературы 1. Описания электронных компонентов в каталоге товаров оптовой базы комплектации электронных компонентов и приборов “ПЛАТАН”: http://www.platan.ru/ 2. Описание электромеханического замка ПОЛИС-13: http://dialog-universal.ru/product_info.php?cPath=109&products_id=173 3. Описание клавиатуры AK-207 на сайте компании Accord: http://www.accordia.com.tw/html/general.htm 4. Описание микроконтроллера AT89S51 на сайте компании Atmel: http://www.atmel.com/dyn/resources/prod_documents/doc2487.pdf 5. Описание микроконтроллера AT89S51: http://www.gaw.ru/html.cgi/txt/ic/Atmel/micros/mcs51/at89s51.htm 6. В.Б. Бродин. Микроконтроллеры: архитектура, программирование, интерфейс: – М.: ЭКОМ, 1999. 7. П. Хоровиц, У. Хилл. Искусство схемотехники М. Мир, 2003. 1 2 |