51单⽚机学习代码(LED灯)完成了布置的LED灯的花式闪烁。代码还是⼗分简单的,⼀看就懂!
#include<reg51.h>
void DelayUs2x(unsigned char); //延迟函数的头⽂件
void DelayMs(unsigned char);//延迟函数的头⽂件
void main()
{
unsigned char i,w;
while(1)
{
for(i=0,w=0x80;i<8;i++)
{
P1 = ~w;
w = w >> 1;
DelayMs(200);
}//从右⾄左依次变亮;
for(i=0,w=0x01;i<8;i++)
{
P1 = ~w;
w = w << 1;
DelayMs(200);
}//从左⾄右依次变亮;
for(i=0,w=0x7f;i<8;i++)
{
P1 = w;
w = w >> 1;
DelayMs(200);
}//从右⾄左逐渐变亮;
for(i=0,w = 0x7f;i<8;i++)
{
P1 = ~w;
w = w >> 1;
DelayMs(200);
}//从右⾄左逐渐熄灭;
for(i=0,w=0xfe;i<8;i++)
{
P1 = w;
w = w << 1;
DelayMs(200);
}//从左⾄右逐渐变亮;
for(i=0,w=0xfe;i<8;i++)
{
P1 = ~w;
w = w << 1;
DelayMs(200);
}//从左⾄右逐渐熄灭;
P1 = 0x7e;
DelayMs(200);
P1 = 0x3c;
DelayMs(200);
P1 = 0x18;
DelayMs(200);
P1 = 0x00;
DelayMs(200);
P1 = 0xe7;
DelayMs(200);
P1 = 0xc3;
DelayMs(200);
P1 = 0x81;
DelayMs(200);
P1 = 0x00;
DelayMs(200);
for(i=0;i<8;i++)
{
P1 = 0xaa;
DelayMs(200);
P1 = 0x55;
html代码转链接
DelayMs(200);
} //单亮双灭,双亮单灭8次;
}
}
void DelayUs2x(unsigned char n)//t = 2*n+5 us {
while(–n);
}
void DelayMs(unsigned char n)//t = n ms
{
while(n–)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
这是基于89c51芯⽚的led开发

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。