当前位置:网站首页>STM32实现74HC595控制
STM32实现74HC595控制
2022-07-03 17:29:00 【Me-Space】
一、前言
本文主要是实出74HC595的简单控制功能实现。
二、概述
(一)74HC595简述
74HC595是一个8位串行输入、平行输出的位移缓存器:平台行输出为三态输出。
在SCHCP的上升沿输入,在STCP的上升沿进入存储寄存器中去,如果两个时钟连在一起,则移位寄存器总是比存储寄存器早一个脉冲。移位寄存器有一个串行移位输入(Ds),和一个串行输出(Q7‘),和一个异步的低电平复位,存储寄存器有一个并行8位的,具备三态的总线输出,当使能OE时(低电平),存储寄存器的数据输出到总线。
74HC595支持级联,当多个74HC595级联一起时,通过数据线发送一个数据最终会移位给最后一个74HC595。因为级联数据会被挤到下一级的ic中,所以先发送的数据是到最后一级的74HC595.。
每次向74HC595发送一个字节,74HC595最先发到的是高位数据,也就是最先收到的数据到达Q7脚,当我们输出数据高位时,最高位的8个脉冲会到Q7脚(数据脚的最高位),如下图:

(二)引脚功能

(三)真值表

三、硬件连接

四、程序例程
1、头文件
#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);
#endif2、源文件
#include "74HC595.h"
void HC595_Pin_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//打开时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
// 改变指定管脚的映射 GPIO_Remap_SWJ_Disable SWJ 完全禁用(JTAG+SW-DP)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
// 改变指定管脚的映射 GPIO_Remap_SWJ_JTAGDisable ,JTAG-DP 禁用 + SW-DP 使能
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) //先传输高位,通过与运算判断第八是否为1
SER = 1; //如果第八位是1,则与 595 DS连接的引脚输出高电平
else //否则输出低电平
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;
}注:
STM32F103C8T6主控中PA13和PA14默认不是GPIO口模式,需要配置成GPIO口模式

相关资料链接,有需要自行下载,谢谢!
链接:https://pan.baidu.com/s/1Tl-AHndfCAuOs3ykptsV2A
提取码:q7ks
边栏推荐
- SVN完全备份svnadmin hotcopy
- kubernetes资源对象介绍及常用命令(四)
- [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
- AcWing 4489. Longest subsequence
- 大消费企业怎样做数字化转型?
- [combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
- kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
- 毕业总结
- SQL injection database operation foundation
- 问题随记 —— 在 edge 上看视频会绿屏
猜你喜欢
![[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.](/img/a0/4fc0e0741aad2885873e60f2af3387.jpg)
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.

Applet setting multi account debugging

2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)

SQL injection database operation foundation

Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code

Golang unit test, mock test and benchmark test

新库上线 | CnOpenData中国保险机构网点全集数据

SWM32系列教程4-端口映射及串口应用

鸿蒙第三次培训
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge
随机推荐
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
POM in idea XML graying solution
September, 19, "cam principle and application" online assignment [Full Score answer]
vs2013已阻止安装程序,需安装IE10
Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
Design e-commerce spike
Leetcode13. Roman numeral to integer (three solutions)
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
Play with fancy special effects. This AE super kit is for you
一位普通程序员一天工作清单
What is the difference between cloud server and cloud virtual machine
大消费企业怎样做数字化转型?
Swm32 series Tutorial 4 port mapping and serial port application
Qt调节Win屏幕亮度和声音大小
Kotlin learning quick start (7) -- wonderful use of expansion
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
Select 3 fcpx plug-ins. Come and see if you like them
QT学习日记9——对话框
HP 阵列卡排障一例
Vs code plug-in korofileheader