background image

01 闪烁的 LED

/*  名称:闪烁的 LED

说明:LED 按设定的时间间隔闪烁

*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P1^0;
//延时
void DelayMS(uint x)
{

uchar i;
while(x--)
{

for(i=0;i<120;i++);

}

}
//主程序
void main()
{

while(1)
{

LED=~LED;
DelayMS(150);

}

}

02  从左到右的流水灯

/*  名 称 : 从 左 到 右 的 流 水

说 明 : 接 在 P0 口 的 8 个

LED 从 左 到 右 循 环 依 次 点 亮 ,
产生走马灯效果
*/
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//延时
void DelayMS(uint x)
{

uchar i;
while(x--)
{

1