当前位置:网站首页>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
边栏推荐
- 鸿蒙第三次培训
- 自动渗透测试工具核心功能简述
- [RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
- Installation and configuration of network hard disk NFS
- QT学习日记9——对话框
- UE4 official charging resources, with a total price of several thousand
- How to train mask r-cnn model with your own data
- Qt调节Win屏幕亮度和声音大小
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- SQL injection database operation foundation
猜你喜欢

1146_ SiCp learning notes_ exponentiation

Introduction to SolidWorks gear design software tool geartrax

Select 3 fcpx plug-ins. Come and see if you like them

The largest matrix (H) in a brush 143 monotone stack 84 histogram

PHP online confusion encryption tutorial sharing + basically no solution

【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用

Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13

QT adjust win screen brightness and sound size

What is your income level in the country?

kubernetes资源对象介绍及常用命令(三)
随机推荐
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
One brush 149 force deduction hot question-10 regular expression matching (H)
Type conversion, variable
Rsync远程同步
Kubernetes resource object introduction and common commands (III)
[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
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Svn full backup svnadmin hotcopy
SSH连接远程主机等待时间过长的解决方法
Vs2013 has blocked the installer, and ie10 needs to be installed
Graduation summary
Squid 服务启动脚本
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
One brush 145 force deduction hot question-2 sum of two numbers (m)
Simple configuration of postfix server
Enterprise custom form engine solution (XI) -- form rule engine 1
One brush 146 force buckle hot question-3 longest substring without repeated characters (m)
新库上线 | CnOpenData中国保险机构网点全集数据
Unity notes unityxr simple to use
企业级自定义表单引擎解决方案(十一)--表单规则引擎1