hi,
I got a code where one avr send message via usart and another avr receives and send back the same message after capitalization. So far capitalization works but I don't know how to include the space between the words. The received message is capitalized but there is no space between the words. Below is example code:
hi,
i removed delay but same effect. i just included delay because the words appeared so fast over the screen. actually i don't understand this part of the code:
mychar += ('A' - 'a');
It's probably -32, I think without looking it up. 'A' is 65 from memory. Lower case characters are a fixed distance from upper case. ASCII chart. It subtracts 32, thus converting LC to UC. It has to be done within a specific range,
Your original code basically says if it's LC convert to UC and send. If it's UC it won't get sent. Neither will numbers and control characters like CR and LF.
hi,
- putting usartsend(mychar); outside the while loop didn't do the trick.
- i now understand mychar += ('A' - 'a'); line, and i tried to use if and else statement for character and space, but how to detect space and send back the space? for example the following didn't work,
Put the "uartsend()" outside the IF tests. You want to call it no matter what. You should be using the IF tests just to alter the character from lowercase to uppercase.
So, now with the new code "
So "a12 3Xa" would only return "A XA"
I have no idea what you really want to do.
Some things you might want to do is convert LC to UC; make multiple spaces 1 space unless it's within quotes.
There is also stuff like carriage returns, line feeds, bells and even form feed. form feed sometimes erases the screen.
I did a neat program back in the mid 70's that would "pretty-print" a file in BASIC. We also had sources for the interpreter, but that was mostly immaterial. it was almost like writing a compiler.
order mattered. There was a token called "forinputasfile" which was replaced by " for input as file " to pretty print.
I did not handle adding or printing strings across line boundries. You could also interchange single and double quotes,.
The program helped make programs readable, though.
- i don't know why usartsend() should be outside the if statement, i want to send capitalized letter if i receive lower letters
- i am actually not sending any numbers only alphabets
As mentioned above, using a single equals is a very common mistake. To combat this I try to replace else if(mychar = ' '){ with else if(' ' = mychar){ as it will always throw an error at compile time is double equals isn't used.
As mentioned above, using a single equals is a very common mistake. To combat this I try to replace else if(mychar = ' '){ with else if(' ' = mychar){ as it will always throw an error at compile time is double equals isn't used.