What is a serial shift register. What is a register? DS – data input

According to the clock signal, the contents of each previous trigger are rewritten into the next trigger in order in the chain. The code stored in the register is shifted by one bit towards the higher bits or towards the lower bits with each clock cycle, which is what gave registers of this type their name.

In connection with the name of the direction of shift in shift registers There is often confusion. There are two types of shift: to the right (the main mode that everyone has shift registers) and to the left (only some, reverse, have this mode shift registers). These names reflect the internal structure shift registers(Fig. 8.14) and rewriting signals sequentially along a chain of triggers. In this case, flip-flops, quite naturally, are numbered from left to right, for example, from 0 to 7 (or from 1 to 8) for 8-bit registers. As a result, shifting information by a register to the right is a shift towards bits with higher numbers, and shifting information by register to the left is a shift towards bits having lower numbers.

However, as you know, in any binary number the most significant bits are on the left, and the least significant bits are on the right. Therefore, shifting a binary number to the right will be a shift towards the low-order bits, and shifting to the left will be a shift towards the high-order bits. This is a contradiction, not someone’s malicious intent, it just happened historically, and the developer of digital equipment must remember this.


Rice. 8.14.

The standard series of digital microcircuits includes several types shift registers, differing in possible operating modes, write, read and shift modes, as well as the type of output stages (2C or 3C). Majority shift registers has eight digits. In Fig. 8.15 shows four types of microcircuits as an example shift registers.

The IR8 register is the simplest of shift registers. It is an 8-bit delay line, that is, it has only one information input, to which serial shifted information is supplied (more precisely, two inputs combined using the 2I function), and eight parallel outputs. The shift towards outputs with higher numbers is carried out along the leading edge clock signal C. There is also a reset input –R, upon which a zero signal resets all register outputs to zero. Truth table register IR8 is given in table. 8.5.


Rice. 8.15.Table 8.5. Truth table shift register IR8
Inputs Exits
-R C D1 D2 Q0 Q1 Q7
0 X X X 0 0 0
1 0 X X Don't change
1 1 X X Don't change
1 0 1 1 1 1 Q0 Q6
1 0 1 0 X 0 Q0 Q6
1 0 1 X 0 0 Q0 Q6

The IR9 register performs the inverse function of the IR8 register. If IR8 converts input serial information into output parallel, then register IR9 converts input parallel information into output serial information. However, the essence of the shift does not change, it’s just that in IR9 all internal triggers have parallel inputs, and only one, the last trigger, has an output (both direct and inverse). The input code is written to the register based on a zero signal at the -WR input. The shift is carried out on a positive edge on one of the two clock inputs C1 and C2, combined

This review is dedicated, in fact, to novice Arduino users or those who want to get involved in this business. We will talk about increasing the number of microcontroller outputs using a shift register, and this does not require large expenses (compared to buying an Arduino Mega, for example). The simplest application is to blink the LEDs, so let's try this in practice.

When I started getting acquainted with microcontrollers (in fact, I still continue to “begin to get acquainted”), one of the first questions was: how can you control the same hundred, thousand LEDs with only a dozen outputs on the controller? Yes, you can use signal multiplexing, back-to-back switching and many other tricks, but still maximum amount Connectable LEDs are limited and another solution must be sought. And they suggested one of the options to me - “take one, two, ten shift register chips and have fun.” It was decided to immediately order them, and in the future even assemble them led cube with their use. I really had to abandon the latter; I found a simpler option, but this is the topic of another review.
I ordered 20 pieces of 74HC595N at once, fortunately they cost mere pennies. The letter N at the end of the marking means that the chip is in a DIP-16 package, very convenient for experiments on breadboard, you don’t even need to solder anything. It looks like this:




What is this microcircuit? It is an eight-bit serial-in, serial-out, or parallel-out shift register with a latch flip-flop and three-state output.
Simply put, using just 3 controller outputs you can control 8 shift register outputs. And if the microcircuits are connected in series one after another, then the number of controlled outputs can be increased to any reasonable limit (I haven’t found a maximum number, but hundreds seem to be combined without problems; if anyone knows what it depends on limit quantity microcircuits included in the cascade - it would be interesting to find out in the comments).
Data is transmitted to the chip serially. Bits 0 and 1 are transferred to the register one after another, the bits are read when a clock pulse arrives. Transmitted 8 bits - received 8 output states at the register outputs. When the 74HC595 is cascaded (if 16, 24, etc. outputs are required), the data from the first register is transferred to the next.
The register output can not only be in a logical 0 or 1 state, but also be in a high impedance state when the output is disconnected from the circuit. Only all outputs can be transferred to this state at once. This is rarely used, but can be useful when switching control to another controller, for example.

Input/output pinout

Q0…Q7 – register outputs, can be in state 0, 1 or high impedance
GND – ground
Q7′ – output for serial connection of registers.
MR – register reset
SH_CP – clock input
ST_CP – data latching input
OE – input converting outputs from high impedance to operating state
DS – data input
VCC – power supply 2-6 volts

All that remains is to check the work; to do this, we will assemble a circuit that is popular among beginners. GND (pin 8) is connected to ground, Vcc (pin 16) to 5V power supply, OE (pin 13) to ground, MR (pin 10) to 5V power supply. The shift register is now powered up and all outputs are active. Now it’s time to connect the microcircuit to the Arduino: connect the DS data input (pin 14) to the 9th digital output of the Arduino, the SH_CP clock input (pin 11) to the 10th digital output, the ST_CP latch input (pin 12) to the 8th Arduino pin. It is recommended to place a 0.1 µF capacitor between ground and the latch to minimize noise.
It remains to connect the LEDs - through 150-300 Ohm resistors we connect them from the register outputs to ground. That's all. Here is a diagram I found for those who like visual materials (please note that the pinout of the real microcircuit and the schematic image on this diagram are different!)


I assembled the circuit on a breadboard, and it turned out like this.

assembled circuit








In Arduino, it is convenient to use the shiftOut() function, which outputs a byte of information to the input/output port sequentially (bit by bit). . We load the test code into Arduino and get a counter from 0 to 255 in binary form:
int latchPin = 8; //ST_CP int clockPin = 10; //SH_CP int dataPin = 9; //DS void setup() ( pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); ) void loop() ( for (int numberToDisplay = 0; numberToDisplay< 256; numberToDisplay++) { // установка синхронизации "защелки" на LOW digitalWrite(latchPin, LOW); // передаем последовательно на вход данных shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); //"защелкиваем" регистр, устанавливаем значения на выходах digitalWrite(latchPin, HIGH); delay(500); } }
This is how it happened for me, everything works as expected:


Thus, with minimal use of controller pins, you can control a large number of LEDs (or something else). Everything would be fine, but I’ll also tell you about the shortcomings. As you can see, the current for each LED must be limited by a resistor, and when building large LED matrices this becomes quite labor-intensive. There are more interesting solution to control LEDs - the DM13A driver, which is a shift register and also limits the current at each output. I’ll tell you about it next time, and as a bonus - my very first LED cube, 5x5x5, assembled on a simplified element base, without the use of 74HC595.

I'm planning to buy +37 Add to favorites I liked the review +35 +61

Last time we considered the option of increasing the outputs of the microcontroller using a decoder chip, today we will consider a more advanced option using a 74HC595 shift register. Using just one microcircuit, you can have an additional 8 outputs at your disposal, using only 3 microcontroller legs. And thanks to the expandability, by adding a second chip, the number of outputs can be increased to 16. If it is not enough, you can add a third and get 24 outputs for use, and this trick can be repeated as many times as you like. At the same time, the number of occupied legs of the microcontroller will remain 3, beautiful!

So, let's take a closer look at the purpose of the microcircuit pins and learn how to control the 74hc595 shift register in the Bascom-AVR.

First, let's get acquainted with the outputs of the microcircuit, or rather with their functionality. Below is a clipping from the datasheet for 74hc595 with the designation of the pins of the microcircuit:


  • Q0…Q7– the outputs that we will control. Can be in three states: logical one, logical zero and high-resistance Hi-Z state
  • GND- Earth
  • Q7′– output intended for serial connection of registers.
  • M.R.– register reset.
  • SH_CP– input for clock pulses
  • ST_CP– data latching input
  • O.E.– input that converts the outputs from HI-Z into operating state
  • D.S.– data input
  • VCC– power supply 5 volts

Register logic

When on clock input SH_CP a logical one appears, the bit located at the data input D.S. read and written to the shift register. This bit is written to the least significant bit. When the next pulse arrives at the clock input high level, the next bit from the data input is written to the shift register. And the bit that was written earlier is shifted one bit to the left, and its place is taken by the newly arrived bit. The next clock pulse will write the third bit, and the previous two will move further. When all eight bits are filled and the ninth clock pulse arrives, the register begins to fill again from the least significant bit and everything repeats again. So that the data appears at the outputs Q0…Q7 you need to “snap” them. To do this, you need to apply a logical one to the input ST_CP.

- M.R. resets the register, setting all outputs Q0…Q7 to a logical zero state. To perform a reset, you need to apply a logical zero to this input and apply a positive pulse to the input ST_CP. Very useful feature, since when power is applied to the microcircuit, a certain arbitrary value appears at the output. When working with a register, a logical unit must be located at this pin.

- O.E.(output enable) if a logical 1 is applied here, the outputs will be in a high-resistance HI-Z state. When we apply logical 0 to this input, the outputs will be in working condition.

- Q7′ designed for serial connection of shift registers.

But it’s better to see once than to read twice =) so let’s look at the animation:


Working with the register head-on

When mastering the work with an unfamiliar microcircuit, it is often useful to work head-on, that is, directly twitching the controls with your feet, this allows you to better understand the principles of working with the test subject. So, following the logic of the work, I wrote a program that should output the register binary number 10010010

$regfile = "attiny2313.dat"
$crystal = 1000000

Config Portb = Output

Sh_cpAlias Portb. 3 "leg for clock pulses
DsAlias Portb. 2 "data output leg
St_cpAlias Portb. 0 "leg for "latching" data into the holding register


"output through the register of the number 146 (in binary representation 10010010)

St_cp= 0 "put your foot in data recording mode

Ds= 1 "set the first bit
Sh_cp= 0 "we give an impulse to the clock output
Sh_cp= 1

Ds= 0 "set the second bit
Sh_cp= 0
Sh_cp= 1

Ds= 0 "set the third bit
Sh_cp= 0
Sh_cp= 1

Ds= 1 "set the fourth bit
Sh_cp= 0
Sh_cp= 1

Ds= 0 "set the fifth bit
Sh_cp= 0
Sh_cp= 1

Ds= 0 "set the sixth bit
Sh_cp= 0
Sh_cp= 1

Ds= 1 "set the seventh bit
Sh_cp= 0
Sh_cp= 1

Ds= 0 "set the eighth bit
Sh_cp= 0
Sh_cp= 1

St_cp= 1 "snap the entered data

End


we compile, embed into the microcontroller or look into the simulator and see our combination at the output.


It works, the sent number appears at the register output!

Working with a register in this way, although possible, is too cumbersome and takes up a lot of program memory. But it clearly demonstrates the entire methodology for working with this microcircuit. Let's consider a more suitable method.

Controlling the 74HC595 register in Bascom using the ShiftOut command

Bascom-AVR has a great team for working with all kinds of serial interfaces SHIFTOUT
This command itself will decompose the number into bit components and sequentially output them to any pin of the microcontroller; at the same time, it can issue clock pulses. Just right for working with shift registers! Command syntax:

SHIFTOUT Datapin, Clockpin, var, option


Datapin – microcontroller port for data output

Clockpin – microcontroller port for outputting clock pulses

Var – data that we want to send to the register

Option – a number from 0 to 3, this parameter selects the order in which data will be entered into the register and the active level on the Clock line at which the bit is written:
option=0 – the most significant bit comes first, Clock active level low
option=1 –
most significant bit comes first, Clock active level high
option=2 –
least significant bit comes first, Clock active level low
option=3 –
least significant bit comes first, Clock active level high

In our case, to work with the 74HC595 register, the option parameter must be set to 1 or 3.

To latch data into a register, use the command PulseOut. This command outputs a pulse to the microcontroller leg with a specified duration. The command configuration looks like this:

Now let's print the number 10010001 (145 in decimal system) to the register output connected to the microcontroller according to the above diagram:

$regfile = "attiny2313.dat"
$crystal = 1000000

Dim A AsByte
Config Portb = Output

A= 145

Gosub Hc595 "we go to the data sending subroutine

End

Hc595: "data sending routine

Shiftout Portb. 2, Portb. 3, A, 1 "send data to the register
Pulseout Portb, 0, 5 "snap data
Return

Having flashed the microcontroller, you can see a similar picture; the sent combination of bits is set at the output of the shift register.


As you can see, controlling the 74HC595 shift register in Bascom consists of only two lines of code and does not present any difficulties.

Increasing the bit depth

One of the problems that arises when developing microcontroller devices is often the need to save lines of I/O ports. Many peripherals, which can work in conjunction with a processor, require a large number of connecting wires to transmit information. The relevance of this task has not decreased even with the advent of processors with a large number of pins, since peripheral devices have also become more complex. For display devices, one option to reduce the number of required lines is to use shift registers.

The shift register is a chain of several D-flip-flops connected in series. The information output of the microcontroller is connected to the first trigger. With each clock pulse transmitted along a separate line, the level at the input of each flip-flop is written to the output. As a result, the signal shifts from the beginning to the end of the chain. If you use to connect the output lines after each of the flip-flops, then the shift register will be a serial-parallel converter. This means that to organize any indicators, it will be minimally necessary to use only two microcontroller pins.

Currently, manufacturers offer a large number of shift register models, with various functional features. In what follows, only microcircuits with serial input and parallel output will be considered. Also, for the described purposes, you can use some universal register models.

Using register 74164

Shift register

One of the simplest and most common microcircuits that implements the shift register function is considered to be model 74164 (555Р8) and its technological variants. This chip is an 8-bit register with serial loading and parallel output. Using 74164 you can relatively easily get a linear indicator of 8 LEDs or a single character seven segment indicator. If necessary, it is possible to connect several microcircuits in series, which will increase the number of output lines and indicators connected to them.

The output current of each line of the current 74ACT164 and 74HCT164 variants is 25mA, which allows direct connection of low-power single LEDs or seven-segment indicators. The cycle time of these chips can be as low as 15 nS, which corresponds to the ability to operate at a frequency of 66 MHz. Considering that similar or higher operating frequencies of processors are rare, to generate clock pulses it is enough to simply turn the controller output on and off, without any delay. To load this shift register, two lines are enough: DATA and CLK. This allows you to use only two microcontroller lines to control the display device. Moreover, in many cases it may not matter how many microcircuits are connected in series, and accordingly, how many indicators the controller controls.

There are many options for using 74164. Several of them can be highlighted. The first, the above-mentioned indicator is based on several LEDs. The second is a single seven-segment indicator or a line of them. An example of a line of indicators is shown in the article - Thermometer on the PIC12F629 microcontroller.

Programming an indication using a shift register is also not very difficult. Especially if the microcontroller implements such an operation as shifting a byte through a carry bit. By checking this bit you can determine the level that needs to be set on the data line. By cyclically repeating such a shift and generating clock pulses, you can completely load the shift register. The next use case could be a dynamic indication circuit, when, to reduce the number of microprocessor lines used, the parallel output on individual segments is replaced with a serial one, using a serial-parallel converter. The same converter can be used in the circuit for switching on an LCD indicator based on HD44780.

Using registers 74595 and 4094

The use of shift registers allows you to build large circuits using LED indicators. But if the indicators consume a large current (consist of many individual LEDs), the output signal of the register becomes insufficient. To enhance the signal you can use various schemes, consisting of individual transistors, or assemblies. The simplest and most profitable way in this case is to use the ULN2803 chip, which contains 8 transistor switches. Each switch is capable of switching a current of up to 500 mA at a voltage of up to 50 V, which allows you to connect to it up to several dozen individual LEDs, low-power incandescent lamps, or segments of large matrix indicators. The only difference from the above diagrams will be the use of LED indicators with common anode, since the ULN2803 is essentially a low-side switch. For all its advantages, the 74164 chip has some disadvantages. First of all, these include the direct connection of the circuit outputs to the output lines of the triggers. In slow LED display systems, when loading a register, you can observe the movement of information from input to output in the form of extraneous illumination of segments. In the case of frequent information updates, such illumination causes somewhat unpleasant sensations. To eliminate it, you should use registers equipped with an output latch. Examples of such elements are the 74595 and 4094 microcircuits. Each of them has an additional gate input SCLK. With the loading principle unchanged, information at the output of these devices can appear only after the pulse has passed through this input. This solution requires the use of an additional microcontroller pin, but allows you to build indicators with a large number of segments, without the appearance of various unpleasant effects. It is especially useful to use registers equipped with latches in conjunction with microcontrollers running on lower frequencies or from internal generators.

The use of shift registers somewhat complicates the circuit of the finished device, but allows the use of a minimum of microcontroller outputs and has many other advantages. Among other things, the use of the above solutions allows you to simplify programming and create multi-digit indicators without high costs.

You have no rights to post comments

To construct registers, a sequential connection of these elements is used.

A serial register (shift register or shift register) is usually used to convert serial code to parallel code and vice versa. The use of serial code is associated with the need to transmit a large number of binary information over a limited number of connecting lines. When transmitting discharges in parallel, a large number of connecting conductors is required. If binary bits are transmitted sequentially, bit by bit, over one conductor, then the size of the connecting lines on the board (and the size of the chip packages) can be significantly reduced.

A schematic diagram of a serial (shift) register, assembled on the basis and allowing the conversion of serial code to parallel, is shown in Figure 1. Please note that if both potential-operating flip-flops (latch flip-flops) and flip-flops operating on the edge, then only D flip-flops operating on the edge are suitable for implementing a sequential (shift) register!


Figure 1. Sequential (shift) register circuit

Inside the shift register, flip-flops are connected in series, that is, the output of the first is connected to the input of the second, etc.


The considered serial register is shown in Figure 2.

Figure 2. Graphic designation of a sequential (shift) register

The clock inputs in serial (shift) registers, as well as in parallel registers, are combined. This ensures the simultaneous change of state of all flip-flops included in the sequential (shift) register.

Converting serial code to parallel in a serial (shift) register is done as follows. Individual bits of binary information are sequentially fed to the input of the shift register D0. Each bit is accompanied by a separate clock pulse, which is applied to the clock input of the serial register C.

After the second clock pulse arrives, the logical level present at the input of the second trigger of the serial (shift) register is stored in it and goes to its output, and since it is connected to the input of the third flip-flop, also to its input. At the same time, the next bit of the input serial code is stored in the first flip-flop of the serial (shift) register.

After the arrival of the fourth clock pulse, the logical levels of the bits that were sequentially present at its input D0 will be written in the flip-flops of the serial (shift) register. Now these bits can be used, for example, for display on indicators.

Let a signal arrive at the input of a serial (shift) register, the timing diagram of which is shown in Figure 3, then the state of the outputs of this register will sequentially take on the values ​​written in Table 1.



Figure 3. Timing diagram of shift register operation

In Figure 3, along with the logic levels, the bit values ​​that are transmitted along the connecting line or present at the outputs of the shift register are recorded.

Bar number 1 2 3 1
Q0 1 0 1 1
Q1 X 1 0 1
Q2 X X 1 0
Q3 X X X 1

As an example of the implementation of a sequential (shift) register, one can name the domestic 1564IR1 microcircuit or the foreign 74NS164.