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);

发布了13 篇原创文章 · 获赞 8 · 访问量 3232

猜你喜欢

转载自blog.csdn.net/qq_45844792/article/details/105161697