STM32——库函数版——数码管静态显示程序

数码管静态显示程序

我的是四位的数码管,共阳极
一个数码管有八段:A,B,C,D,E,F ,G,H,DP,即由八个发光二极管组成
由0到f编码为:
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e

main.c

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

int main(void)
{ 
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);	//系统时钟设置PLL作为系统时钟
	delay_init();			//初始化延时函数
	NUM_STATIC();  //数码管静态显示	
}

num.c

#include "num.h"

//数码管初始化
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_STATIC(void){
	NUM_Init();  
	while(1)
	{
		GPIO_Write(GPIOD,0xc0);  //段码输出0
	}		
}

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_STATIC(void);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

西瓜籽@

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

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

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

打赏作者

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

抵扣说明:

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

余额充值