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--)