新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > [C51代码]广告灯的循环移动

[C51代码]广告灯的循环移动

作者: 时间:2016-11-10 来源:网络 收藏
#include

/************************************************/
sbit Key=P2^0;
static unsigned char p=0;

本文引用地址:https://www.eepw.com.cn/article/201611/317081.htm
void delay1ms(unsigned int count)
{
int x,y;
for(x=0;x for(y=0;y<120;y++);
}
/************************************************/
void ScanKey()
{
if(Key==0)
{
delay1ms(1);
if(Key==0)
{
p++;
if(p==8) p=0;
}
while(Key==0); //按键锁定,每次按键只加1
}
}
/************************************************/
void main()
{
unsigned char i;
unsigned char a,b;
unsigned char temp=0x0f;
while(1)
{ ScanKey();
for(i=0;i<8;i++)
{
a=temp< b=temp>>(8-p);
P0=a|b;
}
}
}


评论


技术专区

关闭