当前位置:网站首页>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
边栏推荐
- 基于主机的入侵系统IDS
- 企业级自定义表单引擎解决方案(十一)--表单规则引擎1
- SQL injection database operation foundation
- Squid 服务启动脚本
- Kotlin learning quick start (7) -- wonderful use of expansion
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
- 鸿蒙第四次培训
- WEB-UI自动化测试-最全元素定位方法
- 数仓任务里面 跑SQL任务的时候用的数据库账号是在哪里配置的
- Swm32 series Tutorial 4 port mapping and serial port application
猜你喜欢
![[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.

Hongmeng fourth training

Introduction to SolidWorks gear design software tool geartrax

Free data | new library online | cnopendata complete data of China's insurance intermediary outlets

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

Swm32 series Tutorial 4 port mapping and serial port application

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

QT learning diary 9 - dialog box

Type conversion, variable

2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
随机推荐
QT学习日记9——对话框
IntelliJ 2021.3 short command line when running applications
Leetcode Valentine's Day Special - looking for a single dog
UE4 official charging resources, with a total price of several thousand
【JokerのZYNQ7020】DDS_ Compiler。
i++与++i的区别:通俗易懂的讲述他们的区别
LeetCode13.罗马数字转整数(三种解法)
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
vs code 插件 koroFileHeader
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
SQL injection database operation foundation
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Loop through JSON object list
Swm32 series Tutorial 4 port mapping and serial port application
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
基于主机的入侵系统IDS
绝对定位时元素水平垂直居中
How do large consumer enterprises make digital transformation?
Hongmeng fourth training