Menu

Problem with Function

2024-02-07
2024-02-08
  • Geoffrey Younger

    Hi Evan ,
    The attached file ' MicroKP.gcb ' is a good, working file that compiled correctly with ver-1073 .
    When I try to compile with the latest ver-1331 I get the following error message -
    ' MicroKP.gcb (49): Error: Missing Function Assignment - assign function result to a variable, or, change to a Subroutine'
    I've racked my brains to find out what I did wrong, without any success.
    Can you please help ?
    Cheers
    Geoffrey Younger

     
  • Anobium

    Anobium - 2024-02-07

    KPD is function. It is better to describe as KPD(). It therefore returns a value. I am guessing you are returning a byte value. So, assign the function to a byte value like myreturnedvaluefromKPDfunction = KPD

    There was a functional change on 21/11/2023 1303 Fix COMPILER N/A Yes PIC Not required Updated to resolve Functions that are not assigned to a target variable[1560] as functions that do not assign the returned value was generating incorrect ASM.

     
  • Anobium

    Anobium - 2024-02-07

    Also, remove #define USELEGACYFORNEXT this is not a good idea. As this was meant as temp measure while we monitored the impact of the change to for-next loops. The compiler must be permitted to use the correct for-next structure.

    The compiler will use the legacy mode for the for-next loop when it can. But #define USELEGACYFORNEXT forces legacy mode for every for-next loop... not recommend as libraries may need the 'working' for-next loop.

     
  • Geoffrey Younger

    Thanks for all the useful information. I have done the following.
    1. Dim myreturnedvaluefromKPDfunction as byte '
    2. Function KPD() 'When called -> Returns PB value
    3. Added myreturnedvaluefromKPDfunction = KPD just below the Function call

    I tried to compile, but I still get the error msg. I then rem'd out #3 and tried to compile again but without success. Any further clues ?
    Geoff

     
  • Anobium

    Anobium - 2024-02-07

    Like this...

     
  • Geoffrey Younger

    Thank you Evan. I compiled and programmed the 15244. Works like a charm !
    Cheers
    Geoff

     
  • Anobium

    Anobium - 2024-02-07

    Pleasure.

    The change was to ensure that the ASM generated was valid. The old compiler could, under certain circumstances, overwrite RAM values. So, the change ensure strict usage of functions.

    If you have not donated to the funding for 2024 please consider. The funding is less than £10 GBP short of the target.

     
  • Geoffrey Younger

    Donation Made

     
    • Anobium

      Anobium - 2024-02-07

      Thank you. 2024 funding target met!!!

       
  • Geoffrey Younger

    One final comment from me, Could you please update the Help File with this change to the
    Function Statement. I spent an awful lot of time in there trying to figure out what had happened.
    Cheers
    Geoff

     
    • Anobium

      Anobium - 2024-02-08

      A very good comment/point.

      Updated see https://github.com/GreatCowBASIC/Help/blob/main/source/functions.adoc

      You can change online if I have made editing errors.

       
  • Anobium

    Anobium - 2024-02-08

    I was just about to delete your program here when I spotted something.

    Using the code segement to explain.

    Do                      'Main Program Loop for 4 way Keypad
    
        'CALL 1
        myreturnedvaluefromKPDfunction = KPD                  'call Function - KeyPad Decode
        locate 1,0          'Line-2
    '----
    'CALL 2
      If KPD = 0   Then     '
        Print "None"        'No Key Pressed
        Testled = 0         '  Data Available
      Else                  '
      'CALL 3
        Print KPD           'Show Decoded Value
        Print "-"           'Data Separator
        Testled = 1         '  Data Available
      End If
    '----
    '  Print adcPB           'show RAW value--UNcomment as required
       wait 250 ms          'For Demo only
    '-----
     locate 1,0             'Line2 - p  rint spaces to
      Print "        "      'Erase old KPD value ( 8 spaces )
     Loop                   '
    

    If the code is as shown above you will get inconsistent results as you are/were reading the value of the ADC three times. I have shown these with the CALL 1,2,3 above.

    You should read once in the variable myreturnedvaluefromKPDfunction and then use the variable for consistency.

    Do                      'Main Program Loop for 4 way Keypad
    
        'CALL 1
        myreturnedvaluefromKPDfunction = KPD                  'call Function - KeyPad Decode
        locate 1,0          'Line-2
    '----
    'CALL 2
      If myreturnedvaluefromKPDfunction = 0   Then     '
        Print "None"        'No Key Pressed
        Testled = 0         '  Data Available
      Else                  '
      'CALL 3
        Print myreturnedvaluefromKPDfunction           'Show Decoded Value
        Print "-"           'Data Separator
        Testled = 1         '  Data Available
      End If
    '----
    '  Print adcPB           'show RAW value--UNcomment as required
       wait 250 ms          'For Demo only
    '-----
     locate 1,0             'Line2 - p  rint spaces to
      Print "        "      'Erase old KPD value ( 8 spaces )
     Loop                   '
    

    Why does this give consistency? Reading three times means that at Call 1 you code get a one value, then at Call 2 the ADC changes.. you will get another value, and then at Call 3 the ADC changes.. you will get another value. Worse case scenario. So, the new segment Calls for the value once.


    I have deleted the code here now. :-)

     
  • Geoffrey Younger

    Many thanks for that.
    Cheers
    Geoff

     
  • Geoffrey Younger

    Many thanks for that.
    Cheers
    Geoff

     

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.