
- •Table of Contents
- •Preface
- •Additional Material
- •Basic Electronics
- •1.0 The Atom
- •1.1 Isotopes and Ions
- •1.2 Static Electricity
- •1.3 Electrical Charge
- •1.4 Electrical Circuits
- •1.5 Circuit Elements
- •1.6 Semiconductors
- •Number Systems
- •2.0 Counting
- •2.1 The Origins of the Decimal System
- •2.2 Types of Numbers
- •2.3 Radix Representations
- •2.4 Number System Conversions
- •Data Types and Data Storage
- •3.0 Electronic-Digital Machines
- •3.1 Character Representations
- •3.2 Storage and Encoding of Integers
- •3.3 Encoding of Fractional Numbers
- •3.4 Binary-Coded Decimals (BCD)
- •Digital Logic, Arithmetic, and Conversions
- •4.0 Microcontroller Logic and Arithmetic
- •4.1 Logical Instructions
- •4.2 Microcontroller Arithmetic
- •4.3 Bit Manipulations and Auxiliary Operations
- •4.4 Unsigned Binary Arithmetic
- •4.5 Signed Binary Arithmetic
- •4.6 Data Format Conversions
- •Circuits and Logic Gates
- •5.0 Digital Circuits
- •5.1 The Diode Revisited
- •5.2 The Transistor
- •5.3 Logic Gates
- •5.4 Transistor-Transistor Logic
- •5.5 Other TTL Logic Families
- •5.6 CMOS Logic Gates
- •Circuit Components
- •6.0 Power Supplies
- •6.1 Clocked Logic and Flip-flops
- •6.2 Clocks
- •6.3 Frequency Dividers and Counters
- •6.4 Multiplexers and Demultiplexers
- •6.5 Input Devices
- •The Microchip PIC
- •7.0 The PICMicro Microcontroller
- •7.1 PIC Architecture
- •Mid-range PIC Architecture
- •8.0 Processor Architecture and Design
- •8.1 The Mid-range Core Features
- •8.2 Mid-Range CPU and Instruction Set
- •8.3 EEPROM Data Storage
- •8.4 Data Memory Organization
- •8.5 Mid-range I/O and Peripheral Modules
- •PIC Programming: Tools and Techniques
- •9.0 Microchip’s MPLAB
- •9.1 Integrated Development Environment
- •9.2 Simulators and Debuggers
- •9.3 Programmers
- •9.4 Engineering PIC Software
- •9.5 Pseudo Instructions
- •Programming Essentials: Input and Output
- •10.0 16F84A Programming Template
- •10.1 Introducing the 16F84A
- •10.2 Simple Circuits and Programs
- •10.3 Programming the Seven-segment LED
- •10.4 A Demonstration Board
- •Interrupts
- •11.0 Interrupts on the 16F84
- •11.1 Interrupt Sources
- •11.2 Interrupt Handlers
- •11.3 Interrupt Programming
- •11.4 Sample Programs
- •Timers and Counters
- •12.0 The 16F84 Timer0 Module
- •12.1 Delays Using Timer0
- •12.2 Timer0 as a Counter
- •12.3 Timer0 Programming
- •12.4 The Watchdog Timer
- •12.5 Sample Programs
- •LCD Interfacing and Programming
- •13.0 LCD Features and Architecture
- •13.1 Interfacing with the HD44780
- •13.2 HD44780 Instruction Set
- •13.3 LCD Programming
- •13.4 Sample Programs
- •Communications
- •14.0 PIC Communications Overview
- •14.1 Serial Data Transmission
- •14.2 Parallel Data Transmission
- •14.4 PIC Protocol-based Serial Programming
- •14.5 Sample Programs
- •Data EEPROM Programming
- •15.0 PIC Internal EEPROM Memory
- •15.1 EEPROM Devices and Interfaces
- •15.2 Sample Programs
- •Analog to Digital and Realtime Clocks
- •16.0 A/D Converters
- •16.1 A/D Integrated Circuits
- •16.2 PIC On-Board A/D Hardware
- •16.3 Realtime Clocks
- •16.4 Sample Programs
- •Index

Data Types and Data Storage |
|
|
|
|
|
|
|
|
|
51 |
|||||||||||||||||||||||||||
|
|
|
|
sign of number |
|
|
|
|
|
|
|
|
|
implied leading digit |
|||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||||||||||
|
|
|
|
|
|
|
field |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
10000101 |
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||||||||||
|
|
|
|
1.1111110 |
1100000 00000000 |
|
|
|
|
|
|||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||
|
|
|
|
|
exponent |
|
|
|
|
|
|
|
|
|
significand |
|
|
|
|
|
|
|
|
|
|||||||||||||
|
|
|
|
|
|
field |
|
|
|
|
|
|
|
|
|
|
|
field |
|
|
|
|
|
|
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42H |
|
FEH |
|
|
|
C0H |
|
|
|
00H |
|||||||||||||||||||||
MEMORY LAYOUT OF 127.375 |
|
MEMORY LAYOUT MAP FOR |
|||||||||||||||||||||||||||||||||||
IN LITTLE-ENDIAN FORMAT |
|
IEEE SINGLE FORMAT |
LOW ADDRESS
LOW ADDRESS
0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 0
0 1 0 0 0 0 1 0
HIGH ADDRESS
|
legend: |
m |
m |
m |
m |
m |
m |
m |
m |
|
00H |
s = sign bit |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
|
e = exponent bit |
||||||||||
|
|
|
|
|
|
|
|
|||
C0H |
m = mantissa bit |
m |
m |
m |
m |
m |
m |
m |
m |
|
|
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
||
|
|
|||||||||
FEH |
|
|
|
|
|
|
|
|
|
|
|
e |
m |
m |
m |
m |
m |
m |
m |
||
42H |
|
8 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
|
|
|
||
|
|
s |
e |
e |
e |
e |
e |
e |
e |
|
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
|
|
|
|
|
|
|
|
|
|
HIGH ADDRESS
Figure 3-8 Encoding of the Number 127.375 in IEEE Single Format
bit value: 11111110-11000000-00000000 = 16,695,296
|------ |
| |--------------- |
| |
| |
| |
|
| |
|________ |
fractional part |
|____________________ |
integer part |
number: 127.375
3.4 Binary-Coded Decimals (BCD)
Floating-point encodings are the most efficient format for storing numerical data in a digital device and binary arithmetic is the fastest way to perform numerical calculations. But other representations are also useful. BCD (binary-coded decimal) is a way of representing decimal digits in binary form. There are two common ways of encoding decimal digits in binary format. One is known as the packed BCD format and the other one as unpacked. In the unpacked format each BCD digit is stored in one byte. In packed form two BCD digits are encoded per byte. The unpacked BCD format does not use the four high-order bits of each byte, which is wasted storage space. On the other hand, the unpacked format facilitates conversions and arithmetic operations on some machines. Figure 3.9 shows the memory storage of a packed and unpacked BCD number.

52 Chapter 3
UNPACKED BCD |
|
PACKED BCD |
|
||||||||||
|
|
|
|
2 |
|
|
23 |
||||||
|
0 0 0 0 |
0 0 1 0 |
|
|
|
||||||||
|
|
0 0 1 0 |
0 0 1 1 |
||||||||||
|
|
|
|
3 |
|
|
79 |
||||||
|
0 0 0 0 |
0 0 1 1 |
|
0 1 1 1 |
1 0 0 1 |
||||||||
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
|
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Figure 3-9 Packed and Unpacked BCD
3.4.1 Floating-Point BCD
Unlike the floating-point binary numbers, binary-coded decimal representations and
BCD arithmetic have not been explicitly described in a formal standard. Each machine or software package stores and manipulates BCD numbers in a unique and often incompatible way. Some machines include packed decimal formats, which are sign-magnitude BCD representations. These integer formats are useful for conversions and input-output operations. For performing arithmetic calculations a float- ing-point BCD encoding is required. This approach provides all the advantages of floating-point as well as the accuracy of decimal encodings.
The BCD floating-point format which we call BCD12 is shown Figure 3-8.
sign of number (1 BCD digit) sign of exponent (1 BCD digit)
exponent (4 BCD digits) significand (18 BCD digits)
S s e e e e m m m m m m m m m m m m m m m m m m
Figure 3-10 Map of the BCD12 Format
BCD12 requires 12 bytes of storage and is described as follows:
1.The sign of the number (S) is encoded in the left-most packed BCD digit. Therefore, the first four bits are either 0000B (positive number) or 0001B (negative number).
2.The sign of the exponent is represented in the four low-order bits of the first byte. The sign of the exponent is also encoded in one packed BCD digit. As is the case with the sign of the number field, the sign of the exponent is either 0000B (positive exponent) or 0001B (negative exponent)
3.The following two bytes encode the exponent in four packed BCD digits. The decimal range of the exponent is 0000 to 9999.
4.The remaining nine bytes are devoted to the significand field, consisting of 18 packed BCD digits. Positive and negative numbers are represented with a significand normal-

Data Types and Data Storage |
53 |
ized to the range 1.00...00 to 9.00...99. The decimal point following the first significand digit is implied. The special value 0 has an all-zero significand.
5.The special value FF hexadecimal in the number’s sign byte indicates an invalid number.
The structure of the BCD12 format is described in Table 3.4.
Table 3.4
Field Structure of the BCD12 Format
CODE |
FIELD NAME |
BITS WIDE |
BCD DIGITS |
|
RANGE |
|
|
|
|
|
|
S |
sign of number |
4 |
1 |
0 |
- 1 (BCD) |
S |
sign of exponent |
4 |
1 |
0 |
- 1 (BCD) |
E |
exponent |
16 |
4 |
0 |
- 9999 |
M |
significand |
72 |
18 |
0 |
- 99..99 (18 digits) |
|
|
----- |
|
|
|
|
Format size |
96 (12 bytes) |
|
|
|
Notes:
1.The significand is scaled (normalized) to a number in the range 1.00..00 to 9.99..99.
2.The encoding for the value zero (0.00..00) is a special case.
3.The special value FFH in the sign byte indicates an invalid number.
The BCD12 format, as is the case in all BCD encodings, does not make ideal use of the available storage space. In the first place, each packed BCD digit requires four bits, which in binary could serve to encode six additional combinations. At a byte level the wasted space is of 100 encodings (BCD 0 to 99) out of a possible 256 (0 to FFH). The sign field in the BCD12 format is wasteful since only one binary digit is actually required for storing the sign. Regarding efficient use of storage, BCD formats cannot compete with floating-point binary encodings. The advantages of BCD representations are a greater ease of conversion into decimal forms, and the possibility of using the processors’ BCD arithmetic instructions.