AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment

Publisher:采菊东篱下Latest update time:2019-07-13 Source: eefocusKeywords:AVRWARE++  74HC595 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

         This article is only for beginners, experts please skip it!


    1. Experimental purpose

Use the IO port of the microcontroller to simulate the SPI bus timing logic, control 24 LEDs through 74HC595, and learn how to use 74HC595 serial control.

  

    2. Experimental content

    Write a program to light up all 24 LEDs first, and then turn them off one by one from left to right at intervals of one second.


    3. Hardware Principle

The hardware schematic diagram of 74HC595 serial control LED lamp is shown in the figure below. Use a flat cable to connect to terminal P3, then the 0-2 pins of the corresponding port of the microcontroller are connected to the CS_595_1, CLK_595_1, and Data_595_1 pins of terminal P3 (for example, use a flat cable to connect P9 to terminal P3, then the PC0 pin is connected to CS_595_1, the PC1 pin is connected to CLK_595_1, and the PC2 pin is connected to Data_595_1). CS_595_1 is the chip select pin of 74HC595, which is used to control the latch between the internal shift register and the pin of 74HC595. CLK_595_1 is the clock pin of 74HC595. Every cycle change of this pin will input 1 bit of data into the internal shift register of 74HC595. Data_595_1 is the data pin, and its high and low values ​​will be sent to the internal shift register of 74HC595 within a cycle of CLK_595_1 change.

    For a 74HC595, the working process is to use CS_595_1 to close the latch between the internal shift register and the pin of the 74HC595, prepare data on the Data_595_1 pin, operate CLK_595_1 to change it for 1 cycle, and the corresponding high and low values ​​of Data_595_1 are sent to the 0th bit of the internal shift register of the 74HC595. This cycle is repeated 8 times, and 8 bits of data are input to the internal shift register of the 74HC595. The first input is at the 7th bit of the internal shift register of the 74HC595, and the last input is at the 0th bit of the internal shift register of the 74HC595. After the data is input, operate CS_595_1 to open the latch between the internal shift register and the pin of the 74HC595, so that the value of the internal shift register of the 74HC595 is presented on the pin, and then close the latch to continue the subsequent operation.

    For the control of multiple 74HC595, the three pins CS_595_1, CLK_595_1, and Data_595_1 are still used. From the schematic diagram, we can see that the Q7 pin of the first 74HC595 is connected to the Data pin of the second 74HC595, and the Q7 pin of the second 74HC595 is connected to the Data pin of the third 74HC595. This connection can control multiple 74HC595. Take three 74HC595 as an example, prepare 3 bytes of data before operation, and send the 3 bytes of data to the first 74HC595 in three times according to the method of operating one 74HC595. Then the first byte will be transmitted to the third 74HC595, and the last byte will be transmitted to the first 74HC595. After the data is transferred, as in the above method, operate CS_595_1 to open the latch between the internal shift register of 74HC595 and the pin, so that the value of the internal shift register of 74HC595 is displayed on the pin, and then close the latch to continue the subsequent operation. 

 picture 

    4. Experimental reference procedures and annotations 

    Change the mapping layer 0_logiclayer_config.h file. The following program enables HC595 so that its driver can be added to the compilation process and prompts the user to configure 595 in the corresponding config file of HC595.

#define EXTERNAL_MODULE_HC595_MODE 1 //0: HC595 chip is not used

//1: Use the HC595 chip and set its pin configuration in the corresponding config file


     Change the mapping layer 3_ExternalModulelayer_HC595_config.h file. The following program changes should be completed according to the schematic diagram. When P9 and P3 terminals are connected, PORTC port is used to control HC595, so the corresponding HC595_PORT and HC595_DDR are defined as PORTC and DDRC respectively. HC595_CLOCK, HC595_CS and HC595_MOSI are specific pin numbers. Just check the schematic diagram and write them.

#define HC595_PORT PORTC

#define HC595_DDR DDRC

#define HC595_CLOCK BIT1

#define HC595_CS BIT0

#define HC595_MOSI BIT2


    Modify the logic layer 0_logiclayer_main.c file  

//Main program

int main(void)

{

    // Target board initialization, this function will automatically initialize the corresponding peripheral files

    TARGET_Init();

    //Background main loop

    while(1)

    {

        //Complete your own project logic here

HC595_WriteByte(0x00); //Write 1 byte of data to HC595. After the whole operation is completed, the data is written to the third HC595

HC595_WriteByte(0x00); //Write 1 byte of data to HC595. After the whole operation is completed, the data is written to the second HC595

HC595_WriteByte(0x00); //Write 1 byte of data to HC595. After the whole operation is completed, the data is written to the first HC595

HC595_SELECT; //Open the latch between the HC595 internal shift register and the pin

                                  // Make the value of the 74HC595 internal shift register appear on the pin, and then close the latch

TARGET_Delayms(1000,1);

HC595_WriteByte(0x01); // Column 1 is off, the binary of 0x01 is 00000001, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x01);

HC595_WriteByte(0x01);

HC595_SELECT;

TARGET_Delayms(1000,1);

HC595_WriteByte(0x03); // Columns 1-2 are off, the binary value of 0x03 is 00000011, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x03);

HC595_WriteByte(0x03);

HC595_SELECT;

TARGET_Delayms(1000,1);    

HC595_WriteByte(0x07); // Columns 1-3 are off, the binary value of 0x07 is 00000111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x07);

HC595_WriteByte(0x07);

HC595_SELECT;

TARGET_Delayms(1000,1);   

HC595_WriteByte(0x0f); // Columns 1-4 are off, the binary value of 0x0f is 00001111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x0f);

HC595_WriteByte(0x0f);

HC595_SELECT;

TARGET_Delayms(1000,1);

HC595_WriteByte(0x1f); // Columns 1-5 are off, the binary value of 0x1f is 00011111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x1f);

HC595_WriteByte(0x1f);

HC595_SELECT;

TARGET_Delayms(1000,1);

HC595_WriteByte(0x3f); // Columns 1-6 are off, the binary value of 0x3f is 00111111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x3f);

HC595_WriteByte(0x3f);

HC595_SELECT;

TARGET_Delayms(1000,1);

HC595_WriteByte(0x7f); // Columns 1-7 are off, the binary value of 0x7f is 01111111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0x7f);

HC595_WriteByte(0x7f);

HC595_SELECT;

TARGET_Delayms(1000,1);

HC595_WriteByte(0xff); // Columns 1-8 are off, the binary value of 0xff is 11111111, please note that the LED in the circuit is lit at low level

HC595_WriteByte(0xff);

HC595_WriteByte(0xff);

HC595_SELECT;

TARGET_Delayms(1000,1);

/*

********************************************************************************

Feed the dog statement, most projects should not remove it

********************************************************************************

*/

        #if WDT_MODE!=0

    TARGET_WatchDogReset();

        #endif

    }

    return 0; //never execute

}


Keywords:AVRWARE++  74HC595 Reference address:AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment

Previous article:AVRWARE++ Development Notes 8: Atmel Studio removes spell check
Next article:AVRWARE++ Development Notes 6: 8-way direct I/O port control LED light experiment

Recommended ReadingLatest update time:2024-11-16 17:42

51 single chip microcomputer uses 74HC595 to drive digital tube
Based on the 51 single chip microcomputer, the pattern of eight digital tubes is displayed as follows: xxx11xxx→xx2222xx→x333333x→44444444→x555555x→xx6666xx→x777777x→88888888 Each state lasts for one second, and the display is repeated. Among them, x means that the corresponding digital tube is off . Supplementary que
[Microcontroller]
51 single chip microcomputer uses 74HC595 to drive digital tube
AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment
         This article is only for beginners, experts please skip it!     1. Experimental purpose Use the IO port of the microcontroller to simulate the SPI bus timing logic, control 24 LEDs through 74HC595, and learn how to use 74HC595 serial control.        2. Experimental content     Write a program to light up al
[Microcontroller]
AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号