Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.
4 posts • Page 1 of 1
On a microcontroller numbers can be represented by variables in memory. The size of memory allocated for storing the numbers are defined by the maximum size of the number you wish to use. A byte variable otherwise known as a char or 8-bit variable can hold a maximum number of 255. An integer variable otherwise known as a word or 16-bit variable can hold a maximum number of 65535. However Flowcode uses signed integer variables to allow for negative numbers so the range is actually -32768 to 32767.
Numbers can be inputted into the system as decimal, hexadecimal or binary format. On the microcontroller itself each of these formats are handled in binary so there is no potential pit falls or reasons to use one format over another. Therefore it is down to preference.
Hexadecimal is popular as it is very easy to convert between hex and binary in your head. To convert from hex to binary simply look at a character at a time and associate a 4-bit binary pattern.
A hexadecimal value of 0x5A represents binary 01011010.
A hexadecimal value of 0x5A5A represents binary 0101101001011010.
Now comes the slightly tricky bit : ASCII data.
ASCII is a means of assigning characters and control commands to a byte variable or 8-bit number. This is used in everyday items like computer keyboards to encapsulate the keystrokes into single byte data. It is important to note that an ASCII byte's data is exactly the same as a normal byte it is however the meaning that is different.
Numeric Byte value of 48 decimal (0x30 hexadecimal) = ASCII Value '0'
For a complete list of ASCII codes please refer here: http://www.asciitable.com/
The LCD prints out characters as ASCII code so therefore we need a way of transferring the single byte variable into a string of ASCII data.
Byte variable 255 needs to be converted into ASCII string "0xFF" - 4 bytes long
Int variable 65535 needs to be converted into ASCII string "0xFFFF" - 6 bytes long
Two software macros have been provided to allow for numbers to be converted from byte or integer variables into ASCII strings, which are then send out to a LCD display. The macros can be included into your programs by using the Macro -> Import menu. The LCD could however be replaced by an RS232 bus or similar for outputting hexadecimal strings.
- Number to Hex.zip
- (4.49 KiB) Downloaded 810 times