借鉴文章

https://blog.csdn.net/Zach_z/article/details/80548423

一,硬件连接

在这里插入图片描述
按照上图:PA1-SER / PA2-RCK/ PA3-SCK关系,利用跳线帽对应连接。

二、软件驱动
seg.h

#ifndef SEG_H
#define SEG_H
#include "stm32f10x.h"

#define SER_H GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define SER_L GPIO_ResetBits(GPIOA,GPIO_Pin_1)    //串行数据输入引脚

#define RCK_H GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define RCK_L GPIO_ResetBits(GPIOA,GPIO_Pin_2)    //串行存储时钟输入引脚

#define SCK_H GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define SCK_L GPIO_ResetBits(GPIOA,GPIO_Pin_3)    //串行移位时钟输入引脚

void Seg_Init(void);
void Seg_Control(u8 bit1,u8 bit2,u8 bit3);
#endif

seg.c

#include "seg.h"

extern void Delay_Ms(u32 nTime);

u8 seg[17]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; 

void Seg_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

	SER_L;
	RCK_L;
	SCK_L;
}

void Seg_Control(u8 bit1,u8 bit2,u8 bit3)
{
	u8 temp;
	u8 i;
	
	temp=seg[bit3];
	for(i=0;i<8;i++)
	{
		if(temp&0x80)
			SER_H;
		else
			SER_L;

		temp=temp<<1;
		SCK_L;
		Delay_Ms(1);
		SCK_H;
	}	

	temp=seg[bit2];
	for(i=0;i<8;i++)
	{
		if(temp&0x80)
			SER_H;
		else
			SER_L;

		temp=temp<<1;
		SCK_L;
		Delay_Ms(1);
		SCK_H;
	}

	temp=seg[bit1];
	for(i=0;i<8;i++)
	{
		if(temp&0x80)
			SER_H;
		else
			SER_L;

		temp=temp<<1;
		SCK_L;
		Delay_Ms(1);
		SCK_H;
	}

	RCK_L;
	Delay_Ms(1);
	RCK_H;
}


Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐