|
原代码:
#include<reg52.h>
#include<intrins.h>//字符循环移动函数库
void delays()//延迟
{
int x,y;
for(x=0;x<110;++x)
for(y=0;y<1000;++y);
}
void delayms(unsigned int xms)//x ms延迟
{
unsigned int c,h;
for(c = 0; c<xms; ++c)
for(h = 0; h<110; ++h);
}
void main()
{
//从左到右,再从右到左的流水灯
unsigned char j;
unsigned char k;
unsigned char temp;
int i=0;
P2 = 0xff;
delays();
temp=0x7f;
for(k=0;k<7;k++)
{
P2=temp;
delays();
temp=_cror_(temp,1); //字符循环右移实现右移
}
for(j=0;j<8;j++)
{
P2=temp;
delays();
temp=_crol_(temp,1); //字符循环左移实现左移
}
/*另外一种思路,用移位运算符实现
unsigned char a,i;
a=0xfe;
for(i=0;i<7;i++)
{
P2=a;
delays();
a=a<<1;//1移动,其他补零
a=a|0x01;//左移一位后与0x01相或(只要满足一个条件) 0000 0001
// //或a=a|0x00;逐个点亮
}
a=0x7f;
for(i=0;i<7;i++)
{
P2=a;
delays();
a=a>>1;//1移动,其他补零
a=a|0x80;//右移一位后与0x80相或(只要满足一个条件) 1000 0000
// //或a=a|0x00;逐个点亮
}*/
/*用数组实现从两侧到中间,再从中间到两侧流水灯
int e;
int i=0;
unsigned char d[]={0x7e,0xbd,0xdb,0xe7};//定义亮灯熄灯数组
for(e=0;e<3;e++) //两侧到中间
{
P2=d[e];
delays();
}
for(e=3;e>=0;e--) //中间到两侧
{
P2=d[e];
delays();
}*/
}
新手上路,请多指教,谢谢!
|
评分
-
查看全部评分
|