17th: The basic driver of the two-piece 74hc595 drive 16 LED Lights

Source: Internet
Author: User
Tags flush reset


Opening:
The previous section describes how to translate the matrix keyboard into a single-button processing method. This section is about 74hc595 drivers. To teach you two points of knowledge:
1th: Zhu Zhao's learning board is controlled with a 74hc595 led, so the 595 OE PIN can be grounded directly. If in the industrial control, used for controlling the relay, then this chip of the selected foot OE not to save an IO port and direct grounding, otherwise it will cause power instantaneous relay inexplicable action. In order to solve this problem, the OE foot should be driven separately by an IO port, and it is important to remember that this IO must be connected to a pull-up resistor of around 15K, and then set the OE high as soon as the program is powered on, and set the 74hc595 output low as quickly as possible. Then set the OE low. Of course, there is another solution, is to use a 10uF electrolytic capacitor with a 100K pull-down resistor, consisting of 51 microcontroller peripheral reset circuit principle of the same circuit, connected to the OE port, so as to ensure that the power instantaneous OE port for a short period of time is in high state, during this period, As soon as possible through the software to 74hc595 all the output low.
2nd: The working process of the two Cascade 74hc595: Each 74hc595 has a 8-bit register and two cascade up to two registers. The St pin is equivalent to a flush signal pin, when the ST pin generates a rising edge signal, the register value is output to the output pin of the 74hc595 and locked up, the DS is the data pin, and SH is the clock signal that the new data is fed into the register. That is, the SH pin is responsible for sending the data into the register, and the St PIN is responsible for updating the register data to the output pin of the 74hc595 and locking it up.

For details, please see the source code explained.

(1) Hardware platform: Based on the Zhu Zhao 51 single-chip computer learning board.

(2) Realization function: Two pieces of the 74hc595 drive 16 LED lights cross-flashing. For example, first the first 1,3,5,7,9,11,13,15 eight lights, the other lights are extinguished. Then in turn, the original light is extinguished, the original extinguished on the light. Alternating flashes.

(3) The source code is explained as follows:
#include "REG52. H

#define CONST_TIME_LEVEL 200

void Initial_myself ();
void Initial_peripheral ();
void Delay_short (unsigned int uidelayshort);
void Delay_long (unsigned int uidelaylong);
void Led_flicker ();
void hc595_drive (unsigned char ucledstatustemp16_09,unsigned char ucledstatustemp08_01);
void T0_time (); Timer Interrupt function

/* Note one:
* The Zhu Zhao Learning Board is controlled with a 74hc595 led, so the 595 OE PIN can be grounded directly. If it is used to control the relay in the industrial industry,
* then this chip selection of the foot OE is not to save an IO port and direct grounding, otherwise it will cause the power instantaneous relay inexplicable action.
* In order to solve this problem, the OE foot should be driven separately by an IO port, and it is important to remember that this IO must be connected to about 15K
* Pull-up resistor, and then when the program just power on, first set the OE high, and as soon as possible all the 74hc595 output low, and then the OE low.
* Of course there is another solution, is to use a 10uF electrolytic capacitor with a 100K pull-down resistor, consisting of 51 microcontroller peripheral reset Circuit principle
* The same circuit, connected to the OE port, so as to ensure that the power instantaneous OE port for a short period of time is in high state, during this period,
* Reduce all output of 74hc595 by software as soon as possible.
*/
Sbit hc595_sh_dr=p2^3;
Sbit hc595_st_dr=p2^4;
Sbit hc595_ds_dr=p2^5;


unsigned char ucledstep=0; Step variable
unsigned int uitimecnt=0; Time delay counter for counting the number of timed interrupts


void Main ()
{
Initial_myself ();
Delay_long (100);
Initial_peripheral ();
while (1)
{
Led_flicker ();
}

}

/* Note two:
* Working process of two Cascade 74hc595:
* There is a 8-bit register inside each 74hc595, and two cascaded up to two registers. The St pin is equivalent to a flush
* Signal PIN, when the ST pin generates a rising edge signal, the value of the register is output to the output pin of the 74hc595 and locked up,
* DS is the data pin, SH is the clock signal that feeds the new data into the register. In other words, the SH pin is responsible for sending the data into the register, the St Pin
* Responsible for updating the register data to the output pin of the 74hc595 and locking it up.
*/
void hc595_drive (unsigned char ucledstatustemp16_09,unsigned char ucledstatustemp08_01)
{
unsigned char i;
unsigned char uctempdata;
hc595_sh_dr=0;
hc595_st_dr=0;

uctempdata=ucledstatustemp16_09; 8-bit higher first
for (i=0;i<8;i++)
{
if (uctempdata>=0x80) hc595_ds_dr=1;
else hc595_ds_dr=0;

hc595_sh_dr=0; The rising edge of the sh pin feeds the data into the register
Delay_short (15);
Hc595_sh_dr=1;
Delay_short (15);

uctempdata=uctempdata<<1;
}

uctempdata=ucledstatustemp08_01; and send the lower 8-bit first.
for (i=0;i<8;i++)
{
if (uctempdata>=0x80) hc595_ds_dr=1;
else hc595_ds_dr=0;

hc595_sh_dr=0; The rising edge of the sh pin feeds the data into the register
Delay_short (15);
Hc595_sh_dr=1;
Delay_short (15);

uctempdata=uctempdata<<1;
}

hc595_st_dr=0; The ST PIN updates the data of the two registers to the output pin of the 74hc595 and locks up
Delay_short (15);
Hc595_st_dr=1;
Delay_short (15);

hc595_sh_dr=0; Low-tension, anti-interference enhancement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.