ES M2-Note2
ES M2-Note2
ES M2-Note2
In microcontrollers, certain information is stored in the form of packed BCD. A packed BCD
contains two decimal digits in a byte. Eg: 34, 76 etc. An unpacked BCD contains one decimal digit
in a byte. Eg: 05, 07 etc. To display these information, we have to convert it into ASCII. ASCII
codes of the digits 0 to 9 are 30 to 39 respectively. It means that to display the digit 7, we have to
first convert it into its ASCII code 37 (ie. 30 is added). Similarly to get the numerical value of
ASCII code, we have to subtract 30 from it.
Programming Example:
Binary (Hex) to Decimal conversion:
Hexadecimal format is a convenient method to represent binary data. The binary data 00–FFH
converted to decimal will give us 000 to 255. One method of converting it to decimal is dividing it
by 10 and keeping the remainder.
Example: Covert 0xFD to decimal. Its decimal value is 253.
DATA SERIALIZATION
Sometimes we need to send a byte of data one bit at a time through a single pin of a microcontroller.
There are two ways to send data serially:
1. Using serial port
2. Data serialization.
Using serial port method, the programmer has very limited control over the sequence of data
transfer. In data serialization, the data bits can be send under the program control. So the
programmer can determine the timing and bit sequence of the data.
Programming Examples:
If we want to send the MSB first, then the following changes can be made in the for loop:
MEMORY ALLOCATION
We can store predefined fixed data in any of the following three spaces in AVR microcontroller:
• SRAM
• EEPROM
• Flash (code ROM)
The size of these spaces depends on the microcontroller. To allocate space for data in EEPROM and
Flash, different C compilers use different directives or built-in functions. Following is one of the
method to allocate space in EEPROM and Flash.