当前位置:网站首页>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
边栏推荐
- STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
- 新库上线 | CnOpenData中国观鸟记录数据
- 绝对定位时元素水平垂直居中
- [RT thread] NXP rt10xx device driver framework -- RTC construction and use
- 鸿蒙第四次培训
- Hongmeng third training
- 1147_ Makefile learning_ Target files and dependent files in makefile
- A day's work list of an ordinary programmer
- Vs2013 has blocked the installer, and ie10 needs to be installed
- VM11289 WAService. js:2 Do not have __ e handler in component:
猜你喜欢
Hongmeng fourth training
免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
新库上线 | CnOpenData中国保险机构网点全集数据
[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
大变局!全国房价,跌破万元大关
Golang单元测试、Mock测试以及基准测试
Test your trained model
One brush 149 force deduction hot question-10 regular expression matching (H)
C language modifies files by line
Talk about several methods of interface optimization
随机推荐
[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)
POM in idea XML graying solution
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Rsync远程同步
UE4 official charging resources, with a total price of several thousand
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
When absolutely positioned, the element is horizontally and vertically centered
The difference between i++ and ++i: tell their differences easily
One brush 145 force deduction hot question-2 sum of two numbers (m)
鸿蒙第四次培训
Golang unit test, mock test and benchmark test
1164 Good in C
i++与++i的区别:通俗易懂的讲述他们的区别
QT学习日记9——对话框
SQL injection database operation foundation
One brush 148 force deduction hot question-5 longest palindrome substring (m)
Leetcode13. Roman numeral to integer (three solutions)
LeetCode13.罗马数字转整数(三种解法)
Notes on problems -- watching videos on edge will make the screen green
Tensorboard quick start (pytoch uses tensorboard)