当前位置:网站首页>STM32 realizes 74HC595 control
STM32 realizes 74HC595 control
2022-07-03 17:34:00 【Me-Space】
One 、 Preface
This article is mainly about the realization 74HC595 The simple control function of .
Two 、 summary
( One )74HC595 sketch
74HC595 It's a 8 Bit serial input 、 Displacement buffer with parallel output : The platform line output is three state output .
stay SCHCP The rising edge of the input , stay STCP The rising edge of goes into the storage register , If two clocks are connected together , The shift register is always one pulse earlier than the storage register . The shift register has a serial shift input (Ds), And a serial output (Q7‘), And an asynchronous low-level reset , The storage register has a parallel 8 Bit , With three state bus output , When enabled OE when ( Low level ), The data of the storage register is output to the bus .
74HC595 Support cascading , When more than one 74HC595 When cascaded together , Sending data over a data line will eventually shift to the last 74HC595. Because cascaded data will be squeezed to the next level ic in , So the data sent first is to the last level 74HC595..
Each direction 74HC595 Send a byte ,74HC595 The first thing to send is the high-order data , That is, the first data received arrives Q7 foot , When we output high data , The highest 8 A pulse will arrive Q7 foot ( The highest bit of the data foot ), Here's the picture :
( Two ) Pin function
( 3、 ... and ) Truth table
3、 ... and 、 Hardware connection
Four 、 Program routine
1、 The header file
#ifndef _74HC595_H_
#define _74HC595_H_
#include "stm32f10x.h"
#include "io_bit.h"
#include "delay.h"
#define SRCLK PAout(14)
#define RCLK PAout(13)
#define SER PAout(12)
void HC595_Pin_Init(void);
void HC595_Send_Data(u8 data);
void HC595_Send_Byte(u8 dat1,u8 dat2,u8 dat3,u8 dat4);
#endif
2、 Source file
#include "74HC595.h"
void HC595_Pin_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Turn on the clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
// Change the mapping of the specified pin GPIO_Remap_SWJ_Disable SWJ Completely disabled (JTAG+SW-DP)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
// Change the mapping of the specified pin GPIO_Remap_SWJ_JTAGDisable ,JTAG-DP Ban + SW-DP Can make
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14);
}
void HC595_Send_Data(u8 data)
{
u8 i = 0;
for (i = 0; i < 8; i++)
{
if (data & 0x80) // Transmit the high bit first , Judge whether the eighth is 1
SER = 1; // If the eighth place is 1, Then with 595 DS The connected pin outputs a high level
else // Otherwise, the output is low
SER = 0;
SRCLK = 0;
delay_us(20);
SRCLK = 1;
data <<= 1;
}
}
void HC595_Send_Byte(u8 dat1,u8 dat2,u8 dat3,u8 dat4)
{
SRCLK = 1;
RCLK = 1;
HC595_Send_Data(dat1);
HC595_Send_Data(dat2);
HC595_Send_Data(dat3);
HC595_Send_Data(dat4);
RCLK = 0;
delay_us(2);
RCLK = 1;
delay_us(2);
RCLK = 0;
}
notes :
STM32F103C8T6 Master control PA13 and PA14 Default is not GPIO Mouth mode , It needs to be configured as GPIO Mouth mode
Links to related materials , You need to download it yourself , thank you !
link :https://pan.baidu.com/s/1Tl-AHndfCAuOs3ykptsV2A
Extraction code :q7ks
边栏推荐
- How to purchase Google colab members in China
- Applet setting multi account debugging
- The third day of writing C language by Yabo people
- Web-ui automated testing - the most complete element positioning method
- ArrayList分析3 : 删除元素
- 鸿蒙第四次培训
- Managing multiple selections with MVVM - managing multiple selections with MVVM
- Y is always discrete and can't understand, how to solve it? Answer: read it several times
- SWM32系列教程4-端口映射及串口应用
- 设计电商秒杀
猜你喜欢
Luogu: p2685 [tjoi2012] Bridge
IntelliJ 2021.3 short command line when running applications
面试官:值为 nil 为什么不等于 nil ?
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
Tensorboard quick start (pytoch uses tensorboard)
Applet setting multi account debugging
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
随机推荐
List of financial products in 2022
SQL injection database operation foundation
How SVN views modified file records
Swm32 series Tutorial 4 port mapping and serial port application
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
i++与++i的区别:通俗易懂的讲述他们的区别
TensorBoard快速入门(Pytorch使用TensorBoard)
一位普通程序员一天工作清单
[combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
Where is the database account used when running SQL tasks in data warehouse tasks configured
Redis: operation commands for list type data
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
Leetcode 669 pruning binary search tree -- recursive method and iterative method
Web-ui automated testing - the most complete element positioning method
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Basic grammar of interview (Part 2)
Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
Tensorboard quick start (pytoch uses tensorboard)
PHP returns 500 errors but no error log - PHP return 500 error but no error log
TCP拥塞控制详解 | 3. 设计空间