Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 8566

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Circuit Components

121

eral methods of switch debouncing have been developed. These can be divided into timing-based schemes and hysteresis-based schemes. Timing-based techniques are based on adding sufficient delays so as to prevent the bounce from being detected.

The main advantage of using timing to control bouncing is that it does not require any special switch design. Alternatively, it is possible to use hysteresis to separate the positions where the make and break actions are detected. We discussed hysterisis in the context of Schmitt trigger inverters, which are actually switches, in Section 5.6.8.

The actual hardware circuits used in switch debouncing belong to three common types: RS flip-flops, CMOS gate debouncers, and integrated RC circuit debouncers. The debouncing action of the RS flip-flop is obvious from its operation, that is, when the key is in a position in which neither contact is touched (key bouncing) the inputs are pulled low by the pull-down resistors. In this case, the key appears as being pressed. Before being pressed, the key is touching the set input and appears as an RS flip-flop, which was covered in Section 6.1.2.

Alternatively, switch debouncing can be accomplished by means of CMOS buffer circuit with high input impedance. One such circuit is the 4050 hex buffer IC, with eight input and eight output gates. When the switch is pressed, the input line of the 4050 chip is gounded, and output is forced low. The output voltage, by means of an internal resistor, is also kept low when the switch is bouncing. The effect is that the switch action is debounced.

Finally, switch debouncing can be implemented by means of a simple resis- tor-capacitor circuit. The circuit action is based on the rate at which the capacitor recharges once the ground connection is broken by the switch. As long as the capacitor voltage is below the threshold level of the logic zero value, the output signal continues to appear as logic zero.

6.5.3 Keypads

In the context of microcontroller-based circuits, a keypad (also called a numeric keypad) is a set of pushbutton switches sometimes labeled with digits, mathematical symbols, or letters of the alphabet. For example, a calculator keypad contains the decimal (occasionally hexadecimal) digits, the decimal point, and keys for the mathematical features of the calculator. Although in theory the computer keyboard is a keypad, the keypad is usually limited to a smaller arrangement of buttons or to part of a computer keyboard consisting mainly of numeric keys.

By convention, the keys on calculator-style keypads and keypads on computer keyboards are arranged such that the keys 123 are on the bottom row. On the other hand, telephone keypads have the 123 keys on the top row.

Keypads are usually implemented as pushbutton switches located in a row and column matrix. The location of any key on the keypad can be based on two coordinates: the row and column position for that key. Therefore only eight outputs are required from the keypad: one for each row and one for each column. Determining which switch on a keypad has been activated can be done either by polling or by means of an interrupt routine. In the polling approach the controller checks the sta-

122

Chapter 6

tus of each switch in a loop. A more efficient approach is to implement and inter- rupt-driven routine that notifies the processor of a keystroke.

Keypads, like the switches that they incorporate, require debouncing. The three methods of switch debouncing described in Section 6.5.2 apply to keypads.

6.6 Output Devices

As is the case with input devices, electronic systems, including computers and microcontrollers, must provide data output in a human-readable form. Here again, computer technology uses many different types of output devices, including video displays, printers, plotters, film recorders, projectors, sound systems, and even holographic devices. Although these output devices cannot be excluded from use in microcontroller systems, they use simpler and limited output means. In this section we discuss two common output devices used in microcontroller-based circuits: the seven-segment LED and the liquid crystal display. Simple devices, such as LEDs and buzzers, are sometimes used as output devices. LEDs were covered in Chapter 5. Buzzers are such simple components that their operation does not require a detailed explanation.

6.6.1 Seven-segment LED

Digital devices often need to output a numeric value. Although individual LEDs can be combined to represent binary, decimal, or hexadecimal digits, a far more convenient device consists of seven built-in LEDs which can be combined to represent all ten decimal digits and even the six letters of the hex character set. Such a circuit is furnished in a single IC, called a seven-segment LED, that is common in clocks, watches, calculators, and household appliances.

Seven-segment displays have been in use since the first generation of calculators came to market. The scheme consists of placing lighted bars in a figure-eight pattern. By selecting which bars are lighted, all the digits and some letters of the alphabet can be represented. In addition, seven-segment LEDs are usually capable of displaying one or two decimal points. Figure 6-30 shows the layout of a seven-segment LED and the combinations to generate the decimal and hex digit sets.

Note in Figure 6-30 that two of the letters (b and d) of the hexadecimal set are displayed in lower-case while the others are in upper-case. This is a limitation of the seven-segment LED since an upper-case letter “D” would coincide with the digit “0", and an upper-case letter ”B" with the digit “8.”

Some seven-segment LED displays are slanted to make the digits appear in italics. It is used in clock displays where the two digits are inverted so that the decimal points appear like a colon between the digits. In addition seven-segment displays are packaged in several different ways. Sometimes several digits are combined in a single IC. Another packaging is in the form of a 14-pin DIP.


Circuit Components

123

a

f

b

g

e

c

d

a-b-c-d-e-f

a-b

a-b-g-e-d

a-b-g-c-d

f-g-b-c

a-f-g-c-d a-f-g-e-c-d

a-b-c

a-b-c-d-e-f-g a-b-c-f-g a-b-c-g-f-e f-g-e-c-d

a-f-e-d

b-c-d-e-g a-f-g-e-d

a-f-g-e

Figure 6-30 Seven-Segment LED Layout and Digit Patterns

Seven-segment displays are also furnished using display technologies other than LEDs. Many line-powered devices and home appliances, such as clocks and microwave ovens, use fluorescent seven-segment displays. Battery-powered devices, such as watches and miniature digital instruments, use seven-segment liquid crystal displays. Liquid crystal technologies are covered in sections that follow.

The LEDs in a seven-segment display are interconnected. The two interconnection modes are to wire together the cathodes of all individual LEDs, or to do so with the anodes. In one case the device is said to have a common-cathode and in the other one a common-anode. This circuit scheme simplifies the wiring and reduces the number of connections, since only one line is necessary for controlling each LED. There is no intrinsic advantage to either system since each one is suited to different applications. Figure 6-31, on the following page, shows the pin diagram for a common-cathode seven-segment LED in a DIP package.

124

Chapter 6

Anode F

1

14

Anode A

Anode G

2

13

Anode B

12

Common cathode

Common cathode

4

Anode E

6

9

Anode DP

Anode D

7

8

Anode C

Figure 6-31 Pin Diagram for a Common Cathode Seven-Segment LED

6.6.2 Liquid Crystal Displays

A liquid crystal display (LCD) is a pixilated output device capable of displaying ASCII characters and dot-based graphics. LCDs can be color or monochrome according to their construction. One of the advantages of LCD displays is their very small consumption of electrical power, making them suitable for battery-powered devices. In operation the liquid crystal display consists of two pieces of polarized glass with perpendicular axes of polarity. Sandwiched between the polarizers is a layer of nematic crystals, as shown schematically in Figure 6-32.

In the top image of Figure 6-32 light cannot pass through the system since the liquid crystal layer preserves the original angle of vibration of the light which cannot pass through the polarizer. In the lower image the various molecular layers of the liquid crystal are twisted approximately 90 degrees. This twisting of the liquid crystal also changes the light’s pane of vibration. So when light reaches the second polarized filter it vibrates at the same angle as the final molecule layer of the liquid crystal and can pass through the polarizer. Note that the electrical current applied to the crystals has the effect of straightening the various molecular layers. When the current is released, the various molecular layers resume their twisted form. By varying the amount of twist in the liquid crystals the amount of light that passes through can be controlled.


Circuit Components

125

Polarizers

Light

Liquid crystal

Polarizers

Light

Figure 6-32 Schematic Representation of a LCD Display

6.6.3 LCD Technologies

Depending on the positioning of the light source LCDs can be either transmissive or reflective. A transmissive LCD is illuminated from the back and viewed from the front. This type is common in applications that require high levels of illumination, as is the case with computer displays and television sets. Reflective LCDs, on the other hand, are illuminated by an external source. This type finds use in digital watches and calcu-

126

Chapter 6

lators. Reflective technology produces a darker black color than the transmissive type, since light is forced to pass twice through the liquid crystal layer. Since reflective LCDs do not require a light source they consume less power than the transmissive ones. A third type, called transflective LCDs, work as either transmissive or reflective LCDs, depending on the ambient light.

LCDs can be color or monochrome. In color systems each individual pixel consists of three cells, which are colored red, green, and blue. These cells, sometimes called subpixels, are controlled independently to yield thousands (or even millions) of possible colors for each pixel. Most LCDs used in microcontroller systems are monochrome.

According to display technology, LCDs are alphanumeric or dot-addressable. The alphanumeric type, most frequently used in microcontroller applications, uses a matrix composed of linear segments. Figure 6-33 shows several possible electrode configurations of LCDs.

The first two electrode configurations in Figure 6-33 are based on linear segments similar to the ones in seven-segment LEDs. Segmented electrodes are suitable for simple alphanumeric displays as are often required in small digital devices such as watches or calculators. To display entire character sets or graphics, a dot-address- able matrix of electrodes is necessary. This setup is shown in the rightmost image in Figure 6-34. However, such power comes at a price, since the more addressable elements in the display, the greater the number of connections and the more complex the driver logic required to operate the system. Note that the 5 x 7 matrix display in Figure 6-34 actually contains eight dot rows. The reason is that the lowest row is used for displaying the cursor. Most popular LCD displays for microcontroller circuits use the 5 x 7 matrix format.

7 segments

16 segments

5 x 7 matrix

Figure 6-33 Electrode Configurations in LCD Displays


Circuit Components

127

One way of reducing the number of electrical connections in an LCD is by means of a method called passive matrix display. Here the pixels to be lighted are determined by the crossing points between the row and the column selector electrodes.

For example, in the 5 x 7 matrix display in Figure 6-34, the pixel at the center of the character is selected by picking row number 4 and column number 3. The name passive matrix originates in the fact that each pixel must retain its state between refreshes. As the number of pixels to be refreshed increases so does the time required for the refresh cycle. As a consequence of their design, passive matrix displays usually have slow response times and poor contrast.

In high-resolution and color LCDs an active matrix display is used. In this design a grid of thin-film transistors is added to the polarizing and color filters. Each pixel contains its own dedicated transistor and each row line and column line is addressed individually. During the refresh cycle each pixel row is activated sequentially. Active matrix displays are brighter and sharper and have quicker response t i m e t h a n p a s s i v e m a t r i x . A c t i v e m a t r i x d i s p l a y s a r e a l s o k n o w n a s thin-film-transistor or TFT displays.


Chapter 7

The Microchip PIC

A microcontroller is a type of microprocessor furnished in a single integrated circuit and needing a minimum of support chips. Its principal nature is self-sufficiency and low cost. It is not intended to be used as a computing device in the conventional sense; that is, a microcontroller is not designed to be a data processing machine, but rather an intelligent core for a specialized dedicated system.

Microcontrollers are embedded in many control, monitoring, and processing systems. Some are general-purpose devices but most microcontrollers are used in specialized systems such as washing machines, telephones, microwave ovens, automobiles, and weapons of many kinds. A microcontroller usually includes a central processor, input and output ports, memory for program and data storage, an internal clock, and one or more peripheral devices such as timers, counters, analog-to-digital converters, serial communication facilities, and watchdog circuits.

More than two dozen companies in the world manufacture and market microcontrollers. They range from 8- to 32-bit devices. Those at the low end are intended for very simple circuits and provide limited functions and program space, while those at the high end have many of the features associated with microprocessors. The most popular ones include several from Intel (such as the 8051), Zilog (derivatives of their famous Z-80 microprocessor), Motorola (such as the 68HC05), Atmel (the AVR), Parallax (the BASIC Stamp), and Microchip. Some of the latter ones are the main topic of this book.

7.0 The PICMicro Microcontroller

PIC is a family of microcontrollers made by Microchip Technology. The original one was the PIC1650 developed by General Instruments. This device was called PIC for “Programmable Intelligent Computer” although it is now associated with “Programmable Interface Controller.” Microchip does not use PIC as an acronym. Instead they prefer the brand name PICmicro. Popular wisdom relates that PIC is a registered brand in Germany and Microchip is unable to use it internationally.

129

130

Chapter 7

The original PIC was built to be used with General Instruments’ CP1600 processor, which had poor I/O performance. The PIC was designed to take over the I/O tasks for the CPU, thus improving performance. In 1985, the PIC was upgraded with EPROM to produce a programmable controller. Today, a huge variety of PICs are available with many different on-board peripherals and program memories ranging from a few hundred words to 32K.

PICs use an instruction set that varies in length from about 35 instructions for the low-end PICs to more than 70 for the high-end devices. The accumulator, which is known as the work register in PIC documentation, is part of many instructions since the PIC contains no other internal registers accessible to the programmer. The PICs are programmable in their native Assembly Language, which is straightforward and not difficult to learn. In addition, C language and BASIC compilers have been developed for the PIC. Open-source Pascal, JAL, and Forth compilers are also available for PIC programming.

One of the reasons for the success of the PIC is the support provided by Microchip. This includes a professional-quality development environment called MPLAB which can be downloaded free from the company’s website (). The MPLAB package includes an assembler, a linker, a debugger, and a simulator. Microchip also sells a low-cost in-circuit debugger called MPLAB ICD 2. Other development products intended for the professional market are available from Microchip. The Microchip website furnishes hundreds of free support documents, including data sheets, application notes, and sample code.

In addition to the documents and products in the Microchip website, the PIC microcontrollers have gained the support of many hobbyists, enthusiasts, and entrepreneurs who develop code and support products and publish their results on the Internet. This community of PIC users is a treasure trove of information and know-how easily accessible to the beginner and useful even to the professional. One such Internet resource is an open-source collection of PIC tools named GPUTILS, which is distributed under the GNU General Public License. GPUTILS includes an assembler and a linker. The software works on Linux, Mac OS, OS/2, and Windows. Another product named GPSIM is an Open Source simulator featuring PIC hardware modules.

7.0.1 Programming the PIC

Programming a PIC microcontroller requires the following tools and components:

1.An Assembler or high-level language compiler. The software package usually includes a debugger, simulator, and other support programs.

2.A computer (usually a PC) in which to run the development software.

3.A hardware device called a programmer that connects to the computer through the serial, parallel, or USB line. The PIC is inserted in the programmer and “blown” by downloading the executable code generated by the development system. The hardware programmer usually includes the support software.

4.A cable or connector for connecting the programmer to the computer.

5.A PIC microcontroller.