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

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

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

Добавлен: 12.06.2025

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

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

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

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

Shift registers

There are two types of shift registers: input and output. Input shift registers receive data in parallel, through 8 lines and then send it serially through two lines to a microcontroller. Output shift registers work in the opposite direction; they receive serial data and on a "latch" line signal, they turn it into parallel data. Shift registers are generally used to expand the number of input-output lines of a microcontroller. They are not so much in use any more though, because most modern microcontrollers have a large number of input/output lines. However, their use with microcontrollers such as PIC16F84 is very important.

Input shift register 74HC597

Input shift registers transform parallel data into serial data and transfer it to a microcontroller. Their working is quite simple. There are four lines for the transfer of data: clock, latch, load and data. Data is first read from the input pins by an internal register through a 'latch' signal. Then, with a 'load' signal, data is transferred from the input latch register to the shift register, and from there it is serially transferred to a microcontroller via 'data' and 'clock' lines.

An outline of the connection of the shift register 74HC597 to a micro, is shown below.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (1 of 7) [4/2/2003 16:19:01]

Chapter 6 - Samples

How to connect an input shift register to a microcontroller

In order to simplify the main program, a macro can be used for the input shift register. Macro HC597 has two arguments:

HC597 macro Var, Var1

Var variable where data from shift register input pins is transferred

Var1 loop counter

Example: HC597 data, counter

Data from the input pins of the shift register is stored in data variable. Timer/counter variable is used as a loop counter.

Macro listing:

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (2 of 7) [4/2/2003 16:19:01]

Chapter 6 - Samples

Example of how to use the HC597 macro is given in the following program. Program receives data from a parallel input of the shift register and moves it serially into the RX variable of the microcontroller. LEDs connected to port B will indicate the result of the data input.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (3 of 7) [4/2/2003 16:19:01]

Chapter 6 - Samples

Output shift register

Output shift registers transform serial data into parallel data. On every rising edge of the clock, the shift register reads the value from data line, stores it in temporary register, and then repeats this cycle 8 times. On a signal from 'latch' line, data is copied from the shift register to input

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (4 of 7) [4/2/2003 16:19:01]

Chapter 6 - Samples

register, thus data is transformed from serial into parallel data.

An outline of the 74HC595 shift register connections is shown on the diagram below:

Connecting an output shift register to a microcontroller

Macro used in this example is found in hc595.inc file, and is called HC595. Macro HC595 has two arguments:

HC595 macro Var, Var1

Var variable whose contents is transferred to outputs of shift register.

Var1 loop counter

Example: HC595 Data, counter

The data we want to transfer is stored in data variable, and counter variable is used as a loop counter.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (5 of 7) [4/2/2003 16:19:01]


Chapter 6 - Samples

An example of how to use the HC595 macro is given in the following program. Data from variable TX is serially transferred to shift register. LEDs connected to the parallel output of the shift register will indicate the state of the lines. In this example value 0xCB (1100 1011) is sent so that the eighth, seventh, fourth, second and first LEDs are illuminated.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (6 of 7) [4/2/2003 16:19:01]

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_08Poglavlje.htm (7 of 7) [4/2/2003 16:19:01]


Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

Seven-Segment Display (multiplexing)

The segments in a 7-segment display are arranged to form a single digit from 0 to F as shown in the animation:

We can display a multi-digit number by connecting additional displays. Even though LCD displays are more comfortable to work with, 7-segment displays are still standard in the industry. This is due to their temperature robustness, visibility and wide viewing angle. Segments are marked with non-capital letters: a, b, c, d, e, f, g and dp, where dp is the decimal point.

The 8 LEDs inside each display can be arranged with a common cathode or common anode. With a common cathode display, the common cathode must be connected to the 0V rail and the LEDs are turned on with a logic one. Common anode displays must have the common anode connected to the +5V rail. The segments are turned on with a logic zero.

The size of a display is measured in millimeters, the height of the digit itself (not the housing, but the digit!). Displays are available with a digit height of 7,10, 13.5, 20, or 25 millimeters. They come in different colors, including: red, orange, and green.

The simplest way to drive a display is via a display driver. These are available for up to 4 displays.

Alternatively displays can be driven by a microcontroller and if more than one display is required, the method of driving them is called "multiplexing."

The main difference between the two methods is the number of "drive lines." A special driver may need only a single "clock" line and the driver chip will access all the segments and increment the display.

If a single display is to be driven from a microcontroller, 7 lines will be needed plus one for the decimal point. For each additional display, only one extra line is needed.

To produce a 4, 5 or 6 digit display, all the 7-segment displays are connected in parallel.

The common line (the common-cathode line) is taken out separately and this line is taken low for a short period of time to turn on the display.

Each display is turned on at a rate above 100 times per second, and it will appear that all the displays are turned on at the same time.

As each display is turned on, the appropriate information must be delivered to it so that it will give the correct reading.

Up to 6 displays can be accessed like this without the brightness of each display being affected. Each display is turned on very hard for one-sixth the time and the POV (persistence of vision) of our eye thinks the display is turned on the whole time.

All the timing signals for the display are produced by the program, the advantage of a microcontroller driving the display is flexibility.

The display can be configured as an up-counter, down-counter, and can produce a number of messages using letters of the alphabet that can be readily displayed.

The example below shows how to dive two displays.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_09Poglavlje.htm (1 of 5) [4/2/2003 16:19:03]

Chapter 6 - Samples

Connecting a microcontroller to 7-segment displays in multiplex mode

File Led.inc contains two macros: LED_Init and LED_Disp2. The first macro is used for display initialization. That is where display refreshment period is defined as well as microcontroller pins used for connecting the displays. The second macro is used for displaying numbers from 0 to 99 on two displays.

Macro LED_Disp2 has one argument:

LED_Disp2 first macro

first is the number from 0 to 99 to be displayed on Msd and Lsd digit.

Example: LED_Disp12 0x34

Number 34 will be shown on the display

Realization of a macro is given in the following listing.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_09Poglavlje.htm (2 of 5) [4/2/2003 16:19:03]


Chapter 6 - Samples

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_09Poglavlje.htm (3 of 5) [4/2/2003 16:19:03]

Chapter 6 - Samples

The following example shows the use of macros in a program. Program displays number '21' in two 7-segment digits.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_09Poglavlje.htm (4 of 5) [4/2/2003 16:19:03]

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_09Poglavlje.htm (5 of 5) [4/2/2003 16:19:03]


Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

LCD Display

More microcontroller devices are using 'smart

LCD' displays to output visual information. The

following discussion covers the connection of a

Hitachi LCD display to a PIC microcontroller.

LCD displays designed around Hitachi's LCD

HD44780 module, are inexpensive, easy to use,

and it is even possible to produce a readout

using the 8 x 80 pixels of the display. Hitachi

LCD displays have a standard ASCII set of

characters plus Japanese, Greek and

A 16x2 line Hitachi HD44780 display

mathematical symbols.

Each of the 640 pixels of the display must be accessed individually and this is done with a number of surface-mount driver/controller chips mounted on the back of the display. This saves an enormous amount of wiring and controlling so that only a few lines are required to access the display to the outside world. We can communicate to the display via an 8-bit data bus or 4-bit data bus.

For a 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4-bit data bus it only requires the supply lines plus seven extra lines. When the LCD display is not enabled, data lines are tri-state which means they are in a state of high impedance (as though they are disconnected) and this means they do not interfere with the operation of the microcontroller when the display is not being addressed.

The LCD also requires 3 "control" lines from the microcontroller.

The Enable (E) line allows access to the display through R/W and RS lines. When this line is low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is high, the LCD checks the state of the two control lines and responds accordingly.

The Read.Write (R/W) line determines the direction of data between the LCD and microcontroller. When it is low, data is written to the LCD. When it is high, data is read from the LCD.

With the help of the Register select (RS) line, the LCD interprets the type of data on data lines. When it is low, an instruction is being written to the LCD. When it is high, a character is being written to the LCD.

Logic status on control lines:

E0 Access to LCD disabled

1 Access to LCD enabled

R/W 0 Writing data to LCD 1 Reading data from LCD

RS 0 Instruction

1 Character

Writing data to the LCD is done in several steps:

Set R/W bit to low

Set RS bit to logic 0 or 1 (instruction or character)

Set data to data lines (if it is writing)

Set E line to high

Set E line to low

Read data from data lines (if it is reading)

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_10Poglavlje.htm (1 of 11) [4/2/2003 16:19:08]