您的位置:首页东哥开发网家用电器开发
内容搜索:
阅读内容
背景:#EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  

智能电加热定时控制电路原程序

[日期:2007-12-30 ] [来源:www.picavr.com 作者:] [字体: (投递新闻)

智能电加热定时控制电路原程序

程序代码

#include <reg51.h>

#include <intrins.h>

#include<stdlib.h>

#define uchar unsigned char

#define uint unsigned int

#define AddWr 0xa0                                               //器件地址选择及写标志

#define AddRd 0xa1                                               //器件地址选择及读标志

sbit Sda= P1^3                                                 //串行数据

sbit Scl= P1^4                                                  //串行时钟

sbit WP= P1^5                                                 //硬件写保护

idata byte rom_sed[9];

idata byte rom_rec[7];

rom_sed[0]=0x00; rom_sed[1]=0x00;

rom_sed[2]=0x00; rom_sed[3]=0x55;

rom_sed[4]=0x23; rom_sed[5]=0x31;

rom_sed[6]=0x06; rom_sed[7]=0x92;

rom_sed[8]=0x99;

 

sbit U3 CLK   = P1^2;ˆ

sbit U3 SD    = P1^1

sbit U4CLK   = P1^3;

sbit U4SD     =P1^4;

sbit TSOR    =  P1^0;

sbit FUZAI =   P1^6;

sbit  BELL =   P1^7;

sbit  RS    = P2^7;  

sbit  RW    = P2^1

sbit  EN    = P2^5;

sbit  S0   =  P3^0

sbit  S1   =   P3^1

sbit  S2   =   P3^2

sbit  S3   =   P3^3

sbit  S4   =   P3^4

sbit  S5   =   P3^5

/*------------------------------------------全局变量-------------------------------------------------------*/

static unsigned char  max temp1,maxtemp2;         //温度值的最大值整数部分、小数部分

static unsigned char min temp1, mintemp2;          //温度值的最小值整数部分、小数部分

static unsigned char hour,  min,;                      //  小时 ,分钟、

static unsigned char hourset str1[];                 //设定的小时数

static unsigned char minset str2[]  ;                 //设定的分钟数

static unsigned char  countset;                      //设定的定时次数

static char line0[] ="     00:00      ";

static char line1[] ="   . C           ”;

/*-------------------------------------------------------------------------------------------------------------*/

 void          KeyboardDelay();

 

/*-------------------------------------------LCD驱动函数------------------------------------------------*/

void          DelayL();

void                     DelayS();

void                     WriteCommand(unsigned char c);

void                     WriteData(unsigned char c);

void                     ShowChar(unsigned char pos,unsigned char c);

void                     ShowString(unsigned char line,char *ptr);

void                     InitLcd();

 /*---------------------------------------------时钟函数-----------------------------------------------*/

void  PCF8563WriteRead()

/*------------------------------------------温度传感器驱动----------------------------------------------*/

void          Delay15();

void          Delay60();

void          Delay100ms();

void          Write0TS();

void          Write1TS();

bit           ReadTS();

void          ResetTS();

void          WriteByteTS(unsigned char byte);

unsigned char  ReadByteTS();

void          InitTS();

void          GetTempTS();

/*-------------------------------------------------主程序---------------------------------------------------*/

void main (void) {

     char code str1[]  ="  Hello World!  ";

     char code str2[]  ="   2005-4-12   ";

          unsigned char i;

countset=0;  

     SP=0x50;

          

          TSOR=1;                                //1-wire总线释放

 

     DelayL();

          InitLcd();                                   //初始化LCD

          DelayL();

     ShowString(0,str1);                              //启动画面

     ShowString(1,str2);

          for(i=0;i<15;i++)

       Delay100ms();

     InitInterupt();                                   //初始化中断设置

Hoursetstr1[0]=00;                                      //缺省定时00小时

     Minsetstr2[0]=00;                                        //缺省定时00分钟

      min=rom-rec[0]                                       //初始化数据

         Hour = rom-rec[1]

  BELL =  0;

FUZAI =  0;  

          count=0;

     P1=0xFF;

         InitTS();                                   //初始化温度计

          while(1)                                                 //循环显示温度值

          {

       GetTempTS();

,       line1[0]=0x20;

            i=temp1;

if(I< max temp1&& i> min temp1)                                                               //告警灯亮

 ALERT=1;

 FUZAI =1

            line1[1]=i/10+0x30;                                  //显示温度的十位

            line1[2]=i%10+0x30;                       //显示个位

            line1[4]=temp2+0x30;                      //显示小数位

        

            ShowString(1,line1);

            line0[5]=hour/10+0x30;                            //显示时间

            line0[6]=hour%10+0x30;

       line0[8]=min/10+0x30;

            line0[9]=min%10+0x30;

            ShowString(0,line0);       

       Delay100ms();

          }

}

//------------------------------------------------初始化中断设置--------------------------------------------------//

void InitInterupt()

{

  TMOD=0x21;                        

  TL1=0x00;

  TH1=0x00;

   EA=1;                

   TR1=1;

   TL0=0x00;                                                

  TH0=0x00; 

  ET0=1;

  IT0=1;

}

 

void KeyboardDelay()                                        //按键中断延时

{

 unsigned char i,j;

 i=0x40;

 j=0xFF;

 while(i--)

  while(j--);

}

 

/*-----------------------------------------T0中断处理-----------------------------------------------------*/

 

Timer0_process() interrupt 1 using 0

{

  EA=0;

  TR0=0;

  TL0=0x00;

  TH0=0x00

    if(hour==hoursetstr1[])                                                     

  {

   if(min==minsetstr2[])                                                           

   {

if(temp<maxtempset&&temp>mintempset)

{

FUZAI =1

     else

          {

      FUZAI =0

    

     } 

   }

 

  } 

  TR0=1;

  EA=1;

}

/*--------------------------------------LCD驱动子程序--------------------------------------------------*/

void DelayL()                          

{unsigned char i,j;

 i=0xF0;

 j=0xFF;

 while(i--)

  while(j--);

}

 

void DelayS()                                                  

{

 unsigned char i;

 i=0x1F;

 while(i--);

}

 

void WriteCommand(unsigned char c)      

{

 DelayS();

 EN=0;

 RS=0;

 RW=0;

 _nop_();

 EN=1;

 P0=c;

 EN=0;

}

 

void WriteData(unsigned char c)         

{

 DelayS();

 EN=0;

 RS=1;

 RW=0;

 _nop_();

 EN=1;

 P0=c;

 EN=0;

 RS=0;

}

 

void ShowChar(unsigned char pos,unsigned char c)

{

 unsigned char p;

 if(pos>=0x10)

    p=pos+0xB0;

 else

    p=pos+0x80;

 WriteCommand(p);

 WriteData(c);

}

 

void ShowString(unsigned char line,char *ptr)   

{

 unsigned char l,i;

 l=line<<4;

 for(i=0;i<16;i++)

   ShowChar(l++,*(ptr+i));

}    

 

void InitLcd()

{

 DelayL();

 WriteCommand(0x38);

 WriteCommand(0x38);

 WriteCommand(0x06);

 WriteCommand(0x0C);

 WriteCommand(0x01);

 WriteCommand(0x80);

}    

/*--------------------------------------------T1中断处理-键盘子程序-------------------------------------------------*/

Timer1_process() interrupt3 using 0

{

EA=0;

  TR1=0;

  TL1=0x00;

  TH1=0x00

  unsigned   char   k

bit  ho/mi;

bit  tempfiag

ho/mi   =  0;

tempfiag  =0

  P3 =0x3F

  k=P3;

  k=k&0x3F;

void     24C04  WriteRead()

  while(k&0x02&& ho/mi= 0 )

  {

        ho/mi   =~ho/mi

KeyboardDelay()

While(K&0x08)

{

KeyboardDelay()

       hour++;

               }

While(K&0x10)

{

KeyboardDelay()

  Hour——;

                }

}  

   while( k&0x02&& ho/mi= 1)

{

  ho/mi   =~ho/mi

KeyboardDelay()

While(K&0x08)

{

KeyboardDelay()

      min++;

                 }

While(K&0x10)

{

KeyboardDelay()

      Min——;

      }

}  

 

while(k&0x01)

{

 

while(k&0x02&& ho/mi= 0 )

{

ho/mi   =~ho/mi

KeyboardDelay()

While(K&0x08)

{

KeyboardDelay()

                       hourset++;

                     }

While(K&0x10)

{

KeyboardDelay()

         Hourset——;

                     }

}  

              while( k&0x02&& ho/mi= 1)

{

ho/mi   =~ho/mi

KeyboardDelay()

While(K&0x08)

{

KeyboardDelay()

       minset++;

}

While(K&0x10)

{

KeyboardDelay()

                              Minset——-;

                           }

}

Hoursetstr[]=hourset

Minsetstr[]=minset

countset++;

*Hoursetstr++

*Minsetstr++

                While(K&0X04&&tempfiag=0 )

{

 

tempfiag=~ tempfiag

While(K&0x08)

{ max temp1++}

While(K&0x10)

                      {max temp1++}

While(K&0X04&&tempfiag=1 )

{

tempfiag=~ tempfiag

While(K&0x08)

{min temp1——}

While(K&0x10)

                      {min temp1——}

}

 }

}

}

      While(K&0X20)

{return}

 

  void     24C04  WriteRead()

TR1=1;

EA=1;

/*------------------------------------------温度传感器DS1820子程序-------------------------------------------*/

void Delay100ms()                               //延时100ms

{

unsigned  char i,j,k;

 for(i=0;i<8;i++)

   for(j=0;j<25;j++)

     for(k=0;k<250;k++);

}

 

void Delay15()                                   //延时