Menu

RESOLVED: Mega 328p, the code with the HSerGetNum command does not compile

Aleksandr
2024-08-26
2024-08-27
  • Aleksandr

    Aleksandr - 2024-08-26

    Hi.
    There is a code of about 580 lines for mega328p. We write the code in the Sub:

    HSerGetNum myNum
    Xmin=myNum

    myNum and Xmin are defined as Word

    when I try to compile, I get an error:
    Error: Out of registers. Please break up any complex calculations

    If I replace the code above with:

    HSerGetString myString
    Xmin=StringToWord (myString)

    then there is no error during compilation.
    What could be the problem?

     
  • Anobium

    Anobium - 2024-08-26

    Hello Aleksandr ,

    Well this is an error I have not seen.

    I would only be able to analyse with your program. Attach to a post.

    I do vaguely remember adding that error message as there was a silent error. So, with your program I can examine.

     
  • Aleksandr

    Aleksandr - 2024-08-26

    I'm new to programming, so I don't understand many things yet. I'm sure a professional would have written the code differently.
    Code in line: 425

     

    Last edit: Aleksandr 2024-08-26
  • Anobium

    Anobium - 2024-08-27

    This issue relates to use of an array in the HSerGetNum() routine.

    Try the code below. Add to your program and call this routine. Does it return the correct result ?

    The routine HSerGetNum() uses an array and was written by one of the other developers. I have rewritten to use a lot less resources and now it should work for you.

    Use myHSerGetNum rather than HSerGetNum

    Let me know if this resolves.


    Your program is great.


    Evan

    sub myHSerGetNum (Out HSerNum As Word, optional In comport = 1)
      Dim HSerInByte, HSerIndex
      HSerIndex = 1  
      HSerNum = 0
      HSerInByte = 255
    
        Do 
            HSerReceive( HSerInByte, comport )
    
            If HSerInByte = 13 Then
                // Exit upon CR
                Exit Do    
            End If     
    
            If HSerInByte >= 48 and HSerInByte <= 57 Then
                // Ensure the calc only uses the first 5 chars
                If HSerIndex < 6 Then 
                    HSerIndex++
                    HSerNum = HSerNum * 10 + HSerInByte - 48  
                End If
            End If
    
        Loop
    
    End Sub
    
     

    Last edit: Anobium 2024-08-27
  • Anobium

    Anobium - 2024-08-27

    You can also check HSerIndex. If this is 0 or greater than 5 then the user entered either No value or the input exceeded the number of characters. So, you can add check to ensure you get a valid number entered.

    :-)

     
  • Anobium

    Anobium - 2024-08-27

    Here is my test program. Seems to work great.

    My choice of chip has no bearing on the operation of the function.

    This test program shows testing for 'nothing enterer'. You may be able to extended this to cover other cases.

    Let me know result on your solution. If this works I will update the master USART library.

    Evan

    #chip mega4809 
    #option Explicit
    
    #DEFINE USART3_BAUD_RATE 9600
    #DEFINE USART3_RX_BLOCKING
    #DEFINE USART3_TX_BLOCKING
    
    #DEFINE USART3_DELAY OFF
    
    Dim HSerNum as Word
    
    Do
    
        myHSerGetNum HSerNum
        If HSerIndex = 1 then 
            HserPrint "No number entered"
        Else
            HserPrint  HSerNum
        End If
    
        HserPrintCRLF
    
    Loop
    
    sub myHSerGetNum (Out HSerNum As Word, optional In comport = 1)
      Dim HSerInByte, HSerIndex
      HSerIndex = 1  
      HSerNum = 0
      HSerInByte = 255
    
        Do 
            HSerReceive( HSerInByte, comport )
    
            If HSerInByte = 13 Then
                // Exit upon CR
                Exit Do    
            End If     
    
            If HSerInByte >= 48 and HSerInByte <= 57 Then
                // Ensure the calc only uses the first 5 chars
                If HSerIndex < 6 Then 
                    HSerIndex++
                    HSerNum = HSerNum * 10 + HSerInByte - 48  
                End If
            End If
    
        Loop
    
    End Sub
    
     
  • Aleksandr

    Aleksandr - 2024-08-27

    thank you very much, I will unsubscribe after checking.

     
  • Anobium

    Anobium - 2024-08-27

    Aleksandr,

    Did you mean 'respond' after checking? I would remain subscribed to the post/forum in case we have another issue.

    Evan

     
  • Aleksandr

    Aleksandr - 2024-08-27

    Yes. I'll text you after checking the code.

     
  • Aleksandr

    Aleksandr - 2024-08-27

    I checked on one of the settings in Proteus, your code works. Thanks again. Will you be fixing the library in the near future?

     
  • Anobium

    Anobium - 2024-08-27

    Great.

    I tested on real AVRDx here and it worked. So, good to hear that is worked on a simulator.

    This will drop into the main release library today. But, it could be a few days before that is available as general release.

    I will upload the library here and then you will good to go.

     
  • Anobium

    Anobium - 2024-08-27

    Attached is the release candidate file.

    Replace the same file in your ..\GCSTUDIO\GCBASIC\INCLUDE\LOWLEVEL folder.

    Remove the sub() from your program and revert back to HSerGetNum().

    Evan


    Please leave a glowing/supportive review for the project https://sourceforge.net/projects/gcbasic/reviews/new?stars=5

     
  • Aleksandr

    Aleksandr - 2024-08-27

    Thank you so much for your work. I'll try the new library later. It was a pleasure for me to write you a great review.

     
  • Aleksandr

    Aleksandr - 2024-08-27

    Now I have replaced usart.h with a new one, deleted Sub myHserGetNum, rewrote all HSerGetString to HSerGetNum, the code has compiled. The program works in Proteus. Thanks again.

     

    Last edit: Aleksandr 2024-08-27
  • Anobium

    Anobium - 2024-08-27

    Excellent!

     

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.