Digital touch Screen Combination lock


Closed Thread
Results 1 to 40 of 42

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    411

    Default Digital touch Screen Combination lock

    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.

    Name:  4d combination lock.png
Views: 1076
Size:  629.9 KB

    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.

    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 #
    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.

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    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.
    Yes indeed. One problem is that you are potentially jumping out of a subroutine without somehow ending up at a matching RETURN.

    Specifically: You're GOSUBing chkey but then, if any of the first couple of convoluted logic statement are found true you're going straight back to start, leaving a return address on stack. Once that has happened enough times (depending on PIC family) the program will crash.

    Next thing, which might not be part of the actual issue but makes your code "clumsy"...
    You're using the five low bits of PORTB as inputs but why on earth are you NOT reading those bits into a BYTE variable and comparing the resulating value against your different qualifiers?

    Code:
    value VAR BYTE
    value = PORTB & 00011111    ' Read 5 low bits of PORTB into value
    Now the variable value will contain a value between 0 and 31 covering all possible combinations of the 5 bits.
    If value is 31 you want pwok
    if value is 1,3,7, or 15 you want start
    if value is anything else you want reset

    That is what ALL those 80 something lines of IF this AND this AND this THEN that type of code in the chkey subroutine does...

    /Henrik.

    EDIT: One more thing: You're clearly reading PORTB which must mean you're using those five low bits as inputs, yet, at the top of the program you have TRISB = %00000000 which makes all of PORTB outputs...
    Last edited by HenrikOlsson; - 10th August 2020 at 13:07.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    not to mention the port pins are still analog ,difficult to see in all the noise

    missed ALLDIGITAL in there , my case rests
    Last edited by richard; - 10th August 2020 at 13:49.
    Warning I'm not a teacher

  4. #4
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Hi Henrik and Richard.

    Many thanks for your prompt reply.

    Really i'm not comfortable with programming, and i try to do what i really understand.

    I think i solve the issue by changing the following lines to these.....

    Code:
    chkey:
    if  portb.0 = 1 and portb.1 = 0 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then return
    if  portb.0 = 1 and portb.1 = 1 and portb.2 = 0 and portb.3 = 0 and portb.4 = 0 then return
    if  portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 0 and portb.4 = 0 then return
    if  portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 0 then return  
    if  portb.0 = 1 and portb.1 = 1 and portb.2 = 1 and portb.3 = 1 and portb.4 = 1 then pwok
    I wish i could manage to learn how to store values and read them after. I know that the code is not efficient at all.

    for now it works. I also change all the PORTX to LATX.

    In the mean time i will try to learn and understand how to right values, then store them, read them and compare.

    Many thanks once again.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    if you have a simple strategy to solve a task the program comes easily i find

    my strategy for this would be :-
    monitor the serial input for 0x07 chr [the start of a transmission pkt]
    when you get an 07 read in the pkt
    (a pkt when received can be decoded [eg '070D0000313B' the 5th byte is the key value data the sixth is a simple xor checksum])
    check if the 5th byte is bel [(0x08) the go button]
    if it is not
    place it in a password length sized ring buffer and continue monitoring the serial input
    if it is
    check if ring buffer contains the password key code sequence
    if it does
    then its a winner
    else
    object to the failed attempt
    keep reading in data
    Warning I'm not a teacher

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    i just can't help myself covid19 mania has set in

    my take
    Code:
    '*  Notes   : This is a codelock based on the following components    *
    '*          : PIC18F26K22 @ 64Mhz                                     *
    '*          : 4D Systems ULCD 32DT diablo                             *
    '*              note chksum untested                                  *
    '**********************************************************************     
    #CONFIG
      CONFIG  FOSC=INTIO67, PLLCFG=OFF, PRICLKEN=OFF, FCMEN=OFF, IESO=OFF
      CONFIG  PWRTEN=OFF, BOREN=SBORDIS, BORV=190, WDTEN=ON, WDTPS=32768
      CONFIG  CCP2MX=PORTC1, PBADEN=OFF, CCP3MX=PORTB5, HFOFST=ON, T3CMX=PORTC0
      CONFIG  P2BMX=PORTB5, MCLRE=EXTMCLR, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF
      CONFIG  CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF
      CONFIG  WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF
      CONFIG  EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
    #ENDCONFIG
    
    define  OSC 64 
    OSCCON    = $70   ; 64Mhz
    OSCTUNE.6 = 1     ; Enable 4x PLL
    
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code 
      
    TRISB = %10111111   
    TRISC = %10111111 
    ansela=0
    anselb=0
    anselc=0 
    
    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
    
    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 
    
    DATAIN          var byte[5] ;key pkt
    pword           var byte[4] ;holds password
    pbuff           var byte[4] ;ringbuffer  must be pow of 2
    buff            var byte[4] ;buffer to test password input
    pbuffinx        var byte    ;ringbuffer index
    chksum          var byte    ;the key pkt checksum if used
    key             var byte    ;the key just read in
    i               var byte
    
    
    ;num1    data  "070D0000313B" ; this is number 1
    ;num2      data  "070D00003238" ; this is number 2
    ;num3    data  "070D00003339" ; this is number 3
    ;num4    data  "070D0000343E" ; this is number 4
    ;num5    data  "070D0000353F" ; this is number 5
    ;num6    Data  "070D0000363C" ; this is number 6
    ;num7    Data  "070D0000373D" ; this is number 7
    ;num8    Data  "070D00003832" ; this is number 8
    ;num9    data  "070D00003933" ; this is number 9
    ;num10   data  "070D00002A20" ; this is number *
    ;num11   data  "070D0000303A" ; this is number 0
    ;num12   data  "070D00000802" ; this is go
    pause 1000
    HSERout2 ["ready"]   ;debug
    arraywrite pword ,["*478"]  ;set password  
    pbuffinx = 0
    
    Start:
    gosub readkey 
        if key != 8 then              ;not go key
            HSERout2 [key]            ;debug
            pbuff[pbuffinx] = key     ;add key to ringbuffer
            pbuffinx = (pbuffinx+1)&3 ;inc ringbuffer index
        else                          ;is go key
            for i = 0 to 3            ;read ringbuffer into buffer
                buff[i] = pbuff[(pbuffinx+i)&3]
            next
            HSERout2 [13,10,str buff\4,13,10];debug
            ARRAYREAD buff,4,fail,[WAITSTR pword\4]  ;test password
            goto unlocked
        endif
        goto start
    unlocked:
        HSERout2 ["unlocked"] ;debug
        pbuffinx = 0  ;may not be needed
        goto start
    fail:
        pbuffinx = 0  ;may not be needed
        HSERout2 ["failed"]  ;debug
    goto start
    
    readkey:         ;read key pkt
        HSERIN [WAIT($07), str datain\5] 
    '    chksum=7               ;chksum untested proteus vterminal won't allow null chr to be sent
    '    for i=0 to 4
    '        chksum  =  chksum ^ datain[i] 
    '    next
    '    if    chksum  then  goto readkey  ;dud read
        key = datain[3]
    return
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    lesson 2

    what happens here and why ? does changing the lata initial value make a difference?

    Code:
    #CONFIG  CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    '    DEFINE DEBUG_REG PORTB
    '    DEFINE DEBUG_BIT 7      ;  if not used for pwr  
    '    DEFINE DEBUG_BAUD 9600
    '    DEFINE DEBUG_MODE 0  
    '  ASM
    
    
    
    
        ;ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
    led1 var lata.0
    led2 var lata.1
    
    
    loopy:
    lata=3   ;init porta
    led2 = !porta.1
    
    
    led1 = porta.1
    
    
    pause 3000
     
    goto loopy
    Warning I'm not a teacher

  8. #8
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Quote Originally Posted by richard View Post
    lesson 2

    what happens here and why ? does changing the lata initial value make a difference?

    Code:
    #CONFIG  CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    '    DEFINE DEBUG_REG PORTB
    '    DEFINE DEBUG_BIT 7      ;  if not used for pwr  
    '    DEFINE DEBUG_BAUD 9600
    '    DEFINE DEBUG_MODE 0  
    '  ASM
    
    
    
    
        ;ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
    led1 var lata.0
    led2 var lata.1
    
    
    loopy:
    lata=3   ;init porta
    led2 = !porta.1
    
    
    led1 = porta.1
    
    
    pause 3000
     
    goto loopy
    excuse me starting from lesson 2.

    Name:  not porta1.png
Views: 1186
Size:  447.5 KB

    First of all as from the configuration, all PORTA is digital with bit 7-2 as input and bit 1-0 to output.

    now you have given a number to lata = 3. Even if you change this number nothing happen so far.

    LED 2 is opossite state from porta.1

    and LED 1 the same state as porta.1

    We havent configured any port to high or low. By default the ports are set to low?

    Could you also explain what is the logic behind the LATA.

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    lesson 3 {i will leave off the config section its unchanged}

    try this with latc initiaised with 1 2 or 3 and pins c0 and c1 grounded
    the leds always reflect the initial state of latc , and in no way reflect the logical state of portc pins why?

    Code:
        ANSELC = 0
        ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
        
    led1 var lata.0
    led2 var lata.1
    
    
    loopy:
    latc=0   ;init latc try 1 2 3
    led2 = latc.1
    led1 = latc.0
    
    
    pause 3000
     
    goto loopy
    ps don't make grounded pin outputs
    Last edited by richard; - 17th August 2020 at 15:11.
    Warning I'm not a teacher

  10. #10
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Quote Originally Posted by richard View Post
    lesson 3 {i will leave off the config section its unchanged}

    try this with latc initiaised with 1 2 or 3 and pins c0 and c1 grounded
    the leds always reflect the initial state of latc , and in no way reflect the logical state of portc pins why?

    Code:
        ANSELC = 0
        ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
        
    led1 var lata.0
    led2 var lata.1
    
    
    loopy:
    latc=0   ;init latc try 1 2 3
    led2 = latc.1
    led1 = latc.0
    
    
    pause 3000
     
    goto loopy
    ps don't make grounded pin outputs
    ok i got this....as i did the changing of the numbers from 0 to 3. It was obvious that those numbers represents binary numbers of the portc and corresponds to LED1 and LED2(assigned via software)

    I did add one more latc.2 to ground and placed one more LED to porta.2 (changed the trisa as well), then went up to 7th number and realised the change in binary on the porta.

    I would love if you could explain to me were this could be useful in real life. I know time is limitted but some time i would love to read your explanation.

    Many thanks.
    Last edited by astanapane; - 17th August 2020 at 20:42.

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    lesson 3
    ok i got this....as i did the changing of the numbers from 0 to 3. It was obvious that those numbers represents binary numbers of the portc and corresponds to LED1 and LED2(assigned via software)
    completely missing the point that:-
    portc pins 0 and 1 are shorted to ground and will always be at logic zero level.
    latc always reads back as the last value written to it [even when port is set as input ]
    latc does not represent the logic level as applied to the pins


    I would love if you could explain to me were this could be useful in real life.
    if you don't know how it works how can you use it ?
    Warning I'm not a teacher

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    excuse me starting from lesson 2.
    First of all as from the configuration, all PORTA is digital with bit 7-2 as input and bit 1-0 to output.


    all PORTA is not digital its all analogue



    now you have given a number to lata = 3. Even if you change this number nothing happen so far.
    the result is fixed , changing the input conditions will never change the result . why ?

    LED 2 is opposite state from porta.1
    no its not its always set. why ?
    and LED 1 the same state as porta.1
    no its not its never set. why ?





    Warning I'm not a teacher

  13. #13
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Quote Originally Posted by richard View Post
    all PORTA is not digital its all analogue





    the result is fixed , changing the input conditions will never change the result . why ?


    no its not its always set. why ?

    no its not its never set. why ?





    My bad, didint notice

    Code:
    ;ANSELA = 0
    Now things are more confused.

    the result is fixed , changing the input conditions will never change the result . why ?
    Really dont know. It might have to do with the analogue settings on the porta. I made all port digital and response to value changed. But really cant understand the reason.

    Code:
    no its not its always set. why ?
    
    no its not its never set. why ?
    ports configured as analogue by default are read as low?

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    ports configured as analogue by default are read as low?

    nearly , pins configured as analogue always read as low
    Warning I'm not a teacher

  15. #15
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Quote Originally Posted by richard View Post
    nearly , pins configured as analogue always read as low
    these are my notes. I think i will try to understand why these happens.

    What i cannot understand is the writting to the portx or to latx.

    For example if we give alias:

    Code:
    LED1 var LATX
    are we correspond the name to the LATX (not really writting to the LATX)

    So the same applies for the PORTX

    Code:
    LED1 var PORTX
    The problem comes as i understand when we really write to the LATx or PORTx. Values are different.

    I need to do some exercises more on this.

    Name:  20200818_113152.jpg
Views: 1189
Size:  154.0 KB

  16. #16
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    On the diagram above the Flip flop....is it an edge triggered D flip flop?

    If so i will focus on the schematic and i will try to understand what is going on in there.

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    when you write to lata you write directly to the porta output latches, only the pins declared as outputs are connected to the pins via the trisa "switch".
    when you write to porta you write directly to the porta output latches, only the pins declared as outputs are connected to the pins via the trisa "switch".
    when you read porta you read the digital logic level of all the porta pins , analog pins always read low
    when you read lata you read the porta output latches value not the digital logic level of all the porta pins
    when you write to a lata.pin you read the porta output latch value into the alu then,
    logically AND it with that pins bit value as 0 to CLEAR the pin
    or
    logically OR it with that pins bit value as 1 to SET the pin
    then write the result back to the porta output latches

    when you write to a porta.pin you read the porta pins value into the alu then,
    logically AND it with that pins bit value as 0 to CLEAR the pin
    or
    logically OR it with that pins bit value as 1 to SET the pin
    then write the result back to the porta output latches

    if you did lesson one you would have noticed that port pins are subject to real world load conditions and that reading the pin value is not always what you wrote to it
    you need to allow for pin loading

    lesson two shows you can set and clear an analog pin made output but you can never read an analog pin properly

    lesson three shows you can read and write to output latches but they may not represent the pin values of that port they are always what you last wrote to the latch

    Name:  portdiag.png
Views: 930
Size:  16.9 KB

    the diagram is for 1 pin
    Last edited by richard; - 18th August 2020 at 12:11. Reason: edited to English not gibberish
    Warning I'm not a teacher

Similar Threads

  1. 4 Wire resistive touch screen, Need help
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 16th February 2012, 18:28
  2. combination lock
    By korayfethi in forum Schematics
    Replies: 13
    Last Post: - 23rd May 2007, 21:02
  3. Round Dial, Electronic Combination Lock
    By Pic_User in forum Off Topic
    Replies: 5
    Last Post: - 6th July 2006, 14:34
  4. touch screen
    By micro in forum General
    Replies: 1
    Last Post: - 13th January 2006, 04:39
  5. Touch Screen Wish List!!!
    By Amity in forum PBP Wish List
    Replies: 2
    Last Post: - 15th September 2005, 15:40

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts