View previous topic :: View next topic |
Author |
Message |
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Sat Apr 11, 2015 11:17 pm Post subject: Backspacing on input inputs backspaces! |
|
|
When I try to input an 8 character long string and use backspaces, the backspaces actually enter the array! Instead, they should remove the last character in the input buffer, but why don't they?
Here's my code
Code: | Dim ime As String * 8
Input ime
Print ime |
On the terminal, when you enter ABCD(backspace)(backspace)EFGH, the input doesn't let you enter GH because the buffer is filled with the backspaces. However, the output is ABEF.
Is there a way to go around this?
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Sat Apr 11, 2015 11:55 pm Post subject: Search for inkey(), Waitkey, ischarwaiting and $timeout |
|
|
Search in the help for inkey()
Action
Returns the ASCII value of the first character in the serial input buffer.
Syntax
var = INKEY()
var = INKEY(#channel)
Remarks
Var
Byte, Integer, Word, Long or String variable.
Channel
A constant number that identifies the opened channel if software UART mode
If there is no character waiting, a zero will be returned.
Use the IsCharWaiting() function to check if there is a byte waiting.
The INKEY routine can be used when you have a RS-232 interface on your uP.
The RS-232 interface can be connected to a comport of your computer.
As zero(0) will be returned when no character is waiting, the usage is limited when the value of 0 is used in the serial transmission. You can not make a difference between a byte with the value 0 and the case where no data is available.
In that case you can use IsCharwaiting to deterimine if there is a byte waiting.
See also
WAITKEY , ISCHARWAITING , $TIMEOUT
Have fun
Ben Zijlstra |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Apr 12, 2015 12:20 am Post subject: |
|
|
Hello Zvoc47
If you are entering characters via a computer and terminal program
and want the backspace to remove characters in a buffer in the AVR
you need to write a sub that does this
I found that more than one value was sent by different terminal programs.
The good news is I have already done all the work.
In the blog section http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewforum&f=19
You will find my Web Servers
The code for a working command prompt with backspace is there as a separate sub that you can use in your own program.
Regards Paul |
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Sun Apr 12, 2015 1:09 am Post subject: |
|
|
But which file is it? |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Apr 12, 2015 10:30 am Post subject: |
|
|
Ok I cut out the code so you can see it
now it depends which terminal program you use as to which character is backspace
some I have found send more than one character
here it is chr 8
so just attach an LCD to the avr and print the character number to the lcd
this is what I did to see what was received in the buffer
Uartrx is the sub that decides what to do with the data sent
Regards Paul
Code: |
'-------------------------------------
'--This will create a command line prompt so that
'--we can use rs232 to communicate with the AVR
Charwaiting = Ischarwaiting()
If Charwaiting = 1 Then
Uart_char = Inkey()
'Print Uart_char;
If Len(uart_command) > 30 Then
Uart_char = 13 'this is the Enter key
End If
Select Case Uart_char
Case 27 'the escape character to abort entry
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
'--- here we backspace characters in the buffer
Case 8
Print Chr(8); 'the backspace
Karpos = Len(uart_command) 'find the length of Uart_command
If Karpos > 0 Then 'if it has characters
Delchar Uart_command , Karpos 'delete last character
End If
Case 13
Call Uartrx
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case Else
Uart_command = Uart_command + Chr(uart_char) 'this adds each character to the string
Print Chr(uart_char); 'this echos the commad back to the screen
'so the user can see what they have typed
End Select
End If
|
|
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Sun Apr 12, 2015 8:24 pm Post subject: |
|
|
Thanks.
If uart_command is long 78 characters, will Code: | Uart_command = Uart_command + Chr(uart_char) | use up 157 bytes? I need to be cautious with the space I use and I must know how long the frame should be. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Apr 13, 2015 9:45 am Post subject: |
|
|
You would need one byte for every character then there is another byte at the end of the string.
I see you are using Local variables this is good as it saves ram but remember they do not get cleared.
I use split to search strings it can replace mid() in many cases but it needs a global array
It has saved me a lot of code.
If you use a mega128 you should not run out of ram I have variables that are 1000 characters in my web servers
and still have spare ram I run out of flash before ram.
Also I use IsCharwaiting so that I do not stop and wait.
Regards Paul |
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Mon Apr 13, 2015 2:54 pm Post subject: |
|
|
Don't worry. They don't need automatic clearing. And as much as I see, they are "popped" from the stack in such a way when the function is re-entered, they are overwritten with new ones. This means no memory leak
This is my code:
Code: | $regfile = "xm128a1def.dat"
$Crystal=32000000
$hwstack=4160 ' This is because I put SPH to $2F instead of $3F
$swstack=16
$framesize=32
$baud = 115200
Config Serialin = Buffered , Size = 80
Config Serialout = Buffered , Size = 254
Declare Sub UsartInput(byref Target As String, byval MaxChars As Integer)
Enable interrupts
Dim ime As String * 8
SPH=$2F
Do
Call UsartInput(ime,8)
Print ime
Loop until lcase(ime)="over"
do
print "Over!"
Waitms 100
loop
End
Sub UsartInput(byref Target As String, byval MaxChars As Integer)
Local A As Byte
Local Index As Integer
Local WhiteSpace As Byte
Local I As Byte
InputAgain:
Target=""
Index=0
WhiteSpace=0
Do
A=WaitKey()
If A=8 Then
If Index>0 Then
Print Chr(8);" ";Chr(8);
Decr Index
Target=left(Target,Index)
End if
Else
If A>31 And A<127 Then
If Index<MaxChars Then
Incr Index
Target=Target+Chr(A)
Print Chr(A);
End If
End If
End If
Loop Until A=13
WhiteSpace=1
If Index>0 Then
For I=1 To Index
If Mid(Target,I,1)<>" " Then WhiteSpace=0
Next I
End If
If WhiteSpace=1 Then
Print ""
Goto InputAgain
End If
Print ""
End Sub |
And I'm using ATXMEGA128A1.
And the best of all, the code works!
Except for waitms 100 waiting 1.5 seconds.[/code] |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue Apr 14, 2015 1:08 am Post subject: pll |
|
|
For the wait problem do a search on PLL.
in the wiki, the 7 inch display is driven bij an Atxmega128a1 and at the top of the program PLL settings.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Fri Apr 17, 2015 3:46 pm Post subject: |
|
|
I don't understand. I don't think I'm using PLL. I have a 32MHz crystal. Is there a way to check this? |
|
Back to top |
|
|
|