控制单片机p1口输出,实现led1~led8左,右流水灯循环,各灯间隔时间为100ms,要求用是、定时器实现延时

如题所述

52单片机,从左至右代码:#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=120;i>0;i--);
}
}

void main()
{
P0 = 0xFE;
while(1)
{
P0 = _crol_(P0,1);
DelayMS(150);
}
}
左右来回代码:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=120;t>0;t--);
}
}

void main()
{
uchar i;
P2=0x01;
while(1)
{
for(i=7;i>0;i--)
{
P2=_crol_(P2,1);
DelayMS(150);
}
for(i=7;i>0;i--)
{
P2=_cror_(P2,2);
DelayMS(150);
}
}
}
花样流水灯代码:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int

uchar code Pattern_P0[]=
{
0xfc,0xf9,0xf3,0xe7,0xcf,0x9f
};
uchar code Pattern_P2[]=
{
0xf5,0xf6,0xfe,0x54,0x56,0x76,0xd7,0x49,0xa9,0xe4,0xc6
};

void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=120;t>0;t--);
}
}

void main()
{
uchar i;
while(1)
{
for(i=136;i>0;i--)
{
P0=Pattern_P0[i];
P2=Pattern_P2[i];
DelayMS(150);
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-12-07
很好~~~
第2个回答  2010-12-06
还做不出来我就来帮你做一个!!
相似回答