![]() If you want to see actual ASCII characters, you will need to add a character '0' (0x30) to each value, like this: char nibble Since these are not proper ASCII digits, they will not show up properly under the ASCII display setting. The nibbles will then display on the screen as 03 04. To display the characters, once again you need to put RealTerm into Hex mode. This could be put into a loop, but it's easier to see this way. Next, you can send the 8-bit value in hex, one 4-bit nibble at a time: char data = 52 // or char data = 0x34 If you changed the display to ASCII, it would instead show just a 4 since the ASCII code for 4 is 0x34, which is an incorrect representation for the value that was sent. ![]() Since hex 34 (3*16 + 4) is the same as 52. If you hooked a terminal program like RealTerm, set it up to receive your data, and set the Display As to Hex it will show the value in hexadecimal as: char data = 52 // or char data = 0x34 Īnd sent the data over the UART TXREG = data If you send a single 8-bit value from a UART to another computer, it will just be a binary value. Converting the binary integer 9525 to the characters "9525" is trivial for the PC, but can require substantial code space and cycles on a small PIC. ![]() Generally it's a lot easier to do any kind of user interface conversion on the PC and let the PIC send and receive native binary. That is a lot more complicated since the PIC has to figure out the decimal digits of the binary integer it has, convert them to the character codes for those digits, then send those. If you wanted the terminal to display "9525" you'd have to send the byte values for the characters "9", "5", "2", and "5". So the terminal will display "5%" when you send 9525. If these bytes were to be intercepted by a terminal, then you'd get whatever characters map to 53 and 37, which happen to be "5" and "%". Note that (37 * 256) + 53 = 9525, which is the value you are transmitting. You send these bytes, and the other PIC receives 53 and 37. The two bytes you will send are therefore 35h and 25h in that order. You have previously decided to send multi-byte values in low to high byte order. Let's convert that to HEX so we can see the individual bytes easily: 2535h. Suppose you wanted to send the 16 bit integer value 9525. Here is a example to illustrate all of the above. That will tell you what the byte values are for each of the characters the terminal can show. Likewise, sending 48 causes the terminal to show "0". If you send the byte 65, then a terminal will show "A". For example, the code for the letter "A" is 65. You send the byte containing the code for a character, and that character shows up on the terminal. ![]() Each possible character has a pre-determined binary code. Note that none of this has anything to do with sending numeric values to show up on a terminal emulator. It receives the low 8 bits first, then the high 8 bits, and writes those consecutively in memory so that the rest of the system can access the value as a 16 bit integer.Ģ4 bit integers, for example, are sent the same way except that 3 bytes are needed instead of 2. If you have a 16 bit integer to send, then you send the low 8 bits first, then the high 8 bits. For example, you might decide that all multi-byte integers are to be sent in least to most significant byte order. If you want to send a wider integer, you have to send more than one byte to represent that integer. The UART inherently only sends 8 bit bytes (in the most common configuration) at a time. Your problem is apparently sending integers that are more than 8 bits wide. You already are sending integer values over the UART with the code you show.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |