* ================================================== * | Author: Unknown Talent | * | Course: ENSC151-2 | * | Assignment: Final Project | * | Description: This file controls the LCD disply | * | and sends a signal when the alarm goes off to | * | Port T so the Altera can use it. | * ================================================== ***** Parallel I/O Port Registers ****************************************** PORTA: equ $00 ;Port A Data Register PORTB: equ $01 ;Port B Data Register DDRA: equ $02 ;Port A Data Direction Register DDRB: equ $03 ;Port B Data Direction Register PORTC: equ $04 ;Port C Data Register DDRC: equ $06 ;Port C Data Direction Register PORTE: equ $08 ;Port E Data Register DDRE: equ $09 ;Port E Data Direction Register PEAR: equ $0A ;Port E Assigment Register PORTT: equ $00AE ;Port T Data Register DDRT: equ $00AF ;Port T Data Direction Register MODE: equ $0B ;Mode Register PUCR: equ $0C ;Pull Up Control Register RDRIV: equ $0D ;Reduced Drive of I/O Lines Register INITRM: equ $10 ;Initialization of Internal RAM Position Register INITRG: equ $11 ;Initialization of Internal Register Position Register INITEE: equ $12 ;Inittaps INTCR: equ $1E ;Interrupt Control Register IRQVEC: equ $0B32 ;Put irq entry address here IRQ_ENABLE: equ $EF ;Activate irq ena by anding with ccr IRQEN: equ $50 ;Value Needed To Set IRQ to Level Triggering BLUE_BUT: equ $FF ;Blue Button value when pressed (Zone 4) WHITE_BUT: equ $EF ;White button value when pressed (Zone 3) RED_BUT: equ $DF ;Red Button value when pressed (Zone 2) YELLOW_BUT: equ $CF ;Yellow Button value when pressed (Zone 1) KEYPAD1: equ $1F ;KeyPad Button #1 value when pressed KEYPAD2: equ $2F ;KeyPad Button #2 value when pressed KEYPAD3: equ $3F ;KeyPad Button #3 value when pressed KEYPAD4: equ $4F ;KeyPad Button #4 value when pressed KEYPAD5: equ $5F ;KeyPad Button #5 value when pressed KEYPAD6: equ $6F ;KeyPad Button #6 value when pressed MOTION: equ $BF ;Motion Detector Check Value When Pressed (Zone 5) ****************************************************************************** ORG $0D00 * * Main Program * ***** Initialize Hardware **************************************************** LDAA #$07 ;SET LOWER 4 BITS OF PORT A STAA DDRA ;TO OUTPUT MODE LDAA #$FF ;SET ALL PORT B BITS TO STAA DDRB ;OUTPUT MODE LDAA #$01 ;SET BIT 0 OF PORT T STAA DDRT ;TO OUTPUT MODE DISINIT ;INITIALISE DISPLAY LDAA #$30 ;SET UP THE FUNCTION JSR WRITE_INST ; LDAA #$0F JSR LONGPAUSE LDAA #$38 JSR WRITE_INST LDAA #$08 JSR WRITE_INST LDAA #$01 JSR WRITE_INST LDAA #$04 JSR LONGPAUSE LDAA #$06 JSR WRITE_INST LDAA #$0C JSR WRITE_INST IRQ_INIT BSET INTCR,IRQEN ;Set IRQ to level triggering MOVW #IRQ_PROC,IRQVEC ;Install Vector Address In Table. SEI ****************************************************************************** PROGRAMSTART LDAA #$80 ;Write message to top line JSR WRITE_INST LDX #STRING1 ;Display "System Ready" to the LCD JSR WRITE_MESS LDAA #$C0 ;Keeps the 2nd line of LCD clear. JSR WRITE_INST LDX #STRING2 JSR WRITE_MESS CLI ;Enable IRQ so IRQ can be called JSR CODEENTER ;calls subroutine which checks if code is right LDAA #$80 ;Write message to top line JSR WRITE_INST LDX #STRING4 ;Display "System Ready" to the LCD JSR WRITE_MESS JSR CHANGESTATE LDAA #$01 ;means only keypad buttons are accepted STAA IGNORE LDAA #$01 ;Causes siren to go off STAA PORTT JSR CODEENTER ;calls subroutine which checks if code is right LDAA #$00 ;Deactivates siren STAA PORTT LDAA #$00 ;means all buttons/motion sensor are accepted STAA IGNORE JMP PROGRAMSTART ;causes program to be in a constant loop ***************************************************************************** * The CODEENTER subroutine checks to see if the correct code has been typed * * in using the keypad. The code has been programed as 1234. If any one of * * the numbers punched in is incorrect, the code will have to be entered all * * over again from the beginning. This code is used to activate the system * * and turn it off after the siren goes off. * ***************************************************************************** CODEENTER JSR CHANGESTATE CMPB #$01 ;Check if key pad button 1 has been pressed BNE CODEENTER JSR CHANGESTATE CMPB #$02 ;Check if key pad button 2 has been pressed BNE CODEENTER JSR CHANGESTATE CMPB #$03 ;Check if key pad button 3 has been pressed BNE CODEENTER JSR CHANGESTATE CMPB #$04 ;Check if key pad button 4 has been pressed BNE CODEENTER RTS ***************************************************************************** CHANGESTATE SEI CLR RESPOND CLI CHANGE2 SEI LDAB RESPOND CLI CMPB #$00 BEQ CHANGE2 RTS ***************************************************************************** * This subroutine will go in a constant loop until it observers a change in * * state for one of the four buttons on the board, the six keypad buttons or * * the motion sensor. It checks each of the signals separtely and goes on * * to the next one if it hasn't been set to high. If it has been set to * * high, it jumps to a subroutine to carry out specific operations. * ***************************************************************************** IRQ_PROC ;Take care of interrupt SEI ;Disable IRQ Conflict (won't allow another one ;to be called until this one exits. LDAA #$C0 JSR WRITE_INST CLRA LDAA PORTA ORAA #$0F CMPA #KEYPAD1 BNE K2 JSR IRQ_KEY1 K2 CMPA #KEYPAD2 BNE K3 JSR IRQ_KEY2 K3 CMPA #KEYPAD3 BNE K4 JSR IRQ_KEY3 K4 CMPA #KEYPAD4 BNE K5 JSR IRQ_KEY4 K5 CMPA #KEYPAD5 BNE K6 JSR IRQ_KEY5 K6 CMPA #KEYPAD6 BNE SW1 JSR IRQ_KEY6 SW1 CMPA #YELLOW_BUT BNE SW2 JSR IRQ_BUT01 SW2 CMPA #RED_BUT BNE SW3 JSR IRQ_BUT02 SW3 CMPA #WHITE_BUT BNE SW4 JSR IRQ_BUT03 SW4 CMPA #BLUE_BUT BNE M1 JSR IRQ_BUT04 M1 CMPA #MOTION BNE IRQ_EXIT4 JSR IRQ_MOTION IRQ_EXIT4 RTI ** IRQ Subroutines BEGIN ***************************************************** * Each IRQ subroutine causes a certain message to be displayed on screen. It * * also causes acc B to be set to a certain value which will be stored in the * * variable RESPOND. This variable will be used to check which button is * * pressed so the system can respond accordingly. A few other subroutines are * * used for operations that are common to a number of the IRQ subroutines. * * The Keypad keys are given priority once the siren has been turned on. This * * means that when one of the other buttons is pressed, the output will be * * placed on the LCD. This allows the code to be punched in without * * interference from the other buttons. * ******************************************************************************* IRQ_KEY1 JSR IRQ_CLEAR LDX #STRING5 LDAB #$01 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_KEY2 JSR IRQ_CLEAR LDX #STRING5 LDAB #$02 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_KEY3 JSR IRQ_CLEAR LDX #STRING5 LDAB #$03 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_KEY4 JSR IRQ_CLEAR LDX #STRING5 LDAB #$04 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_KEY5 JSR IRQ_CLEAR LDX #STRING5 LDAB #$05 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_KEY6 JSR IRQ_CLEAR LDX #STRING5 LDAB #$06 JSR IRQ_EXIT2 JSR IRQ_EXIT3 RTS IRQ_BUT01 JSR IRQ_CLEAR JSR IRQ_EXIT1 LDX #STRING6 LDAA IGNORE ;Used to skip changing CMPA #$01 ;the button code when BEQ SKIP1 ;checking the status of the alarm LDAB #$07 ;after the siren is turned on JSR IRQ_EXIT2 SKIP1 JSR IRQ_EXIT3 RTS IRQ_BUT02 JSR IRQ_CLEAR JSR IRQ_EXIT1 LDX #STRING7 LDAA IGNORE ;Used to skip changing CMPA #$01 ;the button code when BEQ SKIP2 ;checking the status of the alarm LDAB #$08 ;after the siren is turned on JSR IRQ_EXIT2 SKIP2 JSR IRQ_EXIT3 RTS IRQ_BUT03 JSR IRQ_CLEAR JSR IRQ_EXIT1 LDX #STRING8 LDAA IGNORE ;Used to skip changing CMPA #$01 ;the button code when BEQ SKIP3 ;checking the status of the alarm LDAB #$09 ;after the siren is turned on JSR IRQ_EXIT2 SKIP3 JSR IRQ_EXIT3 RTS IRQ_BUT04 JSR IRQ_CLEAR JSR IRQ_EXIT1 LDX #STRING9 LDAA IGNORE ;Used to skip changing CMPA #$01 ;the button code when BEQ SKIP4 ;checking the status of the alarm LDAB #$0A ;after the siren is turned on JSR IRQ_EXIT2 SKIP4 JSR IRQ_EXIT3 RTS IRQ_MOTION JSR IRQ_CLEAR JSR IRQ_EXIT1 LDX #STRINGA LDAA IGNORE ;Used to skip changing CMPA #$01 ;the button code when BEQ SKIP5 ;checking the status of the alarm LDAB #$0B ;after the siren is turned on JSR IRQ_EXIT2 SKIP5 JSR IRQ_EXIT3 RTS IRQ_CLEAR LDAA #$80 ;Sets the LCD to the top line JSR WRITE_INST LDX #STRING2 ;Display " " to the LCD JSR WRITE_MESS LDAA #$C0 ;Sets the LCD to the bottom line JSR WRITE_INST LDX #STRING2 ;Display " " to the LCD JSR WRITE_MESS RTS ;RETURN FROM INTERRUPT IRQ_EXIT1 LDAA #$80 ;Sets the LCD to the top line JSR WRITE_INST LDX #STRING3 ;Display "Sensor Tripped" to the LCD JSR WRITE_MESS RTS IRQ_EXIT2 STAB RESPOND ;stores value for each button so it ;can be used to check the status of ;the alarm IRQ_EXIT3 LDAA #$C0 ;Sets the LCD to the bottom line JSR WRITE_INST JSR WRITE_MESS RTS ** IRQ Subroutines END ******************************************************* ** LCD Subroutines BEGIN **************************************************** WRITE_MESS NEXT_CHAR LDAA 0,X ;Load string in acc A CMPA #$00 ;Check for end of message BEQ END_MESS JSR WRITE_DATA INX ;Increment string pointer BRA NEXT_CHAR END_MESS RTS WRITE_DATA ;Assume data in acc A STAA PORTB ;Write data to Port B LDAA #$01 ;Set the interface lines for data write STAA PORTA JSR PAUSE LDAA #$05 STAA PORTA JSR PAUSE LDAA #$01 STAA PORTA JSR PAUSE RTS WRITE_INST STAA PORTB LDAA #$00 STAA PORTA JSR PAUSE LDAA #$04 STAA PORTA JSR PAUSE LDAA #$00 STAA PORTA JSR PAUSE RTS ** LCD Subroutines END ******************************************************* ** Delay Subroutines BEGIN ************************************************** LONGPAUSE STAA COUNTER LOOK TST COUNTER BEQ FINISH DEC COUNTER JSR PAUSE BRA LOOK FINISH RTS PAUSE2 LDY #$FFFF AGAIN2 DEY CPY #$0000 BNE AGAIN2 RTS PAUSE LDY #$00FF AGAIN DEY CPY #$0000 BNE AGAIN RTS ** Delay Subroutines END **************************************************** ****************************************************************************** ****************************************************************************** ****************************************************************************** ** Constant Strings Define BEGIN ******************************************** ORG $0800 STRING1 DB 'System Ready' FCB $00 STRING2 DB ' ' FCB $00 STRING3 DB 'Sensor Tripped' FCB $00 STRING4 DB 'System Armed' FCB $00 STRING5 DB '*' FCB $00 STRING6 DB 'Zone 1' FCB $00 STRING7 DB 'Zone 2' FCB $00 STRING8 DB 'Zone 3' FCB $00 STRING9 DB 'Zone 4' FCB $00 STRINGA DB 'Motion - Zone 5' FCB $00 ** Constant Strings Define END *********************************************** ** Variable Define BEGIN ***************************************************** COUNTER DB $00 RESPOND DB $00 IGNORE DB $00 ** Variable Define END *******************************************************