Digital touch Screen Combination lock


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 42
  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: 1063
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,516


    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,379


    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,379


    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,379


    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
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Hi Richard,

    thanks so much for your help and time. I need to read carefully your code and understand it.

    right now i'm testing the circuit.

    The unused pins either i will pull them up with a resistors, or i will make ports outputs and set them to low.

    I see in your code you have made those unused pins as inputs.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    The unused pins either i will pull them up with a resistors, or i will make ports outputs and set them to low.


    I see in your code you have made those unused pins as inputs.

    my answer is the same as you asked last time-


    if your program if affected by unused pins then your program is defective.


    when bread boarding unused pins left as inputs are less likely to be damaged by
    inadvertent connection.


    chip current consumption can be reduced by not having floating pins (by a few micro amps).
    enabling weak pull on unused inputs will stop them floating but consumes a few micro watts.
    setting unused pins low and as output consumes the minimal possible micro watts.
    the same can be achieved leaving them as input but physically grounding them.

    if the project is to be battery driven i will worry about unused pins in the final production version
    otherwise it is of no consequence.
    Last edited by richard; - 16th August 2020 at 01:25.
    Warning I'm not a teacher

  9. #9
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Richard, thanks once again.

    The final version will be under a 12V power supply. So there is no problem thinking about power consumption.

    Physically the final version might have resistors to unused pins pulled to +5V.

    At the moment i'm testing the circuit on breadboard for 3 days and there is no problem at all.

    P.S.

    /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...
    So if you use for example the "if"

    Code:
    if LATB.0 = 0
    that mean that we make the port as input? If that so, then what is the way to read the status of the port...."high" or "low" or even the value of the port?

    In the mean time im reading the manual.

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    So if you use for example the "if"

    if LATB.0 = 0
    that mean that we make the port as input? If that so, then what is the way to read the status of the port...."high" or "low" or even the value of the port?
    combined with this continually showing up in your 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.


    Code:
    '------------------------------------------------------------------------|
    '--------------------------- 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     |
    leads me to think there is fundamental lack of understanding here of pic i/o architecture
    and the relation ship between ansel,port,lat and tris registers and their effect on
    pin operations.

    i would recommend a few led flashing exercises to become comfortable with i/o concepts
    Warning I'm not a teacher

  11. #11
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    Hi Richard,

    i will try some LED blinks for sure.

    many thanks.

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


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    contrary to popular belief its a tricky subject

    lesson 1 what happens here with and without the nop compiled in ? and why ?
    Code:
    ;rmw test ,a led with a  270 ohm resistor in series to gnd placed each on pin a0 and a1
    #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=0
    led2 = !porta.1
    ;@ nop
    led1 = porta.1
    
    
    pause 3000
     
    goto loopy
    Warning I'm not a teacher

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    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

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


    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

  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
    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: 1172
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.

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

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


    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

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    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

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

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    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

  21. #21
    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: 1167
Size:  154.0 KB

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

  23. #23
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    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: 928
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

  24. #24
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    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?
    makes no difference
    Warning I'm not a teacher

  25. #25
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    im trying to understand what is going on with the help of the schematic , in lesson 1.

    Please give me some time.

    I just need to clarify something.

    when you write to all LATA register "0", is that just a number or is a bit? For example if we write

    Code:
    LATA = 5
    Is that a number or is translated to a binary 00000101.

    So this writting to lat register

    Code:
    LATA = 5 
    
    represents the 
    
    LATA = %00000101

  26. #26
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    5 dec = 5 hex = bin 101 , numbers are just numbers
    all digital computers to date are binary devices and that's all they can cope with
    programs like pbp C mpasm ...... allow humans to specify numbers in any form we are comfortable with

    generally we have conventions to remove number base confusion
    eg 5 = $5 = 0x05 =%00000101 = 0b00000101= %101 =$05 = %000000000000000101 . the chip only ever sees the binary version
    Warning I'm not a teacher

  27. #27
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    What i mean is if that numbers corresponds to 8 LATx for example for portA

    For example if we write

    Code:
    LATA = 5
    is that number correspond to binary 8 bit LATA.x , so that number 5 will write only to %00000101 which is the LATA.0 and LATA.2

    Can we write a number then to only one LATA.x

    for example can we write

    Code:
    LATA.0 = 5
    What that number will represent for the LATA.0

    based on the schematic logic gates receive only 0s or 1s. So LATA.x could only get 0s or 1s. Is that right?
    Last edited by astanapane; - 18th August 2020 at 13:04.

  28. #28
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    LATA = 5
    replaces the entire contents of lata latch with 5

    LATA.0 = 5

    is a syntax error a bit can only be 0 or 1

    lata.0 is bit 0 of the lata latch
    Warning I'm not a teacher

  29. #29
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    lesson 4 bit manipulation need 8 leds attached to porta:0-7

    These four routines [below] march a single lit led across the eight pins of porta from a0 to a7 when inserted in the shell provided.
    try each, which is the best do you think
    one of them could have "issues" @ 64mhz. which one? and why?


    can you reverse the direction of the march for each one ?
    can you light up the leds and march a single unlit led across the eight pins of porta from a0 to a7 ?

    i.
    PORTA.0=1
    WHILE PORTA
    PAUSE 200
    PORTA=PORTA<<1
    WEND
    ii.
    PORTA.0=1
    WHILE PORTA
    PAUSE 200
    PORTA=PORTA*2
    WEND


    iii.
    PORTA.0=1
    PAUSE 200
    PORTA.0=0
    PORTA.1=1
    PAUSE 200
    PORTA.1=0
    PORTA.2=1
    PAUSE 200
    PORTA.2=0
    PORTA.3=1
    PAUSE 200
    PORTA.3=0
    PORTA.4=1
    PAUSE 200
    PORTA.4=0
    PORTA.5=1
    PAUSE 200
    PORTA.5=0
    PORTA.6=1
    PAUSE 200
    PORTA.6=0
    PORTA.7=1
    PAUSE 200
    PORTA.7=0

    iv.
    PORTA=1
    PAUSE 200
    PORTA=2
    PAUSE 200
    PORTA=4
    PAUSE 200
    PORTA=8
    PAUSE 200
    PORTA=16
    PAUSE 200
    PORTA=32
    PAUSE 200
    PORTA=64
    PAUSE 200
    PORTA=128
    PAUSE 200
    PORTA=0

    Code:
    #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
    
    
    
    
    TRISA  = NOT 17 
    ansela = ~ $FF
    
    
    
    
    LOOPY:
        
      ;insert code here
    
    
        PAUSE 3000
    GOTO LOOPY
    Warning I'm not a teacher

  30. #30
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    im still in lesson 1.



    i need to completely understand it with the use of the port schmeatic.

  31. #31
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Angry Re: Digital touch Screen Combination lock

    make lesson 1 loop like this and try with and without the nop

    Code:
    loopy:
    lata=2
    pause 10
    porta.1 = 0
    ;@ nop
    porta.0 = 1
    
    
    
    
    pause 1000
     
    goto loopy
    the secret is that leds when forward biased charge up , when you set them low the charge can hold the pin high long enough
    to trigger a rmw event on a fast chip. the nop allows enough time for the charge to dissipate {62 nano seconds}
    Last edited by richard; - 18th August 2020 at 14:54.
    Warning I'm not a teacher

  32. #32
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    one by one,

    i'm doing some test. Really i have my own way to catch up and understand things.

    first of all for lata we can only write up to 255 as it is 8 bit.

    I'm still figuring out step by step the diagram.

  33. #33
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    this is really helpful for me as well.

    https://download.mikroe.com/document...c/help/rmw.htm

  34. #34
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    ok i think i have some how understood the concept.

    my question is.

    How could we assign a value that can be stored in memory and represent the state of the pin itself. (0 or 1)

    but at the same time to not read the actual pin, but the value that is stored in memory.

  35. #35
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    How could we assign a value that can be stored in memory and represent the state of the pin itself. (0 or 1)


    but at the same time to not read the actual pin, but the value that is stored in memory.
    simple, to read the value assigned to pins designated as output read latx its value is always what you last set it to
    the latx value of pins set as input is meaningless in regards to actual pin logic level

    to read the actual pin logic levels at a point in time read portx , its always the actual pin value at read time

    pin and latx values are not necessarily equal at a point in time, pins set as output are subject to real world physical constraints dictated by the load impedance they are driving
    Warning I'm not a teacher

  36. #36
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    i did a small test but it is not what i need.

    I would like now once again to clear the following.

    Henrik said

    "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..."
    As this statement, how could we read the status of the actual pin without using the port as input. Could you please explain to me the method?

    Code:
    ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
                                 
    led1 var porta.0    ; alias led1 to porta.0
    led2 var porta.1    ; alias led2 to porta.1
    x    var bit            ; tried to use X var as a bit in order to hold the value of the actual status of the pin.
    
    lata = 0               ; based on the schematic, we write to LATA and clear the ports 
    
    x = 0                  ; we write 0 to var X
    
    
    loopy:
    lata.0 = 1           ; we write 1 to lata.0
    gosub holdmem  ; gosub to holdmem
    
    pause 500
    read 5,led2        ; write the value of the location 5 to led2
    
    pause 500
    lata.0 = x          ; write the value of X to lata.0
    lata.1 = x          ; write the value of X to lala.1
    
    pause 1000
    goto loopy
    
    holdmem:
    write 5,led1  ; read the state of the porta.0 and place it to location 5 in memory.
    return

  37. #37
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    As this statement, how could we read the status of the actual pin without using the port as input. Could you please explain to me the method?
    simply put you cannot , reading portx is the only direct way to read the actual status of the pins.

    what henrik means is why would you read a port to read the value of outputs you have already set. the outputs will be at the level you set them to
    (after a suitable interval to allow pin to settle) {providing load is acceptable}.

    what are trying to do ?
    Warning I'm not a teacher

  38. #38
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Digital touch Screen Combination lock

    do you mean something like this

    no need to wear out the eeprom
    Code:
    ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
                                 
    led1 var porta.0    ; alias led1 to porta.0
    led2 var porta.1    ; alias led2 to porta.1
    x    var bit            ; tried to use X var as a bit in order to hold the value of the actual status of the pin.
    
    
     
    
    
    x = 0                  ; we write 0 to var X
    
    
    
    
    loopy:
    lata.0 = 1           ; we write 1 to lata.0
    gosub holdmem  ; gosub to holdmem
    
    
    pause 500
    led2  = x      ; write the value of x to led2
    pause 500
    led1=0
    @ nop
    led2=0
    pause 1000
    goto loopy
    
    
    holdmem:
    x = led1  ; read the state of the porta.0 and place it in x
    'x = lata.0  ;or  read the state of the lata.0 and place it in x
    return
     
    goto loopy
    Warning I'm not a teacher

  39. #39
    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
    simply put you cannot , reading portx is the only direct way to read the actual status of the pins.

    what henrik means is why would you read a port to read the value of outputs you have already set. the outputs will be at the level you set them to
    (after a suitable interval to allow pin to settle) {providing load is acceptable}.

    what are trying to do ?
    The program for the lockcode, at the moment works fine. As mentioned in my first post im not a programmer, i had to find a way to make it work.

    So the best suitable solution for me is to light up some LEDs and then read the status of the ports for confirmation.

    That's why i made those pins as output and then read the status to confirm if they are 0 or 1.

  40. #40
    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
    do you mean something like this

    no need to wear out the eeprom
    Code:
    ANSELA = 0
        DEFINE OSC 64 
        OSCCON = $70
        OSCTUNE.6 = 1
        TRISA = %11111100 
                                 
    led1 var porta.0    ; alias led1 to porta.0
    led2 var porta.1    ; alias led2 to porta.1
    x    var bit            ; tried to use X var as a bit in order to hold the value of the actual status of the pin.
    
    
     
    
    
    x = 0                  ; we write 0 to var X
    
    
    
    
    loopy:
    lata.0 = 1           ; we write 1 to lata.0
    gosub holdmem  ; gosub to holdmem
    
    
    pause 500
    led2  = x      ; write the value of x to led2
    pause 500
    led1=0
    @ nop
    led2=0
    pause 1000
    goto loopy
    
    
    holdmem:
    x = led1  ; read the state of the porta.0 and place it in x
    'x = lata.0  ;or  read the state of the lata.0 and place it in x
    return
     
    goto loopy
    yes i think this is what i wanted to do. But when we use the following command:

    Code:
    x = led1  ; read the state of the porta.0 and place it in x
    arent we write to EEPROM? Or this is temprorarly held in memory?

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