Home > other >  Beginners 51 single-chip microcomputer and the great spirit to guide the following this figure progr
Beginners 51 single-chip microcomputer and the great spirit to guide the following this figure progr

Time:09-24

Here as I have to write code (led only after the simulation running water, and cannot achieve button control led and water) :

# include "reg52. H"//this file defines the MCU some special function register
# include//to use move function, so join the header file

typedef unsigned int u16;//to statement defines the data type
Typedef unsigned char u8;

# define led P1
Sbit k1=p3 ^ 0;
U8 a;

Void delay (under-16 I)
{
While (I -);
}


Void main ()
{
u8 i;
Led=0 xfe;
Delay (50000);//about 450 ms delay
While (1)
{
If (k1==0)
{
delay(1000);
If (k1==0)
{
A=~ a;
}
}
If (a==0)
{
for(i=0; i<7. I++)
{
Led, led=_crol_ (1);
Delay (50000);//about 450 ms delay
}
}
If (a==1)
{
for(i=0; i<7. I++)
{
Led, led=_cror_ (1);
Delay (50000);//about 450 ms delay
}
}
}
}

CodePudding user response:

refer to the original poster weixin_45811306 response:
here is I have to write code (led only after the simulation running water, and cannot achieve button control led and water) :

1. U8 a; A, not initialized.
2. If a=0, then a=~ a; After a=255,

CodePudding user response:

reference 1st floor yishumei response:
Quote: refer to the original poster weixin_45811306 response:

The following as I have to write code (led only after the simulation running water, and cannot achieve button control led and water) :

1. U8 a; A, not initialized.
2. If a=0, then a=~ a; After a=255,

Can you teach me how to change? thank you

CodePudding user response:

U8 a=0;//initialize

If (k1==0)
{
A=! A;//use logical
}

CodePudding user response:

To join https://ask.csdn.net/questions/906267

CodePudding user response:

#include //light water cycle
#include
# define uchar unsigned char
# define uint unsigned int
Uchar temp, a;
Sbit KEY=P3 ^ 0;
Void delay (uint z);
The void left ();
Void right ();
Void main ()
{
A=0;
Temp=0 xfe;//to an initial value
P1=temp;//light water port
While (1)
{
If (KEY==0)
{
a++;
If (a==1)
{
The left ();//left
}
If (a==2)
{
A=0;
Right ();//right
}

}
}
}
Void delay (uint z)
{
Uint x, y;
For (x=z; x> 0; X -)
For (y=112; Y> 0; Y -);
}
The void left ()
{
Temp=_crol_ (temp, 1);//shift
Delay (500);//delay 500 ms
P1=temp;
}
Void right ()
{
Temp=_cror_ (temp, 1);//shift
Delay (500);//delay 500 ms
P1=temp;
}
  • Related