Menu

TM1638 Key/Button Testing.

Help
ToniG
2022-09-13
2022-09-24
  • ToniG

    ToniG - 2022-09-13

    Hello to all GCbasic users out there.
    I need a bit of help to test the buttons (& specific displays)
    Attached is a .GCB test program to read TM1638 Keys & display Button Number
    or Raw hex data. (4 bytes)
    I have tested 2 module boards I have:
    "LED&KEY" - This one is Common Cathode display with non sequential wired button switches
    "QYF-TM1638" -This one is Common Anode display with sequentially wired button switches & digit com pins are wired reverse.
    If you get a garbled display or out of order buttons, try another configuration constant by enabling another #define in the Configuration. (only 1 can be enabled)

    '#Define TM1638_OEM   ' "OEM" board (Common Cathode display & No Btn re-Map)
    '#Define TM1638_OEM   ' "LED--KEY" module board (should be same as OEM)
    '#Define #Define LED_KEY      ' "LED&KEY" module board (Common Cathode display & Btn re-Map)
    QYF_TM1638  ' "QYF-TM1638"  board (Common Anode display & rev. digits)
    ' #Define NEW_BRD1    ' "new board" here & edit #Script
    

    If none work then enable #Define NEW_BRD1, & edit the Script block IF DEF(NEW_BRD1) by un-commenting relevant line.

     #Define NEW_BRD1
    
      IF DEF(NEW_BRD1) Then
    'Enable appropriate
    '     Com_Anode = ""
    '     Com_Cathode = ""
    '     RevDig = ""
    '     Butn_Map1 = ""
    '     Butn_Map2 = ""
      END IF
    

    If you get out of order buttons with or without Butn_Map1 active in script, change mode to display raw key values, enable this line #Define Raw_Key,
    Refer attached "TM1638 Buttons Table.pdf" & then edit table Butn_Map2 in the .GCB code.

    Looking at a schematic of a board "LED--KEY" is shows sequentially wired buttons, so this one should be display = Com_Cathode , Button re-map = inactive, RevDig = inactive.

    Any result of testing will be much appreciated.
    It is quite likely some "Identical looking" boards may be wired different.

    Toni

     
    • Anobium

      Anobium - 2022-09-14

      Brilliant!

      I tested with my LED&KEY board -worked in a few seconds on a LGT board!


      Result:

      When static (no buttons pressed) Eight 0s.
      Push any single button - a value of the button is shown on right hand LED = ranges from 1 to 8 returning to 0 when the button is released


      See attached LGT code.

      If it works on an LGT it will work on an AVR!

       

      Last edit: Anobium 2022-09-14
      • Anobium

        Anobium - 2022-09-14

        The CDF for the program Test_TM1638_Buttons.gcb

        The CDF can really help developers understand where and when constants are created and used.

        Shows this relative to this program

        A set of constants in the Test_TM1638_Buttons.gcb

        CODE/AddSymbol:     TMDLY                                       10                                  1
        CODE/AddSymbol:     TMCMD0                                      128                                 1
        CODE/AddSymbol:     TMCMD1                                      64                                  1
        CODE/AddSymbol:     TMCMD2                                      68                                  1
        CODE/AddSymbol:     TMCMD3                                      66                                  1
        CODE/AddSymbol:     TMADDR                                      192                                 1
        CODE/AddSymbol:     TM_DISPLEN                                  8                                   1
        CODE/AddSymbol:     TM1638_CLK                                  PORTB.5                             1
        CODE/AddSymbol:     TM1638_DIO                                  PORTB.4                             1
        CODE/AddSymbol:     TM1638_STB                                  PORTB.0                             1
        CODE/AddSymbol:     LED_KEY  
        

        lots of other constants, then two constants added from the script

        SCRIPT/AddSymbol:   COM_CATHODE                                                                                 -1
        SCRIPT/AddSymbol:   BUTN_MAP1                                                                                   -1
        

        Then, all the conditioanl logic and the assiocated code blocks that 'will be' processed. Showing the line numbers and the tests. The #ENDIFs are not shown. And, noting that #ELSE (if used) is shown as inverse test ( #IF > #IF NOT, IFDEF > IFNDEF etc).

                       135: #IFNDEF RAW_KEY
                      ;Make a linear button map from 4 Key bytes (Only single keypress)
                      ;For Cnt1 = 1 to 4
                      137: FOR CNT1 = 1 TO 4
                      ;Select Case TMKeyVal(Cnt1)
                      138: SELECT CASE TMKEYVAL(CNT1)
                      ;Case 4
                      139: CASE 4
                      ;If Cnt1 = 1 then ButnVal = 1
                      140: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 1
                      140: BUTNVAL = 1
                      ;If Cnt1 = 1 then ButnVal = 1
                      140: END IF
                      ;If Cnt1 = 2 then ButnVal = 3
                      141: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 3
                      141: BUTNVAL = 3
                      ;If Cnt1 = 2 then ButnVal = 3
                      141: END IF
                      ;If Cnt1 = 3 then ButnVal = 5
                      142: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 5
                      142: BUTNVAL = 5
                      ;If Cnt1 = 3 then ButnVal = 5
                      142: END IF
                      ;If Cnt1 = 4 then ButnVal = 7
                      143: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 7
                      143: BUTNVAL = 7
                      ;If Cnt1 = 4 then ButnVal = 7
                      143: END IF
                      ;Case 64
                      144: CASE 64
                      ;If Cnt1 = 1 then ButnVal = 2
                      145: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 2
                      145: BUTNVAL = 2
                      ;If Cnt1 = 1 then ButnVal = 2
                      145: END IF
                      ;If Cnt1 = 2 then ButnVal = 4
                      146: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 4
                      146: BUTNVAL = 4
                      ;If Cnt1 = 2 then ButnVal = 4
                      146: END IF
                      ;If Cnt1 = 3 then ButnVal = 6
                      147: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 6
                      147: BUTNVAL = 6
                      ;If Cnt1 = 3 then ButnVal = 6
                      147: END IF
                      ;If Cnt1 = 4 then ButnVal = 8
                      148: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 8
                      148: BUTNVAL = 8
                      ;If Cnt1 = 4 then ButnVal = 8
                      148: END IF
                      ;Case 2
                      149: CASE 2
                      ;If Cnt1 = 1 then ButnVal = 9
                      150: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 9
                      150: BUTNVAL = 9
                      ;If Cnt1 = 1 then ButnVal = 9
                      150: END IF
                      ;If Cnt1 = 2 then ButnVal = 11
                      151: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 11
                      151: BUTNVAL = 11
                      ;If Cnt1 = 2 then ButnVal = 11
                      151: END IF
                      ;If Cnt1 = 3 then ButnVal = 13
                      152: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 13
                      152: BUTNVAL = 13
                      ;If Cnt1 = 3 then ButnVal = 13
                      152: END IF
                      ;If Cnt1 = 4 then ButnVal = 15
                      153: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 15
                      153: BUTNVAL = 15
                      ;If Cnt1 = 4 then ButnVal = 15
                      153: END IF
                      ;Case 32
                      154: CASE 32
                      ;If Cnt1 = 1 then ButnVal = 10
                      155: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 10
                      155: BUTNVAL = 10
                      ;If Cnt1 = 1 then ButnVal = 10
                      155: END IF
                      ;If Cnt1 = 2 then ButnVal = 12
                      156: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 12
                      156: BUTNVAL = 12
                      ;If Cnt1 = 2 then ButnVal = 12
                      156: END IF
                      ;If Cnt1 = 3 then ButnVal = 14
                      157: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 14
                      157: BUTNVAL = 14
                      ;If Cnt1 = 3 then ButnVal = 14
                      157: END IF
                      ;If Cnt1 = 4 then ButnVal = 16
                      158: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 16
                      158: BUTNVAL = 16
                      ;If Cnt1 = 4 then ButnVal = 16
                      158: END IF
                      ;Case 1
                      159: CASE 1
                      ;If Cnt1 = 1 then ButnVal = 17
                      160: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 17
                      160: BUTNVAL = 17
                      ;If Cnt1 = 1 then ButnVal = 17
                      160: END IF
                      ;If Cnt1 = 2 then ButnVal = 19
                      161: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 19
                      161: BUTNVAL = 19
                      ;If Cnt1 = 2 then ButnVal = 19
                      161: END IF
                      ;If Cnt1 = 3 then ButnVal = 21
                      162: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 21
                      162: BUTNVAL = 21
                      ;If Cnt1 = 3 then ButnVal = 21
                      162: END IF
                      ;If Cnt1 = 4 then ButnVal = 23
                      163: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 23
                      163: BUTNVAL = 23
                      ;If Cnt1 = 4 then ButnVal = 23
                      163: END IF
                      ;Case 16
                      164: CASE 16
                      ;If Cnt1 = 1 then ButnVal = 18
                      165: IF CNT1 = 1 THEN
                      ;If Cnt1 = 1 then ButnVal = 18
                      165: BUTNVAL = 18
                      ;If Cnt1 = 1 then ButnVal = 18
                      165: END IF
                      ;If Cnt1 = 2 then ButnVal = 20
                      166: IF CNT1 = 2 THEN
                      ;If Cnt1 = 2 then ButnVal = 20
                      166: BUTNVAL = 20
                      ;If Cnt1 = 2 then ButnVal = 20
                      166: END IF
                      ;If Cnt1 = 3 then ButnVal = 22
                      167: IF CNT1 = 3 THEN
                      ;If Cnt1 = 3 then ButnVal = 22
                      167: BUTNVAL = 22
                      ;If Cnt1 = 3 then ButnVal = 22
                      167: END IF
                      ;If Cnt1 = 4 then ButnVal = 24
                      168: IF CNT1 = 4 THEN
                      ;If Cnt1 = 4 then ButnVal = 24
                      168: BUTNVAL = 24
                      ;If Cnt1 = 4 then ButnVal = 24
                      168: END IF
                      ;Case Else
                      ;ButnVal = 0
                      ;End Select
                      171: END SELECT
                      ;Next
                      172: NEXT
                      174: #IFDEF BUTN_MAP1
                      ;ReadTable ButnMap1, ButnVal-16, ButnVal
                      175: READTABLE BUTNMAP1, BUTNVAL-16, BUTNVAL
        
                      174: #IFDEF BUTN_MAP1
                      ;ReadTable ButnMap1, ButnVal-16, ButnVal
                      175: READTABLE BUTNMAP1, BUTNVAL-16, BUTNVAL
        
                      240: #IFDEF COM_CATHODE
                      ;set TM1638_STB 0
                      241: SET TM1638_STB 0
                      ;TM1638_WrVal (TMcmd2) ' Fixed address mode 44h __
                      242: TM1638_WRVAL (TMCMD2)
                      ;set TM1638_STB 1
                      243: SET TM1638_STB 1
                      ;Wait TMdly us
                      244: WAIT TMDLY US
                      ;For BufIndx = Dig_pos - (Num_Digs -1)  to  Dig_pos
                      245: FOR BUFINDX = DIG_POS - (NUM_DIGS -1) TO DIG_POS
                      ;set TM1638_STB 0
                      246: SET TM1638_STB 0
                      ;TM1638_WrVal (TMaddr +(BufIndx -1)*2)    ' Digit addr
                      247: TM1638_WRVAL (TMADDR +(BUFINDX -1)*2)
                      ;TM1638_WrVal (DBuf(BufIndx))             ' Digit data
                      248: TM1638_WRVAL (DBUF(BUFINDX))
                      ;set TM1638_STB 1
                      249: SET TM1638_STB 1
                      ;Wait TMdly us
                      250: WAIT TMDLY US
                      ;Next
                      251: NEXT
                      ;tmCtrlSnd
                      252: TMCTRLSND
        
         
  • ToniG

    ToniG - 2022-09-16

    I have updated the test code to enable Multiple key press, a value greater than 24 will be result.
    Only the boards with diodes on the key lines will work (so not the QYF- board)
    Not all combination will work due to the LED multiplexing.??
    The actual return value of a multi key press is (obviously) dependent on the wiring order between switches & TM1638 so could vary between different boards.
    The "LED&KEY" board has misaligned key wiring ( K3 & KS not sequential).
    An OEM board should align switch button numbers to K1->K3 & KS1->KS8. eg.K1_KS1=butn1

    File in a later post. - Test_TM1638_2Buttons.gcb

     

    Last edit: ToniG 2022-09-24
    • Anobium

      Anobium - 2022-09-17

      The "LED&KEY" board with misaligned key wiring works. ;-)

      The user could simply write a lookup table to correct the misaligned key wiring ? Or, is it the case that pressing more than one key will yield results that may be Zero? ( S1&S5;S2&S6;S8&S4;S7&S3 )

       
  • ToniG

    ToniG - 2022-09-17

    Please disregard the previous "Test_TM1638_Buttons.gcb", there are 2 issues with 2 buttons code.
    I only have 1 board that will do multi button press test. LED&KEY (17-24 key codes)
    1. The method was flawed, same value could result with different combination of low key values.
    2. My assumption "...due to the LED multiplexing.??" was incorrect, actually was due to 2 key bits in the same byte.

    I have modified to new file "Test_TM1638_2Buttons.gcb"
    It has 2 bytes. ButnVal for 1 key & ButnVal2 for 2nd key.
    User can test for non-zero value in ButnVal2.
    Lower button number is always ButnVal.
    This could be useful for a shift function.

    I can put it in TM1638_OEM_lib
    (I hope someone can find any issues)

    Edit:

    The user could simply write a lookup table to correct the misaligned key wiring

    In this test program there is already a lookup table that can be enable/disabled with #Define LED_KEY ( creates Butn_Map1 = "" in script)
    In the TM1638_OEM_lib it will be #Define Butn_Map1 or #Define Butn_Map2.
    If undefined a user can create their own button re-map table if desired.

    Edit:
    Update GCB file 2022-09-21
    (see file for details)

     

    Last edit: ToniG 2022-09-24
    • Anobium

      Anobium - 2022-09-18

      My display looks ___00_00 then then display represents the key pressed ___0n_0n`

      The results make sense and the program makes a lot of sense also.


      Test on UNO with LED&KEY. Results look good.

       
    • Anobium

      Anobium - 2022-09-22

      Should I test again?

       
      • ToniG

        ToniG - 2022-09-23

        No, you don't need to.
        I just updated the test file as I was finding things that were not right.
        I was interested in anyone with some different boards to test, but as the new lib has a flexible setup (& easy default) they hopefully will ask for help on the forum if their board does not work..
        Thanks for your testing & advise.
        The new TM1638_OEM lib is ready now for review.

        On the subject of the CDF output, I get a different structure from what you posted.
        There is mostly symbols not used in my program & I don't see the conditional logic.

         
        • Anobium

          Anobium - 2022-09-23

          I can see the static constants, and the scripts. So, we know the report is handing the constants plus the 100's of others.

          What is the entry in your use.ini? And, are you using the IDE(s) to execute the compiler (as you need to pass use.ini as the parameter)?

           
          • ToniG

            ToniG - 2022-09-24

            I click the make hex button in the IDE, G+Stool calls batch file(s)
            I have tried various permutations...
            conditionaldebugfile = "sourcefilename".gcb "sourcefileame".gcb
            conditionaldebugfile = Test_TM1638_2Buttons.gcb,
            make hex with other source file & don't change name in .ini etc

            It always produces the .CDF in the source folder & with current compiled file name so that is ok

             
            • Anobium

              Anobium - 2022-09-24

              conditionaldebugfile = Test_TM1638_2Button.gcb with no quotes works. Generates a CDF with the conditional statements at CDF lines 810 - end

               
  • ToniG

    ToniG - 2022-09-18

    Display...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.