找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 938|回复: 1
打印 上一主题 下一主题
收起左侧

求大家帮我看看程序,测量温度大于设置温度LED1灯亮,测量温度小于设置温度LEd2灯亮。

[复制链接]
跳转到指定楼层
楼主
ID:707421 发表于 2020-5-22 21:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include < reg52.h >
#include < character.h >
#include < lcd.h >
#include < clock.h >
#include < sensor.h>
#include < calendar.h >
#include < key.h >


#define uchar unsigned char
#define uint unsigned int

sbit bell = P2 ^ 0;
sbit LED1 = P2 ^ 6;
sbit LED2 = P2 ^7;

void Delay_ms(unsigned int t)
{
        unsigned int i,j;
        for(i=0;i<t;i++)
        for(j=0;j<120;j++)
        ;
}
void Timer0_Service() interrupt 1
{
   static uchar count = 0;
   static uchar flag = 0;
   count = 0;
   TR0 = 0;      
   TH0 = 0x3c;
   TL0 = 0XB0;   
   TR0 = 1 ;     
   count ++;
   if( count == 20 )
   {
      bell = ~ bell;
      count = 0;
      flag ++;
   }
   if( flag == 6 )
   {
      flag = 0;
      TR0 = 0;   
   }

}

uchar HexNum_Convert(uchar HexNum)
{
uchar Numtemp;
Numtemp=(HexNum>>4)*10+(HexNum&0X0F);
return Numtemp;
}

void main( void )
{         
     unsigned char wendu[2]={30,20};
unsigned char clock_time[6] = {0X00,0X59,0X23,0X09,0X04,0X11};     
         unsigned char alarm_time[12]={20,8,12,10,11,10,10,13,11,14,10,16};
         unsigned char temperature[2] ,temperature1[2] ;
   unsigned int  zhengshuA,zhengshuB,zhengshu=0;
  unsigned int  xiaoshu_aA,xiaoshu_aB,xiaoshu_a;
  unsigned int  all;
    zhengshuA=temperature[0]/16+temperature[1]*16;
     xiaoshu_aA=(temperature[0]&0x0f)*10/16
    zhengshuB=temperature1[0]/16+temperature1[1]*16
    xiaoshu_aB=(temperature1[0]&0x0f)*10/16;
    zhengshu=zhengshuA+zhengshuB;      
    xiaoshu_a=xiaoshu_aA+xiaoshu_aB;
    all=(zhengshu*10+xiaoshu_a)/2;        
    Lcd_Initial();
        Clock_Fresh( clock_time );
        Clock_Initial( clock_time )
  LED1=0;
  LED2=0;

    EA = 1
    ET0 = 1;
          ET2 = 1
    TMOD = 0x01
          RCAP2H = 0x3c
    RCAP2L = 0xb0
    while( 1
        {
           switch( Key_Scan()
       {
          case up_array:
                               {
                       Key_Idle()
                       }
                               break;     
          case down_array
                                 {
                                                    Key_Idle()
                                                 }
                                 break;                  
                  case clear_array:
                                  {   
                                                     Key_Idle()
                                              }
                                                  break;
                  case function_array:
                             Key_Function( clock_time, alarm_time,wendu)
                                      }
                  case null:
                           {
                                        Clock_Fresh( clock_time )
                            Lcd_Clock( clock_time )
                Sensor_Fresh( temperature )
                                                                 Sensor1_Fresh( temperature1 );
                                                                 Delay_ms(1000);
                                                                 Sensor_Fresh( temperature )
                Sensor1_Fresh( temperature1 )
                                                                  Delay_ms(1000);
                                                                 Lcd_Temperture( temperature )
                                              Lcd_Temperture1( temperature1 )
                                                                Lcd_pingjun(temperature, temperature1);
                                                                 Delay_ms(1000);

                                                while(1)      
                                                {
                                                        if((all)<(wendu[1]*10))
                                                        {            
                                                        LED1=1;
                                                        LED2=0;      
                                                                                 break;}
          else
                                        {if((all)>(wendu[0]*10))
          {
                                               LED2=1;
                                                LED1=0;
                                                 break;}
                                                 else{LED2=0;
                                                LED1=0;break;}}
            break;}
                                         
                    }
        }
}
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:707421 发表于 2020-5-22 22:31 | 只看该作者
已经弄好了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表