stm32--数码管

smg.c

#include "smg.h"

void SMG_INIT()
{
    GPIO_InitTypeDef GPIO_InitStructure;    //GPIO初始化要配置的结构体定义
    
    RCC_APB2PeriphClockCmd(SMG_PORT_RCC,ENABLE);   //开启APB2总线的时钟
    
    GPIO_InitStructure.GPIO_Pin = SMG_PIN;        //选择要操作的引脚
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  //工作频率
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //模式
    
    GPIO_Init(SMG_PORT,&GPIO_InitStructure);   //初始化端口

}

smg.h

#ifndef _smg_h
#define _smg_h
#include "system.h"

#define SMG_PORT_RCC    RCC_APB2Periph_GPIOC  //定义相应时钟
#define SMG_PIN         (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 SMG_PORT        GPIOC

void SMG_INIT(void);


#endif

main.c


#include "systick.h"
#include "led.h"
#include "system.h"
#include "smg.h"


u8 smgduan[16]={0x3f, 0x06,0x5b, 0x4f, 0x66, 0x6d,0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c,0x39, 0x5e, 0x79, 0x71}; //0-F共阴数码管
int main()
{
    u8 i=0;
    SysTick_Init(72);  //系统时钟初始
    LED_INIT();  //初始化LED
    SMG_INIT();

    while(1)
    {
        for(i=0;i<16;i++)
        {
            GPIO_Write(SMG_PORT,(u16)(~smgduan[i])); //这个函数是往端口写入两个字节,强制转换,低8位是0,板子是共阳,取反是共阴
            delay_ms(1000);         
        }
    }
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值