Home > other >  c51
c51

Time:10-30

For help: I want to have a dc motor and d/a conversion module is added to the following program, when the temperature is greater than 20 degrees when the fan open, when the temperature is 20 degrees below the fan closed, with a board is at89c51,

#include
# include "LCD. H"
# include "ds1302. H"
# include "temp. H"

Sbit K1=P3 ^ 0;
Sbit K2=P3 ^ 1;
Sbit K3=P3 ^ 2;
Sbit K4=P3 ^ 3;//pin connection
Sbit beep=P1 ^ 7;
Sbit JDQ=P1 ^ 6;

Void Int0Configuration ();
Void LcdDisplay ();
Unsigned char SetState SetPlace;
Void Delay10ms (void);//error 0 us
Uchar CNCHAR [6]="c";
Void LcdDisplay1 (int);
Void UsartConfiguration ();
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the function name: main
* function function: the main function
* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


Void main ()
{
Unsigned char I;
Int0Configuration ();
LcdInit ();
Ds1302Init ();
UsartConfiguration ();
LcdWriteCom (0 x8f + 0 x40);//write address 80 indicates the initial address 0 x88
LcdWriteData (" C ");
While (1)
{
If (SetState==0)
{
Ds1302ReadTime ();
}
The else
{
If (K1==0)//check whether keys K1 press
{
Delay10ms ();//to eliminate jitter
If (K1==0)
{
SetPlace++;
If (SetPlace>=7)
SetPlace=0;
}

While ((i<50) & amp; & (K1==0))//inspection or loose button
{
Delay10ms ();
i++;
}
i=0;
}
If (K2==0)//check whether key K2 press
{
Delay10ms ();//to eliminate jitter
If (K2==0)
{
TIME [SetPlace] + +;
If ((TIME/SetPlace & amp; 0 x0f) & gt; 9)//into BCD code,
{
TIME [SetPlace]=TIME [SetPlace] + 6;
}
If ((TIME/SetPlace & gt;=0 x60) & amp; & (SetPlace<2))//minutes only to 59
{
TIME [SetPlace]=0;
}
If ((TIME/SetPlace & gt;=0 x24) & amp; & (SetPlace==2))//hours only to 23
{
TIME [SetPlace]=0;
}
If ((TIME/SetPlace & gt;=0 x32) & amp; & (SetPlace==3))//day only to 31
{
TIME [SetPlace]=0;
}
If ((TIME/SetPlace & gt;=0 x13) & amp; & (SetPlace==4))//month to 12 only
{
TIME [SetPlace]=0;
}
If ((TIME/SetPlace & gt;=0 x7) & amp; & (SetPlace==5))//weeks only to 7
{
TIME [SetPlace]=1;
}
//if (SetPlace==5)//month to 12 only
//{
//TIME [SetPlace]=;
//}
}

While ((i<50) & amp; & (K2==0))//testing or loose button
{
Delay10ms ();
i++;
}
i=0;

}
}
LcdDisplay ();

LcdDisplay1 (Ds18b20ReadTemp ());
//Delay1ms (1000);//1 s clock brush a
}






}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the function name: LcdDisplay ()

* functions: display function* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void LcdDisplay ()
{
LcdWriteCom (0 x80 + 0 x40);
LcdWriteData (' 0 '+ TIME [2]/16);//
LcdWriteData (' 0 '+ (TIME [2] & amp; 0 x0f));
LcdWriteData (', ');
LcdWriteData (' 0 '+ TIME [1]/16);//points
LcdWriteData (' 0 '+ (TIME [1] & amp; 0 x0f));
LcdWriteData (', ');
LcdWriteData (' 0 '+ TIME [0]/16);//s
LcdWriteData (' 0 '+ (TIME [0] & amp; 0 x0f));

LcdWriteCom (0 x80);
LcdWriteData (' 2 ');
LcdWriteData (' 0 ');
LcdWriteData (' 0 '+ TIME [6]/16);//in
LcdWriteData (' 0 '+ (TIME [6] & amp; 0 x0f));
LcdWriteData (' - ');
LcdWriteData (' 0 '+ TIME [4]/16);//
LcdWriteData (' 0 '+ (TIME [4] & amp; 0 x0f));
LcdWriteData (' - ');
LcdWriteData (' 0 '+ TIME [3]/16);//day
LcdWriteData (' 0 '+ (TIME [3] & amp; 0 x0f));
X8d LcdWriteCom (0);
LcdWriteData (' 0 '+ (TIME [5] & amp; 0 x07));//week
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the function name: Int0Configuration ()
Features: * function configuration external interrupt 0
* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void Int0Configuration ()
{
//set INT0
IT0=1;//jump along the way (falling edge)
EX0=1;//open INT0 interruption allows,
EA=1;//open the total interruption
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the function name: Int0 ()
* functions: external interrupt 0 interrupt function
* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void Int0 () interrupt 0
{
Delay10ms ();
If (K3==0)
{
SetState=~ SetState;
SetPlace=0;
Ds1302Init ();
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the function name: Delay10ms
* functions: delay function, delay 10 ms
* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Delay10ms (void)//error 0 us
{
Unsigned char a, b, c;
For (c=1; C> 0; C -)
For (b=38; B> 0; B -)
For (a=130; A> 0; A -);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull