RS232 serial communication not working
Moderator: Benj
RS232 serial communication not working
I want to communicate 18f452 device to PC through RS232 and try to display a byte number on hyperterminal. But only different symbols are display when i pressed any key on 18f452. Any idea to solve it
- Attachments
-
- SDR.jpg (44.45 KiB) Viewed 3931 times
-
- 452.fcf
- (19 KiB) Downloaded 237 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 serial communication not working
Hello,
You are simply printing the TOTAL variable as a byte if you look at the ASCII table then you can see that the values 0-255 will generate lots of different characters.
http://www.asciitable.com/
If you instead convert total to a string and then print the string then this will print the number as an ASCII set of digits representing the value of the number.
str = ToString$(TOTAL)
If you only want to print a single digit 0-9 then you can change the SendRS232Char parameter from TOTAL to TOTAL + '0'. This shifts the value up by the ASCII value for 0, again refer to the ASCII table link for info. You will also need to bounds check the TOTAL value so when incrementing and decrementing the value it cannot go lower than 0 or higher than 9.
Hope this helps.
You are simply printing the TOTAL variable as a byte if you look at the ASCII table then you can see that the values 0-255 will generate lots of different characters.
http://www.asciitable.com/
If you instead convert total to a string and then print the string then this will print the number as an ASCII set of digits representing the value of the number.
str = ToString$(TOTAL)
If you only want to print a single digit 0-9 then you can change the SendRS232Char parameter from TOTAL to TOTAL + '0'. This shifts the value up by the ASCII value for 0, again refer to the ASCII table link for info. You will also need to bounds check the TOTAL value so when incrementing and decrementing the value it cannot go lower than 0 or higher than 9.
Hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel