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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
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.
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
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 thanHSerGetNum
Let me know if this resolves.
Your program is great.
Evan
Last edit: 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.
:-)
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
thank you very much, I will unsubscribe after checking.
Aleksandr,
Did you mean 'respond' after checking? I would remain subscribed to the post/forum in case we have another issue.
Evan
Yes. I'll text you after checking the code.
I checked on one of the settings in Proteus, your code works. Thanks again. Will you be fixing the library in the near future?
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.
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
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.
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
Excellent!