跑马灯程序大全
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
L E D跑马灯(从右至左)#include<>
#include<>
#define uchar unsigned char
#define uint unsigned int
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<255;i++);
}
}
void main()
{
P1=0xfe;
while(1)
{ if(P1==0xef)
P1=0xfe;
else
P1=_crol_(P1,1);
DelayMS(80);
}
}
LED跑马灯(从左至右)
#include<>
#include<>
#define uchar unsigned char
#define uint unsigned int void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<255;i++);
}
}
void main()
{
P1=0xef;
while(1)
{ if(P1==0x7f)
P1=0xef;
else
P1=_cror_(P1,1); DelayMS(40);
}
}
LED跑马灯(左右循环)#include<>
#include<>
#define uchar unsigned char #define uint unsigned int void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<255;i++);
}
}
void main()
{
uchar i;
P1=0xef;
while(1)
{
for(i=0;i<4;i++)
{P1=_cror_(P1,1);
DelayMS(40); } P1=0xfe;DelayMS(40); for(i=0;i<3;i++)
{P1=_crol_(P1,1);
DelayMS(40); } P1=0xef;DelayMS(40); }
}
单个LED的闪烁
#include <>
#define uchar unsigned char #define uint unsigned int sbit LED = P1^0;
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=120;i>0;i--);
} }
void main()
{
while(1)
{
LED = ~LED;
DelayMS(150);
}
}
连绵灯
#include<>
#include<>
#define uchar unsigned char #define uint unsigned int void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<255;i++);
}
}
void main()
{
P1=0x0e;
while(1)
{ if(P1==0xb1)
P1=0x0e;
else
P1=_crol_(P1,1);
DelayMS(80); }
}