Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;**** FIL OPLYSNINGER ******************************************************************
- ; Fil: LAB5_1.asm
- ; Dato: 8.September 2014
- ; Forfatter: Ib Refer
- ; Redigeret: Steen Heide
- ; ****** BESKRIVELSE **********************************************************************
- ; dette program anvender SDUboard.lib til at skrive til vores display
- ; Der skrives i første omgang tekster (string´s) ud til displayet
- ; ****** UDVIDELSER ***********************************************************************
- ; Udvidelser:
- ; 1: du skal ændre teksterne
- ; ****** Anvendte kommandoer **************************************************************
- ; String er en kommando, der er konstrueret som en macro i SDUboard.lib,
- ; den anbringer tegnene på hver sin memmory adresse så vi senere ved hjælp af
- ; strengens navn (msg) kan få skrevet strengens tegn ud på vores display
- ; LCDstr er en kommando, der er konstrueret som en macro i SDUboard.lib
- ; Den udskriver indholdet i en navngivet (msg) streng efter hinanden på displayet
- ; ******* PROCESSOR DEFINITIONER **********************************************************
- processor 16f877a ;Sets processor
- #include p16f877a.inc
- ; errorlevel -302 ;fjerner meddelser om forkerte banker fra fejl listen
- ; errorlevel -305 ;fjerner meddelser om forkerte banker fra fejl listen
- ; ******* COMPILER configuration bits *****************************************************
- __config _HS_OSC & _PWRTE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _LVP_OFF
- ; ******* DEFFINITION AF VARIABLE *********************************************************
- #include "SDUboard.var" ;Variable som bruges af SDUboard 0x79 - 0x7F)
- ;INDSÆT DINE VARIABLE HER (start med 0x20)
- ; ******* OPSÆTNING AF PROGRAM POINTERE ***************************************************
- org 0x0000 ;Programstart efter et reset
- GOTO init ;Gå til opsætning
- org 0x0005 ;Første position efter interrupt-vektor
- ; GOTO ISR
- Delay1 EQU 0x20
- Delay2 EQU 0x21
- Delay3 EQU 0x22
- RESULTAT EQU 0X23
- KEY equ 0x26
- KEY1 equ 0x27
- KEY2 equ 0x28
- KEY3 equ 0x29
- KEY4 equ 0x2A
- PassKey1 equ 0x2B
- PassKey2 equ 0x2C
- PassKey3 equ 0x2D
- PassKey4 equ 0x2E
- KEYCOUNT equ 0x2F
- LockStatus equ 0x30
- NewKeyStatus equ 0x31
- NEWKEYCOUNT equ 0x32
- TempPassKey equ 0x33
- StartMessage equ 0x34
- ; ******* INCLUDEREDE FILER ***************************************************************
- #Include "SDUboard.lib" ; SDU PICborad subroutine bibliotek.
- ; #Include "Delay.LIB" ; Tilføjer delay filen
- #Include "Transmitter.inc" ; Tilføjer Transmitter filen
- #Include "Reciever.inc" ; Tilføjer Reciever filen
- ; ******* INITIALISERING AF PROGRAM *****************************************************
- init CALL LCD_Init ; Initialiser LCD og indsæt DK-bogstaver (æøå)
- BCF STATUS,RP1 ; GÅR TIL BANK 1 }
- BSF STATUS,RP0 ; GÅR TIL BANK 1 }
- MOVLW b'00011111'
- MOVWF TRISC
- MOVLW b'00000000'
- MOVWF TRISB
- MOVLW b'00000000'
- MOVWF CMCON
- BCF STATUS,RP1 ; GÅR TIL BANK 0 }
- BCF STATUS,RP0 ; GÅR TIL BANK 0 }
- ;KODE = 2587
- MOVLW d'2'
- MOVWF PassKey1
- MOVLW d'5'
- MOVWF PassKey2
- MOVLW d'8'
- MOVWF PassKey3
- MOVLW d'7'
- MOVWF PassKey4
- MOVLW b'00000000'
- MOVWF KEY1
- MOVWF KEY2
- MOVWF KEY3
- MOVWF KEY4
- MOVWF KEY
- MOVWF KEYCOUNT
- BSF LockStatus,0
- BCF PORTB,0
- BCF PORTB,1
- BCF PORTB,2
- BCF NewKeyStatus,0 ; Midlertidiget bit der er sat under ny-kode
- ; ******* OPSÆT TRANSMITTER- / RECEIVERREGISTRE **********************************
- BSF STATUS,RP0 ; definer porte - start (bank1)
- CLRF TRISB ; lav port C til udgange
- BCF TRISC,6 ; RC6/TX/CK
- BSF TRISC,7 ; RC7/RX/DT
- BCF STATUS,RP0 ; definer porte - slut (bank0)
- CALL TRANSMITTERSETUP ; transmitter (Udkommenter RECIEVERSETUP)
- CALL RECIEVERSETUP ; reciever (Udkommenter TRANSMITTERSETUP)
- ; ******* HOVEDPROGRAM ********************************************************************
- main
- ; Send heartbeat
- MOVLW 0X30 ; Fly hexkoden for 0 til W
- CALL TRANSMITTER ; Send dataen fra W, ved at køre TRANSMITTER
- CALL Timeout4 ; Delay for at sikre tid nok til transmission
- CALL RECIEVER ; Tjek om PIC har modtaget data
- BTFSS StartMessage,0
- LCDstr welcomemsg
- BSF StartMessage,0
- BTFSC PORTC,4 ; Ny-kode ønsket
- CALL NewKeyTrigger
- BSF PORTB,4 ; Output0
- BSF PORTB,5 ; Output1
- BSF PORTB,6 ; Output2
- BTFSC PORTC,0 ; Input 0
- GOTO Row1
- BTFSC PORTC,1 ; Input 1
- GOTO Row2
- BTFSC PORTC,2 ; Input 2
- GOTO Row3
- BTFSC PORTC,3 ; Input 3
- GOTO Row4
- GOTO main
- Row1
- ;LCDstr row1
- BSF PORTB,4
- BCF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,0
- GOTO Key1Pressed
- BCF PORTB,4
- BSF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,0
- GOTO Key2Pressed
- BCF PORTB,4
- BCF PORTB,5
- BSF PORTB,6
- CALL Timeout2
- BTFSC PORTC,0
- GOTO Key3Pressed
- GOTO main
- Row2
- ;LCDstr row2
- BSF PORTB,4
- BCF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,1
- GOTO Key4Pressed
- BCF PORTB,4
- BSF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,1
- GOTO Key5Pressed
- BCF PORTB,4
- BCF PORTB,5
- BSF PORTB,6
- CALL Timeout2
- BTFSC PORTC,1
- GOTO Key6Pressed
- GOTO main
- Row3
- ;LCDstr row3
- BSF PORTB,4
- BCF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,2
- GOTO Key7Pressed
- BCF PORTB,4
- BSF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,2
- GOTO Key8Pressed
- BCF PORTB,4
- BCF PORTB,5
- BSF PORTB,6
- CALL Timeout2
- BTFSC PORTC,2
- GOTO Key9Pressed
- GOTO main
- Row4
- ;LCDstr row4
- BSF PORTB,4
- BCF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,3
- GOTO Key10Pressed
- BCF PORTB,4
- BSF PORTB,5
- BCF PORTB,6
- CALL Timeout2
- BTFSC PORTC,3
- GOTO Key11Pressed
- BCF PORTB,4
- BCF PORTB,5
- BSF PORTB,6
- CALL Timeout2
- BTFSC PORTC,3
- GOTO Key12Pressed
- GOTO main
- KeyPressed
- CALL Timeout ; Håndtér prel med en tidspildsrutine
- CALL ShiftKeys ; Ryk alle keys et "trin" ned
- INCF KEYCOUNT ; Inkrementér KeyCounteren
- BTFSC KEYCOUNT,2 ; Tjek om bit 2 i KEYCOUNTER er sat (Altså om den er 4 (Da den ikke kan blive større end 4))
- GOTO CodeEntered ; Hvis den er lig 4, udføres CodeEntered funktionen
- GOTO main
- CodeEntered
- BCF StartMessage,0 ;Geninizilatiser startbesked til LED
- MOVFW KEY1
- XORWF PassKey1,w
- BTFSS STATUS,Z ; Skip næste linje hvis Key1 og PassKey1 er ens
- GOTO WrongCode
- MOVFW KEY2
- XORWF PassKey2,w
- BTFSS STATUS,Z ; Skip næste linje hvis Key2 og PassKey2 er ens
- GOTO WrongCode
- MOVFW KEY3
- XORWF PassKey3,w
- BTFSS STATUS,Z ; Skip næste linje hvis Key3 og PassKey3 er ens
- GOTO WrongCode
- MOVFW KEY4
- XORWF PassKey4,w
- BTFSS STATUS,Z ; Skip næste linje hvis Key4 og PassKey4 er ens
- GOTO WrongCode
- GOTO CorrectCode
- WrongCode
- CALL ClearKeys
- CALL Timeout
- LCDstr wrongmsg
- BSF PORTB,1
- BCF PORTB,2
- CALL Timeout3
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- BCF PORTB,1
- BCF PORTB,2
- GOTO main ; TEMP LØSNING
- CorrectCode
- BTFSC LockStatus,0
- GOTO Unlock
- GOTO Lock
- Lock
- CALL ClearKeys
- CALL Timeout
- LCDstr lockmsg
- BCF PORTB,0
- BCF PORTB,1
- BSF PORTB,2
- BSF LockStatus,0
- CALL Timeout
- BCF PORTB,2
- CALL Timeout
- BSF PORTB,2
- CALL Timeout3
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- BCF PORTB,1
- BCF PORTB,2
- GOTO main ; TEMP LØSNING
- Unlock
- CALL ClearKeys
- CALL Timeout
- LCDstr unlockmsg
- BSF PORTB,0
- BCF PORTB,1
- BSF PORTB,2
- BCF LockStatus,0
- CALL Timeout3
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- BCF PORTB,1
- BCF PORTB,2
- GOTO main ; TEMP LØSNING
- ShiftKeys
- MOVF KEY2,w
- MOVWF KEY1
- MOVF KEY3,w
- MOVWF KEY2
- MOVF KEY4,w
- MOVWF KEY3
- MOVF KEY,w
- MOVWF KEY4
- RETURN
- ClearKeys
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- MOVLW b'00000000' ;Reset variabler
- MOVWF KEYCOUNT
- MOVWF KEY
- MOVWF KEY1
- MOVWF KEY2
- MOVWF KEY3
- MOVWF KEY4
- RETURN
- Key1Pressed
- MOVLW d'1'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'1'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key2Pressed
- MOVLW d'2'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'2'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key3Pressed
- MOVLW d'3'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'3'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key4Pressed
- MOVLW d'4'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'4'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key5Pressed
- MOVLW d'5'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'5'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key6Pressed
- MOVLW d'6'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'6'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key7Pressed
- MOVLW d'7'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'7'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key8Pressed
- MOVLW d'8'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'8'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key9Pressed
- MOVLW d'9'
- CALL CONV2ASCII
- CALL LCD_Data
- MOVLW d'9'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key10Pressed
- LCDstr hashtag
- MOVLW d'10'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key11Pressed
- MOVLW d'0'
- CALL CONV2ASCII
- CALL LCD_Data ; Printer tallet 0
- MOVLW d'11'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- Key12Pressed
- LCDstr star
- MOVLW d'12'
- BTFSC NewKeyStatus,0
- GOTO NewPass ; Der anmodes om en ny kode
- MOVWF KEY
- CALL KeyPressed
- CALL Timeout
- GOTO main
- NewKeyTrigger
- BSF NewKeyStatus,0 ; Ny-kode tjek bit sat
- BTFSS NewKeyStatus,1
- CALL InitializeNewKey
- BSF NewKeyStatus,1
- RETURN
- InitializeNewKey
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- CALL ClearKeys
- LCDstr newcodemsg
- RETURN
- NewPass
- MOVWF TempPassKey ; Flytter tallet trykket til TempPassKey
- CALL Timeout ; Håndterer prel
- INCF NEWKEYCOUNT
- MOVLW d'1'
- XORWF NEWKEYCOUNT,w
- BTFSC STATUS,Z ;Skipper ikke hvis det er første gang i NewPass
- GOTO MoveKey1
- MOVLW d'2'
- XORWF NEWKEYCOUNT,w
- BTFSC STATUS,Z ;Skipper ikke hvis det er anden gang i NewPass
- GOTO MoveKey2
- MOVLW d'3'
- XORWF NEWKEYCOUNT,w
- BTFSC STATUS,Z ;Skipper ikke hvis det er tredje gang i NewPass
- GOTO MoveKey3
- MOVLW d'4'
- XORWF NEWKEYCOUNT,w
- BTFSC STATUS,Z ;Skipper ikke hvis det er fjerde gang i NewPass
- GOTO MoveKey4
- GOTO main ;Backup, burde ikke køres
- MoveKey1
- MOVF TempPassKey,w ;Flytter tallet trykket til w
- MOVWF PassKey1 ;Flytter tallet trykket til PassKey1
- GOTO main
- MoveKey2
- MOVF TempPassKey,w ;Flytter tallet trykket til w
- MOVWF PassKey2 ;Flytter tallet trykket til PassKey2
- GOTO main
- MoveKey3
- MOVF TempPassKey,w ;Flytter tallet trykket til w
- MOVWF PassKey3 ;Flytter tallet trykket til PassKey3
- GOTO main
- MoveKey4
- MOVF TempPassKey,w ;Flytter tallet trykket til w
- MOVWF PassKey4 ;Flytter tallet trykket til PassKey4
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- BCF StartMessage,0 ;Geninizilatiser startbesked til LED
- LCDstr newcodeconfirmedmsg
- BSF PORTB,2
- CALL Timeout3
- MOVLW LCDCLR ; Flyt Clear til W registret
- CALL LCD_Reg ; Clear LCD
- BCF PORTB,2
- CLRF NEWKEYCOUNT ;Resseter NEWKEYCOUNT
- BCF NewKeyStatus,0 ;Resseter ny-kode tjek bitten
- BCF NewKeyStatus,1 ;Resseter ny-kode trigger bitten
- goto main
- Timeout
- MOVLW D'45' ; Tidsforsinkelse på ca. 450 ms
- MOVWF Delay3 ;
- Loop12 MOVLW D'115' ; h'73'= 115 tælles op <=> 255-115 =140 der tælles ned
- MOVWF Delay1 ;
- MOVLW D'32' ; h'DF'= 223 tælles op <=> 255-223 =32 der tælles ned
- MOVWF Delay2 ;
- Loop1 DECFSZ Delay1,F ;
- GOTO Loop1 ;
- MOVLW D'115' ;
- MOVWF Delay1 ;
- DECFSZ Delay2,F ;
- GOTO Loop1 ;
- DECFSZ Delay3,F ;
- GOTO Loop12 ;
- RETURN
- Timeout2
- MOVLW D'1' ; Tidsforsinkelse på ca. 10 ms
- MOVWF Delay3 ;
- Loop123 MOVLW D'115' ; h'73'= 115 tælles op <=> 255-115 =140 der tælles ned
- MOVWF Delay1 ;
- MOVLW D'32' ; h'DF'= 223 tælles op <=> 255-223 =32 der tælles ned
- MOVWF Delay2 ;
- Loop13 DECFSZ Delay1,F ;
- GOTO Loop13 ;
- MOVLW D'115' ;
- MOVWF Delay1 ;
- DECFSZ Delay2,F ;
- GOTO Loop13 ;
- DECFSZ Delay3,F ;
- GOTO Loop123 ;
- RETURN
- Timeout3
- MOVLW D'1000' ; Tidsforsinkelse på ca. 10000 ms
- MOVWF Delay3 ;
- Loop124 MOVLW D'115' ; h'73'= 115 tælles op <=> 255-115 =140 der tælles ned
- MOVWF Delay1 ;
- MOVLW D'32' ; h'DF'= 223 tælles op <=> 255-223 =32 der tælles ned
- MOVWF Delay2 ;
- Loop14 DECFSZ Delay1,F ;
- GOTO Loop14 ;
- MOVLW D'115' ;
- MOVWF Delay1 ;
- DECFSZ Delay2,F ;
- GOTO Loop14 ;
- DECFSZ Delay3,F ;
- GOTO Loop124 ;
- RETURN
- Timeout4
- MOVLW D'4' ; Tidsforsinkelse på ca. 10000 ms
- MOVWF Delay3 ;
- Loop125 MOVLW D'115' ; h'73'= 115 tælles op <=> 255-115 =140 der tælles ned
- MOVWF Delay1 ;
- MOVLW D'32' ; h'DF'= 223 tælles op <=> 255-223 =32 der tælles ned
- MOVWF Delay2 ;
- Loop15 DECFSZ Delay1,F ;
- GOTO Loop15 ;
- MOVLW D'115' ;
- MOVWF Delay1 ;
- DECFSZ Delay2,F ;
- GOTO Loop15 ;
- DECFSZ Delay3,F ;
- GOTO Loop125 ;
- RETURN
- ;ISR
- ;
- ; RETFIE
- ; ******* OPSÆTNING AF TEKST STRENGE ******************************************************
- org 0x700
- hashtag string "#"
- star string "*"
- lockmsg string "Låst"
- unlockmsg string "Åben"
- wrongmsg string "Forkert"
- newcodemsg string "Ny kode:"
- newcodeconfirmedmsg string " Ny kode godkendt"
- welcomemsg string "Indtast kode:"
- ; ******* PROGRAM AFSLUTTET ***************************************************************
- END ;her slutter programmet...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement