用獨立按鍵控制流水燈轉(zhuǎn)向,按下獨立按鍵流水燈向右移動,再按下獨立按鍵流水燈向左移動
此代碼用到
邏輯左移:_crol_(移動對象,移動的位數(shù))文章來源:http://www.zghlxwxcb.cn/news/detail-723372.html
邏輯右移:_cror_(移動對象,移動的位數(shù))文章來源地址http://www.zghlxwxcb.cn/news/detail-723372.html
#include <REGX52.H>
#include <INTRINS.H> //導(dǎo)入頭文件
unsigned char LEDNum;
unsigned int count;
void Delay1ms(unsigned int xms) //@11.0592MHz //延時函數(shù)
{
unsigned char i, j;
while (xms--)
{
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void main()
{
while(1)
{
if(P3_1==0)
{
Delay1ms(20);
while(P3_1==0);
Delay1ms(20); //軟件消抖
P2=0xFE;
Delay1ms(500);
LEDNum = 0xFE;
while(1)
{
while(count == 0) //當(dāng)count為0時進(jìn)入此循環(huán)
{
LEDNum =_crol_(LEDNum,1);
P2 = LEDNum;
Delay1ms(500);//1
if(P3_1==0)
{
Delay1ms(20);
while(P3_1==0);
Delay1ms(20);
count = 1; //再次按下K1改變count值使進(jìn)入邏輯右移
LEDNum = LEDNum;
}
}
while(count == 1) //當(dāng)count為1時進(jìn)入此循環(huán)
{
LEDNum =_cror_(LEDNum,1);
P2 = LEDNum;
Delay1ms(500);
if(P3_1==0)
{
Delay1ms(20);
while(P3_1==0);
Delay1ms(20);
count = 0; //再次按下K1改變count值使進(jìn)入邏輯左移
LEDNum = LEDNum;
}
}
}
}
}
}
到了這里,關(guān)于在51單片機(jī)中使用一個獨立按鍵控制流水燈方向的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!