采用数码管静态显示电路,实现数码管从99到0的倒计数。

main.c 

#include "stm32f10x.h"
#include "smg.h"

uint8_t table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void delays(int t){
    int i,j;
    for(i=0;i<t;i++)
    {
        for( j = 0 ; j < t ; j++);
    }        
}

int main(){
    uint16_t temp =0;
    SMG_Init();
    int a=0;
    while(1){
        for(a=99;a>=0;a--)
        {
            temp =(table[a/10]<<8) | table[a%10];
            GPIO_Write(GPIOC,temp);
            delays(500);
        }
    }
}
 

smg.c

#include "stm32f10x.h"
#include "smg.h"

void SMG_Init(){
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); 
      GPIO_InitTypeDef GPIO_InitStructure; 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
    GPIO_Init(GPIOC, &GPIO_InitStructure);
}
 

smg.h

#ifndef __SMG_H
#define __SMG_H

void SMG_Init(void);

#endif
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值