当前位置:网站首页>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);
#endif
2、源文件
#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
边栏推荐
- Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
- Svn full backup svnadmin hotcopy
- Brief introduction to the core functions of automatic penetration testing tool
- Select 3 fcpx plug-ins. Come and see if you like them
- RDS数据库的监测页面在哪看?
- Great changes! National housing prices fell below the 10000 yuan mark
- One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
- i++与++i的区别:通俗易懂的讲述他们的区别
- [combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
- [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
猜你喜欢
Luogu: p2685 [tjoi2012] Bridge
SQL injection database operation foundation
How to read the source code [debug and observe the source code]
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
Simple use of unity pen XR grab
How do large consumer enterprises make digital transformation?
Unity notes unityxr simple to use
国内如何购买Google Colab会员
Notes on problems -- watching videos on edge will make the screen green
[RT thread] NXP rt10xx device driver framework -- pin construction and use
随机推荐
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
Javescript variable declaration -- VaR, let, const
Unity notes unityxr simple to use
Hongmeng third training
RedHat 6.2 配置 Zabbix
How to purchase Google colab members in China
Where is the monitoring page of RDS database?
数仓任务里面 跑SQL任务的时候用的数据库账号是在哪里配置的
List of financial products in 2022
Svn full backup svnadmin hotcopy
Graduation summary
Talk about several methods of interface optimization
Kubernetes resource object introduction and common commands (III)
Detailed explanation of common network attacks
vs2013已阻止安装程序,需安装IE10
Kubernetes resource object introduction and common commands (4)
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
TensorBoard快速入门(Pytorch使用TensorBoard)
基于主机的入侵系统IDS
UE4 official charging resources, with a total price of several thousand