本帖最后由 zichenjushi 于 2019-7-19 17:40 编辑
心血来潮码的程序,,是由stm32F103战舰板子和自己焊接的一个HC595驱动的四位共阴极数码管写的倒计时60s的程序,希望大家能喜欢!
单片机源程序如下:
- #include "stm32f10x.h"
- #include "led.h"
- #include "delay.h"
- #include "timer.h"
- #include "hc595.h"
- u16 i;
- u16 temp = 0;
- u8 ledchar[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- u8 ledbuff[]={ 0x00, 0x00,0x00, 0x00 };
- void display()
- {
-
- static u8 a = 0;
-
- wei1 = 1;
- wei2 = 1;
- wei3 = 1;
- wei4 = 1;
- HC595data(0x00);
- switch(a)
- {
- case 0: wei1 = 0; HC595data(ledbuff[a]); a++; break;
- case 1: wei2 = 0; HC595data(ledbuff[a]); a++; break;
- case 2: wei3 = 0; HC595data(ledbuff[a]); a++; break;
- case 3: wei4 = 0; HC595data(ledbuff[a]); a=0; break;
- }
-
- }
- int main(void)
- {
-
- LED_Init(); //初始化
- delay_init();
- HC595_Init();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断分组
- TIMER_INT_Init(19,7119); //2ms
- temp = 60;
- while(1)
- {
-
- if(i >= 500)
- {
- i = 0;
- temp--;
- ledbuff[0] = ledchar[temp%10];
- ledbuff[1] = ledchar[temp/10%10];
- ledbuff[2] = ledchar[temp/100%10];
- ledbuff[3] = ledchar[temp/1000%10];
- }
- if(temp ==0)
- i = 0;
- }
- }
复制代码
所有资料51hei提供下载:
595定时器(数码管)倒计时60s.7z
(182.99 KB, 下载次数: 64)
|