|
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei截圖_20220123194441.png (25.17 KB, 下載次數(shù): 66)
下載附件
2022-1-24 15:29 上傳
單片機(jī)源程序如下:
- //實(shí)驗現(xiàn)象:3位數(shù)碼管輪流顯示數(shù)碼管編碼表里面的字符
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "HC595.h"
- unsigned char Qian_Wei,Bai_Wei,Shi_Wei,Ge_Wei; //千位,百位,十位,個位
- //數(shù)碼管編碼
- unsigned char table[] =
- {0xc0,0xf9,0xa4,0xb0,0x99,
- 0x92,0x82,0xf8,0x80,0x90,
- 0xff,0x00,0x90,0x86,0xaf,
- 0xc0,0x89,0xc7,0x8e,0xc1,0x7f};
- //0,1,2,3,4,5,6,7,8,9,全暗,全亮,g,E,r,O,H,L,F,U,小數(shù)點(diǎn),共陽數(shù)碼管使用
- int main(void)
- {
- int a, b, c, d;
- a = 0;//這些常量置0,否則后面顯示會出問題
- b = 0;
- c = 0;
- d = 0;
- SystemInit(); //系統(tǒng)時鐘初始化為72M SYSCLK_FREQ_72MHz
- delay_init(72); //延時函數(shù)初始化
- NVIC_Configuration(); //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級
- LED_Init(); //LED端口初始化
- HC595_Init();
-
- //清空LED數(shù)碼管
- Bai_Wei = table[10];//清空LED
- Shi_Wei = table[10];//清空LED
- Ge_Wei = table[10];//清空LED
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(3000);
-
- //依次測試百位至個位全亮
- Bai_Wei = table[11];//百位全亮
- Shi_Wei = table[10];//清空LED
- Ge_Wei = table[10];//清空LED
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[10];//清空LED
- Shi_Wei = table[11];//十位全亮
- Ge_Wei = table[10];//清空LED
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[10];//清空LED
- Shi_Wei = table[10];//清空LED
- Ge_Wei = table[11];//個位全亮
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
-
- //同時顯示0~9
- Bai_Wei = table[0];
- Shi_Wei = table[0];
- Ge_Wei = table[0];
- HC595_Display(Bai_Wei, Shi_Wei, Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[1];
- Shi_Wei = table[1];
- Ge_Wei = table[1];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[2];
- Shi_Wei = table[2];
- Ge_Wei = table[2];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[3];
- Shi_Wei = table[3];
- Ge_Wei = table[3];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[4];
- Shi_Wei = table[4];
- Ge_Wei = table[4];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[5];
- Shi_Wei = table[5];
- Ge_Wei = table[5];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[6];
- Shi_Wei = table[6];
- Ge_Wei = table[6];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[7];
- Shi_Wei = table[7];
- Ge_Wei = table[7];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[8];
- Shi_Wei = table[8];
- Ge_Wei = table[8];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- Bai_Wei = table[9];
- Shi_Wei = table[9];
- Ge_Wei = table[9];
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
- HC595_Display(Bai_Wei, Shi_Wei,Ge_Wei);
- delay_ms(2000);
-
- while(1)
- {
- LED0=0; //這里使用了位帶操作,也可以使用 GPIO_ResetBits(GPIOA,GPIO_Pin_8);
- delay_ms(20);
- LED0=1; //也可以使用 GPIO_SetBits(GPIOA,GPIO_Pin_8);
- delay_ms(20);
- a++;
- if(a==1)
- {
- a = 0;
- b++;
- }
- if(b == 10)
- {
- b = 0;
- c++;
- }
- if(c == 10)
- {
- c = 0;
- d++;
- }
- if(d == 10)d= 0;
- Bai_Wei = table[d];
- Shi_Wei = table[c];
- Ge_Wei = table[b];
- HC595_Display(Bai_Wei,Shi_Wei,Ge_Wei);
- //delay_ms(100);
- }
- }
復(fù)制代碼
所有資料51hei附件下載:
代碼:
STM32F103C6.7z
(179.12 KB, 下載次數(shù): 89)
2022-1-25 09:38 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
仿真:
protues.zip
(65.16 KB, 下載次數(shù): 71)
2022-1-24 15:29 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|