Each time you press the S2 button of the independent keyboard, one LED connected to the P1 port moves down one bit.
#include
Sbit BY1=P3^4; //Define the input of the button S2
Unsigned char count; / / button count, each press, count plus 1
Unsigned char temp;
Unsigned char a,b;
Void delay10ms(void) //delay program
{
Unsigned char i,j;
For(i=20;i>0;i--)
For(j=248;j>0;j--);
}
Key () / / button to determine the program
{
If(BY1==0) //Determine whether to press the keyboard. When the MCU is powered on, all IO ports are // high level, S2 is grounded at one end and the other end is connected to P3.4, so when the button is pressed, P3. 4 port / / direct grounding, at this time detection P3.4 must be low.
{
Delay10ms(); //delay, software to interfere
If(BY1==0) //Confirm the button press
{
Count++; //key count plus 1
If(count==8) //count 8 times to recount
{
Count=0; //clear count
}
}
While(BY1==0);//Wait for the button to be released, if the button is not released, it will wait here.
}
}
Move() //Advertising light moves the move function down
{
a=temp<
b=temp>>(8-count);// _crol_() function
P1=a|b;
}
Main()
{
Count=0; //Initialize parameter settings
Temp=0 xfe;
P1=0 xff;
P1=temp;
While(1) //Forever loop, scan to determine if the button is pressed
{
Key(); //call key recognition function
Move(); //call the ad light move function
}
}
Stainless Steel Piano Wire,Ss Piano Wire,Stainless Steel Spring Piano Wire,Piano Wire Stainless Steel
ShenZhen Haofa Metal Precision Parts Technology Co., Ltd. , http://www.haofametals.com