1 Introduction
bcd code, also known as b / decimal code, a binary coded decimal code, design, digital circuit testing process, or the face of the hardware interface IC with bcd code, often want to easily and quickly generate bcd code to complete the current work, test the correctness of hardware circuits, such as PLL Frequency Synthesizer IC mc145163p with four bcd encoder interface for setting the loop n divider, through the completion of this article describes the production of bcd generator can provide 4 bit bcd code output, easy to control the output of each bcd, bcd coding can quickly get the completion of the test or received encoded output bcd bcd encoder interface IC, without frequent jumpers.
In addition, bcd coding with 8421 yards, 2421 yards, and other forms of more than three yards, 8421 yards this paper, a common implementation of an example circuit and program preparation. If a slightly modified version of the program can easily implement other types of encoding (such as 2421 yards). The circuit is designed to at89c2051 core 4 × 4 matrix keyboard (s0-s15), so just press the appropriate key on the keyboard (s0-s9) that can generate a corresponding (decimal 0-9) of the bcd code , by setting the toggle button (s10-s13) are free to control the four in any one, during the show in real time with a digital code corresponding to the current bcd decimal.
Circuit functions and features:
4 bcd encoded output, use of MCU port lines can be extended digits.
Change the software key number 0 – 9 number keys (ie, the corresponding function s0-s9) of the program can achieve other encoding forms (such as 2421 yards). See the software section.
Circuitry used 8421 yards, for example, and a digital display corresponding decimal number (can be omitted).
Complete 4 × 4 matrix keyboard scan program execution, the application can be ported to other circuits.
bcd coding for signal latched by the latch, and leads to interfaces to connect other circuit.
“Position” control and 0-9 encoded output independently of each other, press the function key you can directly obtain the required bcd coding output and the “median” choice.
2 circuit diagram
Circuit diagram shown in Figure 1.
3 Circuit Analysis
at89c2051 the p1 port 4 × 4 matrix composed of the keyboard (s0-s15), which p1.0-p1.3 as a line of wire, p1.4-p1.7 as a column line, designed keyboard scanner can achieve pre-conceived function ( See software design section). Press s0-s9 can produce 0-9 decimal code number corresponding to the bcd, s10-s13 for four bcd code switching button, s14, s15 yet to use, you can not install, p3.3-p3.0 is bcd code data output lines can be seen from the circuit, because the function of the keyboard and output to achieve four bcd coding, apparently p3.3-p3.0 and the same time as the data bus connected to the 4 d latch (4042), by s10-s13 to switch, latch for 4 d (u3-u6) only one time while the p3.3-p3.0 valid data “read” and then latched. In fact s10-s13 control p3.4 and p3.5 state (p3.4 and p3.5 four combinations) and by 2-4 line decoder (u2; 74ls139) corresponding u3-u6 be effective signal, Table 1 s10-s13 control state corresponding to each chip, we can see, u3-u6 in any one (for example, u3) is active and “read” p3.3-p3.0 data, the rest of the (u4 / u5/u6) in the latch state, to retain the original data, so users can change in any one of the desired bcd code output.
u2 (74ls139) is a 2-4 line decoder functions in Table 1, and his input b, a respectively connected to p3.4, p3.5, output y0-y3 depend on the input side, each one where only one output (y0-y3) to active-low output. u3-u6 is d latch, is one of the main 5 feet and 6 feet of the relationship determine their work status, access to information that, when 5 feet and 6 feet logic potential is the same, the chip can output data to d3-d0 to q3-q0; 5 feet and 6 feet when the logic is not the same potential, the chip is latched state of the original data, but not “read into” the current d3-d0 data circuits to u3-u6 6 feet fixed then low, and 5 feet respectively u2 (74ls139) of the output signal to control, it is easy to achieve, “you can achieve alone bcd code set.” 4511 is a decoder driver, then the common cathode LED displays the current corresponding to each of the bcd decimal code number to facilitate the observation, shows some very simple, not repeat them here, at the same time, show some of the circuit is not required, can be omitted , bcd code leads by j3 and j2, the reason for using two linker is to be more flexible and easy to use.
4 Software Design
Treatment is to achieve the main keyboard, the program must confirm which one button is pressed, then go to the appropriate handler execution, in fact, the program is a complete keyboard scanner, if the changes which the subroutine can apply to other control circuit, the following description with detailed procedures and for reference, Figure 2 is a flow chart.
Keyboard scanner simply, it is the task: First, to confirm whether there is button pressed, then scan to determine which line to get the key in the final 4 by comparing the pre-set line of table lookup and calculated specific key to turn procedures to the appropriate function.
(1) set out lines for the input state (p1.4-p1.7 1), line-line (p1.0-p1.3) the first is 0, that is set equal to f0h and p1.7-p1.0