;------------------------------------------------------------------------------- ; FILE: Interrupt and Timer ; AUTH: Ed's Projects ; DATE: 06/07/2016 ; DESC: 4x4 Keypad input, 10 values saved to EEPROM, displayed on LCD, three Analogue Inputs and the Timer1 Interrupt ;------------------------------------------------------------------------------- LIST P=16F887, R=DEC ; All numbers Decimal format unless otherwise stated. include ; Define configurations, registers, etc. __CONFIG _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOREN_ON & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDTE_OFF & _HS_OSC ;------------------------------------------------------------------------------- ;----------------------------- Port Definitions ------------------------------ ;------------------------------------------------------------------------------- ; PortD - Output - RD1 - Pin 20 - RS Register select for LCD ; PortD - Output - RD0 - Pin 19 - E Enable for LCD ; PortC - Output - RC0 - Pin 15 - DB4 Dataline for LCD ; PortC - Output - RC1 - Pin 16 - DB5 Dataline for LCD ; PortC - Output - RC2 - Pin 17 - DB6 Dataline for LCD ; PortC - Output - RC3 - Pin 18 - DB7 Dataline for LCD ; PortB - Output - RB0 - Pin 33 - Column 1 Keypad ; PortB - Output - RB1 - Pin 34 - Column 2 Keypad ; PortB - Output - RB2 - Pin 35 - Column 3 Keypad ; PortB - Output - RB3 - Pin 36 - Column 4 Keypad ; PortB - Input - RB4 - Pin 37 - Row 1 Keypad ; PortB - Input - RB5 - Pin 38 - Row 2 Keypad ; PortB - Input - RB6 - Pin 39 - Row 3 Keypad ; PortB - Input - RB7 - Pin 40 - Row 4 Keypad ; PORTA - Output - RA5 - Pin 7 - Password Correct Indicator ; PORTE - ADC - AN5 - Pin 8 ; PORTE - ADC - AN6 - Pin 9 ; PORTE - ADC - AN7 - Pin 10 ;------------------------------------------------------------------------------- ;-------------------------------- Variables ---------------------------------- ;------------------------------------------------------------------------------- cblock h'20' micro200f ms2delayf ms2delayg dly0 ; Number of 2ms delays Tmp temp temp2 temp3 temp4 temp5 startemp ; Indicates star button pressed hashtemp ; Indicates hash button pressed offset ; Offsets the PCL keytemp vartemp lcdtemp clrtemp ee_data ; EEPROM data ee_adr ; EEPROM address unlock ; System locked / unlocked tempA ; States A pressed, for second menu tempB ; States B pressed, for second menu tempC ; States C pressed, for second menu tempD ; States D pressed, for second menu Adc_low ; Low bit ADC read process Adc_high ; High bit ADC read process ADCtemp ; ADC temp address file tempdig ; The temp variable to aid splitting 3 nibbles orgdig ; The variable to be split into 3 nibbles digit3 ; High nibble digit2 ; Middle nibble digit1 ; Low nibble inttemp ; interrupt timer loop temp adrtemp ; address location for reading EEPROM sectemp ; second temp file, for LCD endc ;------------------------------------------------------------------------------- ;--------------------- Indirect Addressing Variables ------------------------- ;------------------------------------------------------------------------------- ; A0 - A9 ; Variables for Keypad ; AA - E5 ; EEPROM output variables ;------------------------------------------------------------------------------- ;------------------------------ EEPROM Address ------------------------------- ;------------------------------------------------------------------------------- ; 0 - 9 ; Password ; 10 - 69 ; 60 Measurments ;------------------------------------------------------------------------------- ;----------------------------- Define Symbols -------------------------------- ;------------------------------------------------------------------------------- #define R1 PORTB, 4 ; Row 1 Keypad #define R2 PORTB, 5 ; Row 2 Keypad #define R3 PORTB, 6 ; Row 3 Keypad #define R4 PORTB, 7 ; Row 4 Keypad #define C1 PORTB, 0 ; Column 1 Keypad #define C2 PORTB, 1 ; Column 2 Keypad #define C3 PORTB, 2 ; Column 3 Keypad #define C4 PORTB, 3 ; Column 4 Keypad #define LCD4 PORTC, 0 ; DB4 LCD #define LCD5 PORTC, 1 ; DB5 LCD #define LCD6 PORTC, 2 ; DB6 LCD #define LCD7 PORTC, 3 ; DB7 LCD #define LCDRS PORTD, 1 ; Reset LCD #define LCDE PORTD, 0 ; Enable LCD #define UNLOCK PORTA, 5 ; System unlocked Indicator ;------------------------------------------------------------------------------- ;------------------------------- Program Code -------------------------------- ;------------------------------------------------------------------------------- ORG 0 goto Init ;------------------------------------------------------------------------------- ;---------------------------- Interrupt Address ------------------------------ ;------------------------------------------------------------------------------- ORG 04 goto Interrupt ;------------------------------------------------------------------------------- ;-------------------------- Initialisation of Ports -------------------------- ;------------------------------------------------------------------------------- Init bcf STATUS,RP0 ; Set RP0 to 0 bcf STATUS,RP1 ; Set RP1 to 0 ; Bank 0 Selected movlw b'00110000' movwf T1CON ; Set Timer1 to prescale 8, internal clock clrf ADCON0 ; Turn off ADC bsf STATUS,RP0 ; Set RP0 to 1 ; Bank 1 Selected bsf INTCON, PEIE ; Turn on peripheral Interrupts bsf PIE1, 0 ; Turn on Timer1 Interrupt bsf INTCON, GIE ; Turn on global interrupts movlw b'00000000' movwf ADCON1 ; Set Left justified data output - ADC clrf VRCON ; Set Vref to off clrf TRISA ; Set all PortA as Output clrf TRISC ; Set all PortC as Output clrf TRISD ; Set all PortD as Output movlw b'00000111' movwf TRISE ; Set RE0, 1 and 2 to inputs - for ADC movlw b'11110000' ; Load 11110000 to working register movwf TRISB ; Set bits 0-3 as outputs, rest inputs bsf STATUS,RP1 ; Set RP0 to 1 ; Bank 3 Selected movlw b'11100000' movwf ANSEL ; Set AN5, AN6, AN7 as analogue clrf ANSELH ; Set all high analogue inputs to digital bcf STATUS,RP0 ; Set RP0 to 0 ; Bank 2 Selected clrf CM1CON0 ; Turn off comparator 1 clrf CM2CON0 ; Turn off comparator 2 bcf STATUS,RP0 ; Set RP0 to 0 bcf STATUS,RP1 ; Set RP1 to 0 ; Bank 0 Selected clrf PORTA clrf PORTB clrf PORTC clrf PORTD clrf PORTE clrf micro200f clrf ms2delayf clrf ms2delayg clrf dly0 ; Number of 2ms delay loops clrf Tmp clrf temp clrf temp2 clrf temp3 clrf temp4 clrf temp5 clrf startemp clrf hashtemp clrf keytemp clrf lcdtemp clrf clrtemp clrf ee_data ; EEPROM data clrf ee_adr ; EEPROM data address movlw h'A0' movwf vartemp movlw h'A0' ; This section will clear the first 64 movwf FSR ; blocks of RAM in bank 1 clrram clrf INDF incf FSR, f incf clrtemp, f btfss clrtemp, 6 goto clrram ; Clear variables and output ports bsf UNLOCK ; Sets system as unlocked ;------------------------------------------------------------------------------- ;--------------------------- LCD Initialisation ------------------------------ ;------------------------------------------------------------------------------- movlw d'32' call delay bsf LCD5 bsf LCD4 call Enable call ms2delay call ms2delay call Enable call micro200 call Enable bcf LCD4 call Enable ;Function Set movlw b'00101000' ;4-bit mode, 2 lines, 5x7 matrix call SendLCD ;Display on / off movlw b'00001100' ;Display on, Cursor off, Blink off call SendLCD ;Entry Mode Set movlw b'00000110' ;Increment, Display shifted call SendLCD ;Cursor or display shift movlw b'00010000' ;Display Shift call SendLCD ;Clear Screen movlw b'00000001' ; Clear screen call SendLCD call ms2delay call ms2delay bsf LCDRS ; Set data mode goto Start ;------------------------------------------------------------------------------- ;----------------------------- Send Data to LCD ------------------------------ ;------------------------------------------------------------------------------- SendLCD ; Send data in two 4-bit nibbles movwf Tmp bcf LCD7 bcf LCD6 bcf LCD5 bcf LCD4 btfsc Tmp, 7 bsf LCD7 btfsc Tmp, 6 bsf LCD6 btfsc Tmp, 5 bsf LCD5 btfsc Tmp, 4 bsf LCD4 call Enable bcf LCD7 bcf LCD6 bcf LCD5 bcf LCD4 btfsc Tmp, 3 bsf LCD7 btfsc Tmp, 2 bsf LCD6 btfsc Tmp, 1 bsf LCD5 btfsc Tmp, 0 bsf LCD4 call Enable return ;------------------------------------------------------------------------------- ;--------------------------------- Enable ------------------------------------ ;------------------------------------------------------------------------------- Enable bsf LCDE nop nop nop nop bcf LCDE call micro200 call micro200 call micro200 return ;------------------------------------------------------------------------------- ;--------------------------------- LCD Clear --------------------------------- ;------------------------------------------------------------------------------- LCDClr bcf LCDRS movlw b'00000001' call SendLCD bsf LCDRS call ms2delay call ms2delay return ;------------------------------------------------------------------------------- ;----------------------------- LCD Cursor Shift ------------------------------ ;------------------------------------------------------------------------------- LCDShi bcf LCDRS iorlw b'10000000' call SendLCD bsf LCDRS call ms2delay return ;------------------------------------------------------------------------------- ;--------------------------- LCD Character Space ----------------------------- ;------------------------------------------------------------------------------- LCDSpace movlw d'32' call SendLCD return ;------------------------------------------------------------------------------- ;---------------------------- Loops 2ms Delay -------------------------------- ;------------------------------------------------------------------------------- delay movwf dly0 delayloop call ms2delay decfsz dly0, f goto delayloop return ;------------------------------------------------------------------------------- ;------------------------------- 2ms Delay ----------------------------------- ;------------------------------------------------------------------------------- ms2delay movlw d'8' movwf ms2delayg ms2delayc movlw d'250' movwf ms2delayf ms2delaya nop ;0.2us nop ;0.2us decfsz ms2delayf,f ;0.2us goto ms2delaya ;0.4us ;total 250us ms2delayb decfsz ms2delayg,f ;0.2us goto ms2delayc ;0.4us return ;return from call ;------------------------------------------------------------------------------- ;------------------------------- 200us Delay --------------------------------- ;------------------------------------------------------------------------------- micro200 movlw d'200' movwf micro200f micro200a nop ;0.2us nop ;0.2us decfsz micro200f,f ;0.2us goto micro200a ;0.4us return ;return from call ;------------------------------------------------------------------------------- ;--------------------------- Character Storage ------------------------------- ;------------------------------------------------------------------------------- Charr ; Since this table will cross the a page call LCDClr ; and increment the PCH then PCLATH must be clrf offset ; dealt with Charra call Charrb ; Fetch a character addlw 0 btfsc STATUS, Z return call SendLCD call micro200 incf offset, f ; Increment offset to choose next character goto Charra ; from table Charrb movlw LOW tabler ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH tabler ; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW tabler ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table tabler DT " Welcome to ", " EEPROM using the ", " Ed's Projects ", " PIC16F628A ", d'0' Char1 ; Since this table will cross the a page call LCDClr ; and increment the PCH then PCLATH must be clrf offset ; dealt with Char1a call Char1b ; Fetch a character addlw 0 btfsc STATUS, Z goto Char1c call SendLCD call micro200 incf offset, f ; Increment offset to choose next character goto Char1a ; from table Char1b movlw LOW table ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH table ; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW table ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table table DT "Please enter a value ", d'0' Char1c movlw h'A0' ; Load start of RAM location to be sent movwf lcdtemp Chard movf lcdtemp, w movwf FSR movf INDF, w addlw d'48' call SendLCD incf lcdtemp movf lcdtemp, w xorlw h'AA' ; Check if ten digits have been sent, if btfss STATUS, Z ; so return goto Chard return Char2 ; Since this table will cross the a page call LCDClr ; and increment the PCH then PCLATH must be clrf offset ; dealt with Char2a call Char2b ; Fetch a character addlw 0 btfsc STATUS, Z return call SendLCD call micro200 incf offset, f ; Increment offset to choose next character goto Char2a ; from table Char2b movlw LOW table2 ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH table2 ; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW table2 ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table table2 DT "Press A to Read ADC", "Press C to return ", "Press B to View ADC", "Press D Lock System", d'0' Char3 ; Since this table will cross the a page call LCDClr ; and increment the PCH then PCLATH must be clrf offset ; dealt with Char3a call Char3b ; Fetch a character addlw 0 btfsc STATUS, Z return call SendLCD call micro200 incf offset, f ; Increment offset to choose next character goto Char3a ; from table Char3b movlw LOW table3 ; Get low 8 bits of table address addwf offset, w ; Check to see if a carry will occur movlw HIGH table3 ; Get high 5 bits of address btfsc STATUS, C ; Has page crossed? addlw 1 ; Yes then increment PCLATH - PCH movwf PCLATH ; Load high address into PCLATH - PCH movlw LOW table3 ; Get low 8 bits of table address again addwf offset, w ; Load original PCL offset value movwf PCL ; Jump into table table3 DT "Press A Scroll Up ", "Press C to Return ", "Press B Scroll Down", "Press D Lock System", d'0' ;------------------------------------------------------------------------------- ;---------------------------------- Keypad ----------------------------------- ;------------------------------------------------------------------------------- Keyscan bsf C1 ; Check to see if any key has been pressed bsf C2 bsf C3 bsf C4 btfsc R1 goto scanprocess btfsc R2 goto scanprocess btfsc R3 goto scanprocess btfsc R4 goto scanprocess return Keynot ; Return to main program when no keys are bsf C1 ; pressed bsf C2 bsf C3 bsf C4 btfsc R1 goto Keynot btfsc R2 goto Keynot btfsc R3 goto Keynot btfsc R4 goto Keynot bsf temp2, 0 movlw d'10' ; 20ms delay for switch bounce call delay return scanprocess ; Start scanning which key is pressed bsf C1 bcf C2 bcf C3 bcf C4 movlw d'1' call Rscan bcf C1 movlw d'2' bsf C2 call Rscan bcf C2 movlw d'3' bsf C3 call Rscan bcf C3 movlw d'32' bsf C4 call Rscan movf keytemp, w xorlw d'11' btfsc STATUS, Z clrf keytemp ; When 48 is added later on it will translate movf keytemp, w ; to the ASCII number 0 xorlw d'10' btfsc STATUS, Z ; Check if star key pressed call star movf keytemp, w xorlw d'12' btfsc STATUS, Z ; Check if hash key pressed call hash goto Keynot star ; When 48 is added later on it will roll over movlw d'250' ; to ASCII number 42 - * movwf keytemp bsf startemp, 0 ; Used as confirm key return hash movlw d'243' ; When 48 is added later on it will roll over movwf keytemp ; to ASCII number 35 - # bsf hashtemp, 0 ; Used as an option key return Rscan btfsc R1 goto R1set btfsc R2 goto R2set btfsc R3 goto R3set btfsc R4 goto R4set return R1set movwf keytemp call checkalpha goto Keynot R2set addlw d'3' movwf keytemp call checkalpha goto Keynot R3set addlw d'6' movwf keytemp call checkalpha goto Keynot R4set addlw d'9' movwf keytemp call checkalpha goto Keynot checkalpha ; Check if A, B, C or D has been pressed btfss keytemp, 5 return movf keytemp, w xorlw b'00100000' btfsc STATUS, Z goto leta movf keytemp, w xorlw b'00100011' btfsc STATUS, Z goto letb movf keytemp, w xorlw b'00100110' btfsc STATUS, Z goto letc goto letd leta movlw d'17' ; When 48 is added later on these will movwf keytemp ; translate to ASCII letter corresponding bsf tempA, 0 ; with what was pressed on the keypad return letb movlw d'18' movwf keytemp bsf tempB, 0 ; For a second menu, states B pressed return letc movlw d'19' movwf keytemp bsf tempC, 0 ; For a second menu, states C pressed return letd movlw d'20' movwf keytemp bsf tempD, 0 ; For a second menu, states D pressed return ;------------------------------------------------------------------------------- ;------------------------------ EEPROM Write --------------------------------- ;------------------------------------------------------------------------------- Ewrite movf ee_adr, w ; Load working register with ee_adr bsf STATUS, RP1 ; Bank 2 Selected movwf EEADR ; Set location to write to EEPROM bcf STATUS, RP1 ; Bank 0 Selected movf ee_data, w ; Load working register with ee_data bsf STATUS, RP1 ; Bank 2 Selected movwf EEDATA ; Data to be written to address bsf STATUS, RP0 ; Bank 3 Selected bcf EECON1, EEPGD ; Ensure writing to EEPROM bsf EECON1, WREN ; Enables EEPROM write bcf INTCON, GIE ; Global interrupts disabled, all ints off btfsc INTCON, GIE ; Check to make sure interrupts are disabled goto $-1 ; Jump to above instruction ; The next four lines must be there to allow the data to be written movlw d'85' ; Load working register with decimal 85 movwf EECON2 ; Load working register to EECON2 movlw d'170' ; Load working register with decimal 170 movwf EECON2 ; Load working register to EECON2 bsf EECON1, WR ; Send data btfsc EECON1, WR goto $-1 ; If 1, check again, 0 indicates data written bsf INTCON, GIE ; Turn back on all interrupts bcf EECON1, WREN ; Turn off EEPROM write bcf STATUS, RP1 ; Select bank 0 bcf STATUS, RP0 ; Select bank 0 return ; return from where left off ;------------------------------------------------------------------------------- ;------------------------------ EEPROM Read ---------------------------------- ;------------------------------------------------------------------------------- Eread movf ee_adr, w ; Load working register with ee_adr bsf STATUS, RP1 ; Bank 2 Selected movwf EEADR ; Set location to read EEPROM from bsf STATUS, RP0 ; Bank 3 Selected bsf EECON1, RD ; Enables EEPROM read btfsc EECON1, RD goto $-1 bcf STATUS, RP0 ; Bank 2 Selected movf EEDATA, w ; Load working resgister with EEPROM data bcf STATUS, RP1 ; Bank 0 Selected movwf ee_data return ; return from where left off ;------------------------------------------------------------------------------- ;------------------------- Main part of program ------------------------------ ;------------------------------------------------------------------------------- Start call Charr Starta movlw d'250' call delay movlw d'250' call delay movlw d'250' call delay movlw d'250' call delay Startb call Char1 movlw h'A0' movwf vartemp Here call Keyscan btfsc startemp, 0 ; Confirm Key goto confirm btfsc hashtemp, 0 ; Option / Confirm Key goto hashcon btfsc temp2, 0 ; Only write if a new character has been entered call incvar clrf temp2 clrf keytemp goto Here incvar ; Adds characters to variables, max. 10 movf vartemp, w movwf FSR movf keytemp, w movwf INDF call Char1 clrf keytemp incf vartemp movf vartemp, w xorlw h'AA' btfss STATUS, Z return movlw h'A0' movwf vartemp return confirm ; To here when star key is pressed btfsc UNLOCK ; Pressing star when unlocked will go goto menu2 ; to another menu clrf keytemp clrf temp2 clrf startemp movlw h'A0' movwf vartemp clrf temp3 ; EEPROM address variable movlw h'A0' movwf temp4 ; Keypad check variable confirma ; Compares variables to EEPROM movf temp3, w movwf ee_adr call Eread movf temp4, w movwf FSR movf INDF, w xorwf ee_data, w btfss STATUS, Z goto wrongcode incf temp3, f incf temp4, f movf temp3, w xorlw d'10' btfss STATUS, Z goto confirma ; String to LCD saying correct code bsf UNLOCK call LCDClr call LCDSpace call LCDSpace movlw d'67' ; C call SendLCD movlw d'111' ; o call SendLCD movlw d'114' ; r call SendLCD movlw d'114' ; r call SendLCD movlw d'101' ; e call SendLCD movlw d'99' ; c call SendLCD movlw d'116' ; t call SendLCD call LCDSpace movlw d'80' ; P call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'115' ; s call SendLCD movlw d'119' ; w call SendLCD movlw d'111' ; o call SendLCD movlw d'114' ; r call SendLCD movlw d'100' ; d call SendLCD goto Starta hashcon ; To here when hash key pressed btfss UNLOCK ; Will not allow change of password unless goto entpasmes ; system is unlocked clrf keytemp clrf temp2 clrf hashtemp movlw h'A0' movwf vartemp clrf temp3 ; EEPROM address variable movlw h'A0' movwf temp4 ; Keypad new password variable hashcona ; Writes data from variables to EEPROM movf temp3, w movwf ee_adr movf temp4, w movwf FSR movf INDF, w movwf ee_data call Ewrite incf temp3, f incf temp4, f movf temp3, w xorlw d'10' btfss STATUS, Z goto hashcona call LCDClr call LCDSpace call LCDSpace movlw d'80' ; P call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'115' ; s call SendLCD movlw d'119' ; w call SendLCD movlw d'111' ; o call SendLCD movlw d'114' ; r call SendLCD movlw d'100' ; d call SendLCD call LCDSpace movlw d'67' ; C call SendLCD movlw d'104' ; h call SendLCD movlw d'97' ; a call SendLCD movlw d'110' ; n call SendLCD movlw d'103' ; g call SendLCD movlw d'101' ; e call SendLCD movlw d'100' ; d call SendLCD call LCDSpace goto Starta wrongcode ; To here when entered code does not match EEPROM call LCDClr call LCDSpace call LCDSpace call LCDSpace movlw d'87' ; W call SendLCD movlw d'114' ; r call SendLCD movlw d'111' ; o call SendLCD movlw d'110' ; n call SendLCD movlw d'103' ; g call SendLCD call LCDSpace movlw d'80' ; P call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'115' ; s call SendLCD movlw d'119' ; w call SendLCD movlw d'111' ; o call SendLCD movlw d'114' ; r call SendLCD movlw d'100' ; d call SendLCD goto Starta entpasmes ; To here when system locked and trying to set clrf keytemp ; a new password. clrf temp2 clrf hashtemp call LCDClr movlw d'69' ; E call SendLCD movlw d'110' ; n call SendLCD movlw d'116' ; t call SendLCD movlw d'101' ; e call SendLCD movlw d'114' ; r call SendLCD call LCDSpace movlw d'80' ; P call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'115' ; s call SendLCD movlw d'119' ; w call SendLCD movlw d'111' ; o call SendLCD movlw d'114' ; r call SendLCD movlw d'100' ; d call SendLCD call LCDSpace movlw d'70' ; F call SendLCD movlw d'105' ; i call SendLCD movlw d'114' ; r call SendLCD movlw d'115' ; s call SendLCD movlw d'116' ; t call SendLCD goto Starta nowlocked ; To here when entered code is correct bcf UNLOCK ; System now locked call LCDClr call LCDSpace call LCDSpace call LCDSpace movlw d'83' ; S call SendLCD movlw d'121' ; y call SendLCD movlw d'115' ; s call SendLCD movlw d'116' ; t call SendLCD movlw d'101' ; e call SendLCD movlw d'109' ; m call SendLCD call LCDSpace call LCDSpace movlw d'76' ; L call SendLCD movlw d'111' ; o call SendLCD movlw d'99' ; c call SendLCD movlw d'107' ; k call SendLCD movlw d'101' ; e call SendLCD movlw d'100' ; d call SendLCD goto Starta ;------------------------------------------------------------------------------- ;-------------------------------- ADC Read ----------------------------------- ;------------------------------------------------------------------------------- ADCread movlw b'10010101' ; Set conversion speed to highest movwf ADCON0 ; 1/32 and select AN5 call micro200 ; Allows channel time to adjust call ADCreada call ADCconv movlw b'10011001' ; Set conversion speed to highest movwf ADCON0 ; 1/32 and select AN6 call micro200 ; Allows channel time to adjust call ADCreada call ADCconv movlw b'10011101' ; Set conversion speed to highest movwf ADCON0 ; 1/32 and select AN7 call micro200 ; Allows channel time to adjust call ADCreada call ADCconv movf ee_adr, w ; Program will loop a total of 20 times xorlw d'70' ; saving each result in EEPROM, 60 btfss STATUS, Z ; readings total goto retread bcf T1CON, 0 ; Stop timer1 goto menu2 ADCconv movf Adc_high, w ; Data is left justified, using this movwf ee_data ; bank is the same as dividing the call Ewrite ; 10-bit number by 4 to get 8-bit incf ee_adr, f return ADCreada bsf ADCON0, GO ; Convert analogue to digital btfsc ADCON0, GO ; Check to see if complete goto $-1 ; If not loop to above instruction movf ADRESH, w movwf Adc_high ; Move to variable bsf STATUS, RP0 ; Set RP0 to 1 ; Bank 1 Selected movf ADRESL, w bcf STATUS, RP0 ; Set RP0 to 0 ; Bank 0 Selected movwf Adc_low ; Move to variable return menu2 call clrall call Char2 menu2a call Keyscan ; Check A, B, C or D btfsc tempA, 0 goto Aoption ; Readadc btfsc tempB, 0 goto Boption ; Check saved adc value btfsc tempC, 0 goto Coption ; Return to previous menu btfsc tempD, 0 goto Doption ; Lock System goto menu2a Doption call clrall goto nowlocked ; Lock System Coption call clrall goto Startb ; Return to start menu - unlocked Aoption call clrall call LCDClr call LCDSpace call LCDSpace movlw d'82' ; R call SendLCD movlw d'101' ; e call SendLCD movlw d'97' ; a call SendLCD movlw d'100' ; d call SendLCD movlw d'105' ; i call SendLCD movlw d'110' ; n call SendLCD movlw d'103' ; g call SendLCD call LCDSpace movlw d'65' ; A call SendLCD movlw d'110' ; n call SendLCD movlw d'97' ; a call SendLCD movlw d'108' ; l call SendLCD movlw d'111' ; o call SendLCD movlw d'103' ; g call SendLCD movlw d'117' ; u call SendLCD movlw d'101' ; e call SendLCD ; Start read process movlw d'10' movwf ee_adr movlw b'00001011' ; This first delay is to allow enough time movwf TMR1H ; to read ADC. movlw b'11110100' ; Load timer1 with 3060, total of 62500 movwf TMR1L ; increments. bsf T1CON, 0 ; Start timer1 loop clrf inttemp goto ADCread retread btfss inttemp, 7 ; Check for one second past goto retread goto loop Boption call Char3 movlw d'9' ; When scroll down will go to 10 movwf adrtemp ; location start of EEPROM clrf sectemp ; Seconds display to LCD decf sectemp, f ; Sets to 255 menu3 call clrall menu3a call Keyscan ; Check A, B, C or D btfsc tempA, 0 goto Aoption2 ; Scroll Up btfsc tempB, 0 goto Boption2 ; Scroll Down btfsc tempC, 0 goto menu2 ; Return to previous menu btfsc tempD, 0 goto Doption ; Lock System goto menu3a Aoption2 movlw d'5' subwf adrtemp decf sectemp, f goto result Boption2 incf adrtemp, f incf sectemp, f result call LCDClr call LCDSpace call LCDSpace call LCDSpace call LCDSpace movlw d'83' ; S call SendLCD movlw d'101' ; e call SendLCD movlw d'99' ; c call SendLCD movlw d'111' ; o call SendLCD movlw d'110' ; n call SendLCD movlw d'100' ; d call SendLCD movlw d'115' ; s call SendLCD call LCDSpace call LCDSpace call LCDSpace movf sectemp, w call digitcharacter movf digit3, w call SendLCD movf digit2, w call SendLCD movf digit1, w call SendLCD call LCDSpace call LCDSpace call LCDSpace movlw d'77' ; M call SendLCD movlw d'101' ; e call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'117' ; u call SendLCD movlw d'114' ; r call SendLCD movlw d'101' ; e call SendLCD movlw d'109' ; m call SendLCD movlw d'101' ; e call SendLCD movlw d'110' ; n call SendLCD movlw d'116' ; t call SendLCD call LCDSpace movlw d'50' ; 2 call SendLCD call LCDSpace call LCDSpace incf adrtemp, f movf adrtemp, w movwf ee_adr call Eread movf ee_data, w call digitcharacter movf digit3, w call SendLCD movf digit2, w call SendLCD movf digit1, w call SendLCD call LCDSpace call LCDSpace movlw d'77' ; M call SendLCD movlw d'101' ; e call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'117' ; u call SendLCD movlw d'114' ; r call SendLCD movlw d'101' ; e call SendLCD movlw d'109' ; m call SendLCD movlw d'101' ; e call SendLCD movlw d'110' ; n call SendLCD movlw d'116' ; t call SendLCD call LCDSpace movlw d'49' ; 1 call SendLCD call LCDSpace call LCDSpace decf adrtemp, f movf adrtemp, w movwf ee_adr call Eread movf ee_data, w call digitcharacter movf digit3, w call SendLCD movf digit2, w call SendLCD movf digit1, w call SendLCD call LCDSpace call LCDSpace movlw d'77' ; M call SendLCD movlw d'101' ; e call SendLCD movlw d'97' ; a call SendLCD movlw d'115' ; s call SendLCD movlw d'117' ; u call SendLCD movlw d'114' ; r call SendLCD movlw d'101' ; e call SendLCD movlw d'109' ; m call SendLCD movlw d'101' ; e call SendLCD movlw d'110' ; n call SendLCD movlw d'116' ; t call SendLCD call LCDSpace movlw d'51' ; 3 call SendLCD call LCDSpace call LCDSpace incf adrtemp, f incf adrtemp, f movf adrtemp, w movwf ee_adr call Eread movf ee_data, w call digitcharacter movf digit3, w call SendLCD movf digit2, w call SendLCD movf digit1, w call SendLCD goto menu3 clrall clrf tempA ; Clear A pressed indicator variable clrf tempB ; Clear B pressed indicator variable clrf tempC ; Clear C pressed indicator variable clrf tempD ; Clear D pressed indicator variable clrf keytemp ; Clear keypad temp file clrf temp2 ; Clear Key entered indicator clrf hashtemp ; Clear hash pressed indicator clrf startemp ; Clear star pressed indicator return ;------------------------------------------------------------------------------- ;---------------------- Convert variable to characters ----------------------- ;------------------------------------------------------------------------------- digitcharacter movwf tempdig ; temp variable movwf orgdig clrf digit3 clrf digit2 clrf digit1 dlabel1 movlw d'100' subwf tempdig btfss STATUS, C goto dlabel3 movlw d'100' subwf orgdig incf digit3, f goto dlabel1 dlabel3 movf orgdig, w movwf tempdig dlabel2 movlw d'10' subwf tempdig btfss STATUS, C goto dlabel4 movlw d'10' subwf orgdig incf digit2, f goto dlabel2 dlabel4 movf orgdig, w addlw d'48' movwf digit1 movf digit3, w addlw d'48' movwf digit3 movf digit2, w addlw d'48' movwf digit2 return ;------------------------------------------------------------------------------- ;---------------------------- Interrupt Program ------------------------------ ;------------------------------------------------------------------------------- Interrupt bcf PIR1, 0 ; Clear Interrupt bit bcf T1CON, 0 ; Stop timer1 movlw b'00001011' movwf TMR1H movlw b'11110100' ; Load timer1 with 3060, total of 62500 movwf TMR1L ; increments. bsf T1CON, 0 ; Start timer1 incf inttemp, f movf inttemp, w xorlw d'10' btfss STATUS, Z retfie bsf inttemp, 7 ; When looped 10 times retfie end