forked from MetalSeed/stc51_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.6.c
44 lines (41 loc) · 1.19 KB
/
1.6.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
/*****************************方法二**********************************
* 描述 : 本实验,让8个LED不停显示依照规律轮流显示。
首先,8个LED分别两次间隔显示。然后高4位显示和低4位显示。
最后间隔全亮、全灭两次。
采用查表方式进行操作,代码更短。
***********************************************************************/
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[10]={0xaa,0x55,0xcc,0x33,0x0f,0xf0,0x00,0xff,0x00,0xff};
/********************************************************************
* 名称 : Delay()
* 功能 : 延时,延时时间为 10ms * del
* 输入 : del
* 输出 : 无
***********************************************************************/
void Delay(uint del)
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<1827; j++)
;
}
/********************************************************************
* 名称 : Main()
* 功能 : 实现灯的闪烁
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Main(void)
{
uchar i;
while(1)
{
for(i=0;i<10;i++)
{
P0 = table[i];
Delay(30); //延时0.3秒
}
}
}