Dear all,
i need your help once again. I would like to replace the physical matrix 3x4keypad combination lock with a Digital touch screen display.
I have for couple of years a display from 4D systems, 32DT which is a nice touch display. So i though i could add the digital 3x4 matrix keypad and retrieve the information for every key, via serial port and using this information, i could manage to make a simple combination code.
The following is the information recieved for every key pressed. There is also 07Hex in front of all those numbers.
As i read the datasheet of the Screen the actual value every number sent.....for example for the number 1 is 31hex.
In the beggining i wanted to store those values everytime the key is pressed. My knowledge in programming is limitted so i though that if i want to use the digital 3x4 touch display i need to find an other way.Code:num1 data "0D0000313B" ; this is number 1 num2 data "0D00003238" ; this is number 2 num3 data "0D00003339" ; this is number 3 num4 data "0D0000343E" ; this is number 4 num5 data "0D0000353F" ; this is number 5 num6 Data "0D0000363C" ; this is number 6 num7 Data "0D0000373D" ; this is number 7 num8 Data "0D00003832" ; this is number 8 num9 data "0D00003933" ; this is number 9 num10 data "0D00002A20" ; this is number * num11 data "0D0000303A" ; this is number 0 num12 data "0D00000802" ; this is number #
Please check the following program....it works for the first couple of 30 seconds. But then somthing goes wrong, maybe in the loops or in the gosub instructions, and program messed up and freeze.
Could anyone help me please?
Code:'* Notes : This is a codelock based on the following components * '* : PIC18F26K22 or PIC18F46K22 @ 64Mhz * '* : 4D Systems ULCD 32DT diablo * '********************************************************************** '********************************************************************************* @ ERRORLEVEL -306 ; this command prevents the compiler to give you a notice of * ; crossing page boundary - make sure bits are set * '********************************************************************************* #CONFIG ; The PBP configuration for the PIC18F26K22 is: ; CONFIG FOSC = RCIO6 ; External RC oscillator CONFIG FOSC = HSHP ; HS oscillator (high power > 16 MHz) ;*---------------------------------4x PLL ENABLE--------------------------------------*| ;* 4X PLL Enable *| ;* CONFIG PLLCFG = OFF ;Oscillator used directly *| CONFIG PLLCFG = ON ;Oscillator multiplied by 4 *| ;*------------------------------------------------------------------------------------*| ; ; Primary clock enable bit ; CONFIG PRICLKEN = OFF ;Primary clock can be disabled by software CONFIG PRICLKEN = ON ;Primary clock enabled ; ; Fail-Safe Clock Monitor Enable bit CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disabled ; CONFIG FCMEN = ON ;Fail-Safe Clock Monitor enabled ; ; Internal/External Oscillator Switchover bit CONFIG IESO = OFF ;Oscillator Switchover mode disabled ; CONFIG IESO = ON ;Oscillator Switchover mode enabled CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled) ;*--------------------------------------------------------------------------------------------------------;| CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect ;| CONFIG WDTPS = 32768 ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;| ;*--------------------------------------------------------------------------------------------------------;| CONFIG PWRTEN = ON CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status CONFIG MCLRE = EXTMCLR ; MCLR pin enabled, RE3 input pin disabled CONFIG LVP = OFF ; Single-Supply ICSP disabled CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode) CONFIG DEBUG = OFF ; Disabled #ENDCONFIG ;*---------------------------------------------------------------------------------------------------------| ;*---------------------------------------------------------------------------------------------------------| define OSC 64 INCLUDE "modedefs.bas" INCLUDE"ALLDIGITAL.pbp" OSCCON = %01110000 ; 64Mhz OSCTUNE.6 = 1 ; Enable 4x PLL while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code '------------------------------------------------------------------------------------------------------------------------------------------------------------- TRISA = %00000000 'use TRISA to specify which pin is (1 = input) and which (0 = output) (ALL pins are output) TRISB = %00000000 'use TRISB to specify which pin is (1 = input) and which (0 = output) (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output) TRISC = %10000000 'use TRISC to specify which pin is (1 = input) and which (0 = output) (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output) 'in PORTC the RC3 attached is an LED. '------------------------------------------------------------------------| '--------------------------- TRIS A B C ---------------------------------| '------------------------------------------------------------------------| ' PORTA.7 PORTA.6 PORTA.5 PORTA.4 PORTA.3 PORTA.2 PORTA.1 PORTA.0 | ' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 | ' 0 0 0 0 0 0 0 0 | '------------------------------------------------------------------------| '------------------------------------------------------------------------| ' PORTB.7 PORTB.6 PORTB.5 PORTB.4 PORTB.3 PORTB.2 PORTB.1 PORTB.0 | ' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 | ' 0 0 0 0 0 0 0 0 | '------------------------------------------------------------------------| '------------------------------------------------------------------------| ' PORTC.7 PORTC.6 PORTC.5 PORTC.4 PORTC.3 PORTC.2 PORTC.1 PORTC.0 | ' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 | ' 1 0 0 0 0 0 0 0 | '------------------------------------------------------------------------| '------------------------------------------------------------------------| '----------------------- At start all PORTS LOW -------------------------| '------------------------------------------------------------------------| PORTA = 0 'make low all ports at A range | PORTB = 0 'make low all ports at B range | PORTC = 0 'make low all ports at C range | PORTE = 0 'make low all ports at E range | '------------------------------------------------------------------------| '------------------------------------------------------------------------| '-------------------------- COMPARATORS OFF -----------------------------| '------------------------------------------------------------------------| CM1CON0.7 = 0 'Disable comparator1 | CM2CON0.7 = 0 'Disable comparator2 | '------------------------------------------------------------------------| '*-----------------------------------------------------------------------------| '* | --------------------- | | '*----------------------- | EUART 1 Configuration | --------------------------| '* | --------------------- | | '*-----------------------------------------------------------------------------| DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0.08% SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator '*-----------------------------------------------------------------------------| '* | --------------------- | | '*----------------------- | EUART 2 Configuration | --------------------------| '* | --------------------- | | '*-----------------------------------------------------------------------------| DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER2_CLROERR 1 ' Clear overflow automatically DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0.08% SPBRGH2 = 1 BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator '*-----------------------------------------------------------------------------| '*-----------------------------------------------------------------------------| Timeout CON 2000 DATAIN var byte[5] ResetLCD var PORTC.2 RED var PORTC.3 BLUE var PORTC.4 i var byte ' -----[ EEPROM Data ]----------------------------------------------------- i just made a note of those numbers. ;num1 data "0D0000313B" ; this is number 1 ;num2 data "0D00003238" ; this is number 2 ;num3 data "0D00003339" ; this is number 3 ;num4 data "0D0000343E" ; this is number 4 ;num5 data "0D0000353F" ; this is number 5 ;num6 Data "0D0000363C" ; this is number 6 ;num7 Data "0D0000373D" ; this is number 7 ;num8 Data "0D00003832" ; this is number 8 ;num9 data "0D00003933" ; this is number 9 ;num10 data "0D00002A20" ; this is number * ;num11 data "0D0000303A" ; this is number 0 ;num12 data "0D00000802" ; this is number # ;------------------------------------------------------------------------------| ; [LCD hold on reset] | ;------------------------------------------------------------------------------| high resetlcd pause 500 low resetlcd ' -----------------------------------------------------------------------------| ' [ pic power led ] | '------------------------------------------------------------------------------| for i = 1 to 5 high RED : pause 50 low red : pause 50 next i high red '------------------------------------------------------------------------------| Start: HSERIN [WAIT($07), str datain\5] if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$31 and datain[4] =$3B then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$32 and datain[4] =$38 then gosub flash2 endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$33 and datain[4] =$39 then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$34 and datain[4] =$3E then gosub flash4 endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$35 and datain[4] =$3F then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$36 and datain[4] =$3C then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$37 and datain[4] =$3D then gosub flash7 endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$38 and datain[4] =$32 then gosub flash8 endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$39 and datain[4] =$33 then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$2A and datain[4] =$20 then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$30 and datain[4] =$3A then gosub reset endif if datain[0] = $0D and datain[1] =$00 and datain[2] =$00 and datain[3] =$08 and datain[4] =$02 then gosub flash12 endif goto start flash: hserout2 [str datain\5] high blue pause 50 low blue return flash2: hserout2 [str datain\5] high blue pause 50 low blue high portb.0 gosub chkey return flash7: hserout2 [str datain\5] high blue pause 50 low blue high portb.1 gosub chkey return flash8: hserout2 [str datain\5] high blue pause 50 low blue high portb.2 gosub chkey return flash4: hserout2 [str datain\5] high blue pause 50 low blue high portb.3 gosub chkey return flash12: hserout2 [str datain\5] high blue pause 50 low blue high portb.4 gosub chkey return chkey: if portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then start if portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then start if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then start if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 0 then start if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 1 then pwok if portb.0 = 0 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 0 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 0 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 1 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 1 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 0 and portb.2 = 1 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 0 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 0 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 0 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 1 and portb.4 = 0 then gosub reset endif if portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 1 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 1 then gosub reset endif if portb.0 = 1 and portb.1 = 0 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then gosub reset endif return reset: high blue pause 50 low blue low portb.0 low portb.1 low portb.2 low portb.3 low portb.4 return pwok: low portb.0 low portb.1 low portb.2 low portb.3 low portb.4 high portb.5 pause 2000 low portb.5 return
Bookmarks