|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
--------------------------------------------------------------------------------
#include <reg52.h>
#include <intrins.h>
void Delay10ms(unsigned int c);
main()
{
unsigned char LED;
LED = 0xfe;
while (1)
{
P0 = LED;
Delay10ms(50);
LED = LED << 1; if (P0 == 0x00)
{
LED = 0xfe; // 0xfe = 1111 1110
}
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
}
}
}
<<左移运算符,LED<<1就是把LED向左移1位,右边填0,LED一开始是FE,二进制是1111 1110,左移一位,右边填0就是 1 111 11100,因为LED只能存8元,最高位舍弃掉,就是111 11100
|
|