Home > database >  How to use the buttons in the control of single chip microcomputer LED lights? The great god look at
How to use the buttons in the control of single chip microcomputer LED lights? The great god look at

Time:10-11


#include
Sbit LED=P0 ^ 0;
Sbit k1=P2 ^ 0;
Unsigned char mode, k1_s;
Void delay (unsigned int x)
{
While (x -);
}
Void the key ()
{
If (k1==0)
{
Delay (50);
If (k1==0)
{
K1_s=1;
}
}
If ((k1==1) & amp; & (k1_s==1))
{
K1_s=0;
Mode++;
If (mode & gt;=2) mode=0;
}
}
Void mode_s ()
{
If (mode==0)
{
LED=1;
}
If (mode_s==1)
{
LED=0;
}
}
Void main ()
{
While (1)
{
The key ();
Mode_s ();
}
}
  • Related