打印

恳求侠友改改!(电风扇温度,转速,定时控制程序)

[复制链接]
1835|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
pmmimosa|  楼主 | 2008-6-27 20:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
恳求侠友改改!(电风扇温度,转速,定时控制程序)
    keil可以通过,但仿真显示的结果不对,
    按键功能:K1功能;K2移位;K3递增;K4递减;
    
    设计的想法是开机显示当前的温度,可以设置时间,
上限温度,定时开始时间和定时结束时间。当处在设置
的时间段里边时,如果当前温度超过了上限值,则风扇
转,其转速受当前温度和上限温度的差值控制,差值越
小转速越慢,反之则越快,

    恳求高手们可以给我改改不胜感激!我的联系方式:
        QQ:270662589   Email:pmmimosa@126.com

#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
uchar display[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,//0~9
                 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xff};//带点0~9;关数码管
uchar disbit[4];
uchar hour,min,sec,hour1,min1,hour2,min2;
uint count_down;
uint temp5,temp,temp1,temp2;
uchar htemp,ltemp;
uchar or_b;
uchar show_p;
uchar attr;
char tep;
bit led_on;
bit flash;
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
sbit S1=P3^4;
sbit S2=P3^5;
sbit S3=P3^6;
sbit S4=P3^7;
sbit CORT=P1^4;
void time_to();
void pwm_temp();


void delay(uchar t)//112ms?
{  uchar i;
   while(t--)
   for(i=0;i<10;i++);
}

void main()

   hour=0;min=0;sec=0;count_down=8000;
   hour1=0;min1=0;hour2=23;min2=59;
   htemp=24;ltemp=0;
   flash=0;
   show_p=0;
   attr=0xff;
   led_on=1;

   TMOD=0x22;
   TH0=0xFF;TL0=0x8C;//0.125ms,ff8cH;1/8000s用于走时;提供A/D时钟,640kHZ以下
   TH1=0xB8;TL1=0x00;//20ms,B800H;用于按键扫描
   TR0=1;TR1=1;
   ET0=1;ET1=1;EA=1;
   while(1)
   ;

    

}



void pwm_temp()
{  if(EOC==1)
     {  OE=1;
        temp5=P2;
        OE=0;
     }
   temp=temp5*1000/256;
   temp1=htemp*10+ltemp;
   if(temp>temp1)
     {  temp2=temp-temp1;
        if(temp2<40)
          {  CORT=1;
             delay(temp2);
             CORT=0;
             delay(40-temp2);
          }
        else
          CORT=1;
     }
   ST=1;ST=0;
}

void time_to()//定时时间的处理
{  if(hour2>=hour1)
     {if(hour1==hour2)
        {  if(min2>min1)
             or_b=1;
           else
             or_b=2;
         }
      else
        or_b=3;
      }
   else
     or_b=2;
   switch(or_b)
   {  case 1: if(hour==hour1&&min<min2&&min>min1)
                pwm_temp();
      case 2: if(hour>=hour1)
                {  if(hour==hour1)
                     {  if(min>min1)
                           pwm_temp();
                     }
                   else
                     pwm_temp();
                 }
               if(hour<=hour2)
                 {  if(hour==hour2)
                      {  if(min<min2)
                           pwm_temp();
                      }
                    else
                      pwm_temp();
                 }
      case 3: if(hour==hour1&&min>min1)
                pwm_temp();
              if(hour>hour1&&hour<hour2)
                pwm_temp();
              if(hour>hour1&&hour==hour2)
                {  if(min<min2)
                     pwm_temp();
                }
   }
    return;
}





void time0(void) interrupt 1
{  CLK=~CLK;
   count_down--;
   if(count_down==1||count_down==4001)
     flash=~flash;
   if(count_down==0)
     {  count_down=8000;
        sec++;
        if(sec==60)
          {  sec=0;
             min++;
             if(min==60)
               { min=0;
                 hour++;
                 if(hour==24)    
                   hour=0;
               }
          }
     }
   TH0=0xFF;TL0=0x8C;//0.125ms,ff8cH
}





void time1(void) interrupt 3
{  uchar i;
   TH1=0xB8;TL1=0x00;
  
  /************键值处理*************/
    if(K1==0&&led_on==1)
   {  if(show_p==1)
        show_p=0;
      if(show_p==0)
        show_p=3;
      if(show_p==3)
        show_p=4;
      if(show_p==4)
        show_p=5;
      if(show_p==5)
        show_p=1;
   }
   if(K2==0&&led_on==1)
   {  switch(attr)
        {case 0xff:attr=0x3f;break;
         case 0x3f:attr=0xcf;break;
         case 0xcf:attr=0xff;
        }
   }
   if(K3==0)
   {  switch(attr)
        {case 0xff:if(show_p==0)
                     led_on=~led_on;
                     break;
         case 0x3f:if(show_p==0)
                     hour=(hour+1)%24;
                   if(show_p==3)
                     htemp=(htemp+1)%100;
                   if(show_p==4)
                     hour1=(hour1+1)%24;
                   if(show_p==5)
                     hour2=(hour2+1)%24;
                   break;
         case 0xcf:if(show_p==0)
                     min=(min+1)%60;
                   if(show_p==3)
                     ltemp=(ltemp+1)%10;
                   if(show_p==4)
                     min1=(min1+1)%60;
                   if(show_p==5)
                     min2=(min2+1)%60;
        }
   }
    if(K4&&led_on==1)
      {  switch(attr)
           {case 0xff:if(show_p==0||show_p==3||show_p==4||show_p==5)
                        show_p=1;
                      break;
            case 0x3f:if(show_p==0)
                        {  tep=hour-1;
                           if(tep<0)
                             hour=23;
                           else hour=tep;
                        }
                      if(show_p==3)
                        {  tep=htemp-1;
                           if(tep<0)
                             htemp=99;
                           else htemp=tep;
                        }
                      if(show_p==4)
                        {  tep=hour1-1;
                           if(tep<0)
                             hour1=23;
                           else hour1=tep;
                         }
                       if(show_p==5)
                        {  tep=hour2-1;
                           if(tep<0)
                             hour2=23;
                           else hour2=tep;
                        }
                       break;
             case 0xcf:if(show_p==0)
                        {  tep=min-1;
                           if(tep<0)
                             min=59;
                           else min=tep;
                        }
                      if(show_p==3)
                        {  tep=ltemp-1;
                           if(tep<0)
                             ltemp=9;
                           else ltemp=tep;
                        }
                      if(show_p==4)
                        {  tep=min1-1;
                           if(tep<0)
                             min1=59;
                           else min1=tep;
                         }
                       if(show_p==5)
                        {  tep=min2-1;
                           if(tep<0)
                             min2=59;
                           else min2=tep;
                       }
           }
      }
   /*********当前显示的内容*********/
   if(show_p==0)
   {  disbit[0]=hour/10;
      disbit[1]=hour%10+10;
      disbit[2]=sec/10;
      disbit[3]=sec%10;
   }
   if(show_p==1)
   {  disbit[0]=20;
      disbit[1]=temp/100;
      disbit[2]=(temp%100)/10+10;
      disbit[3]=temp%100;
   }
   if(show_p==3)
   {  disbit[0]=20;
      disbit[1]=temp1/100;
      disbit[2]=(temp%100)/10+10;
      disbit[3]=temp%10;
   }
   if(show_p==4)
   {  disbit[0]=hour1/10;
      disbit[1]=hour1%10+10;
      disbit[2]=min1/10;
      disbit[3]=min1%10;
   }
   if(show_p==5)
   {  disbit[0]=hour2/10;
      disbit[1]=hour2%10+10;
      disbit[2]=min2/10;
      disbit[3]=min2%10;
   }

         if(led_on)
       { for(i=0;i<4;i++)
           { 
              if(flash||attr&(0x80>>i))
               {  P0=display[disbit];
                  switch(i)
                  {  case 0:S1=1;delay(10);S1=0;
                     case 1:S2=1;delay(10);S2=0;
                     case 2:S3=1;delay(10);S3=0;
                     case 3:S4=1;delay(10);S4=0;
                  }
               }
           }
       }
     else S1=S2=S3=S4=0;
}







相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

11

帖子

0

粉丝