STM32——库函数版——数码管流动显示程序

数码管流动显示

我是用遍历两个数组让数码管流动显示数字
main.c

#include "sys.h"
#include "delay.h"
#include "num.h"

int main(void)
{ 
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);	//系统时钟设置PLL作为系统时钟
	delay_init();			//初始化延时函数

	NUM_FLOW();  //数码管流动显示
}

num.c

#include "num.h"
#include "delay.h"

//动态数码管段码
//unsigned char seg[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};

//流动数码管
u8 smgduan[4]={0xF9,0xB0,0xF9,0x99};//段选
u8 smgwei[4]={0xfE,0xfd,0xfb,0xf7}; //位选

//数码管初始化
void NUM_Init(void){

	GPIO_InitTypeDef  GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);	 //使能GPIO端口时钟,数码管显示GPIO使能配置
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);	//位选使能
	//段码设置
	GPIO_InitStructure.GPIO_Pin = NUM_STATIC_GPIO;    //数码管段选显示GPIO引脚配置
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出
	GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;  //最高输出速率50MHz	
	GPIO_Init(GPIOD, &GPIO_InitStructure);  //IO口初始化
	//位选设置
	GPIO_InitStructure.GPIO_Pin = NUM_STATIC_BIT;    //数码管位选显示GPIO引脚配置
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出
	GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;  //最高输出速率50MHz	
	GPIO_Init(GPIOC, &GPIO_InitStructure);  //IO口初始化
	GPIO_ResetBits(GPIOC, NUM_STATIC_BIT);   //给数码管位码置0
}
//数码管流动显示
void NUM_FLOW(void){
	uint16_t i;
	NUM_Init();
	while(1)
	{
		for(i=0;i<4;i++)
		{
			GPIO_Write(GPIOD,0xff);
			GPIO_Write(GPIOC,0xff);
			GPIO_Write(GPIOC,smgwei[i]);  //位选输出
			GPIO_Write(GPIOD,smgduan[i]);  //段码输出
			delay_ms(10);
		}
	}	
	
}

num.h

#include "sys.h"

//段码引脚
#define NUM_STATIC_GPIO  GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7  
#define NUM_STATIC_BIT GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3
//数码管流动显示
void NUM_FLOW(void);



  • 0
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西瓜籽@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值