-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.5.c
52 lines (49 loc) · 1.58 KB
/
2.5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/********************************************************************
* 文件名 : 动态显示.c
* 描述 : 八位数码管依次显示0,1,2,3,4,5,6,7
这里是做一个动态的演示实验。
最开始,两个数码管闪烁间隔时间为50豪秒,每闪烁一次,
间隔时间减少1毫秒,当间隔时间小到一定程度的时候,
因为人的视觉暂留现象,就不会发现数码管在闪烁了。
***********************************************************************/
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/********************************************************************
* 名称 : Delay_1ms()
* 功能 : 延时子程序,延时时间为 1ms * x
* 输入 : x (延时一毫秒的个数)
* 输出 : 无
***********************************************************************/
void Delay(uint i)
{
uint x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
/********************************************************************
* 名称 : Main()
* 功能 : 数码管的显示
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Main(void)
{
uchar i,j=50;
while(1)
{
for(i=0;i<8;i++)
{
//每位数码管依次闪烁
P0 = 0; //消隐
P2 = i; //选择哪一位数码管点亮
P0 = table[i]; //赋值段码给P0口
Delay(j); //延时
}
if(j>=3) //当大于3毫秒的时,执行括号中的语句
{
j-=1; //延时时间自减1毫秒
}
}
}