⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 em78p468 ntc lcd测温全套(c语言源代码).txt

📁 用EM78P468 ntc rc测温全套程序 用EM78P468 ntc rc测温全套程序
💻 TXT
📖 第 1 页 / 共 2 页
字号:
 tamp=Bin1toBcd(RC_num);
 //Rc_t<<=4;
 //Rm_t|=Rc_t;
 P6CR&=0xfC;
 PORT6&=0xfC;

 return tamp;
}

void display(uchar temp_v,uchar tamp_v,uchar set_tmp)
{     
        uchar real_dep,tmp1;
      
        LCD_ADDR=6;
        LCD_DB=0x08;
        //风速+冷热
        LCD_ADDR=0;
        LCD_DB=tamp_v;
        LCD_ADDR=23;
      _asm
  {
   swap %tamp_v
  }
     LCD_DB=tamp_v;
     //当时温度
     real_dep=temp_v;
     temp_v>>=4;
 
     real_dep&=0x0f;
  LCD_ADDR=4;
  tmp1=lcd_ram[real_dep];
  tmp1&=0xf7;
  LCD_DB=tmp1;
 
  LCD_ADDR=3;
  _asm
  {
   swap %tmp1
  }
  LCD_DB=tmp1; 
 
  tmp1=temp_v&0x0f;
  LCD_ADDR=2;
  tmp1=lcd_ram[tmp1];
  LCD_DB=tmp1;
  LCD_ADDR=1;
  _asm
  {
   swap %tmp1
  }
  LCD_DB=tmp1;
  //设置温度
  real_dep=set_tmp;
     set_tmp>>=4;
 
     real_dep&=0x0f;
  LCD_ADDR=10;
  tmp1=lcd_ram[real_dep];
  LCD_DB=tmp1;
 
  LCD_ADDR=9;
  _asm
  {
   swap %tmp1
  }
  LCD_DB=tmp1; 
 
  tmp1=set_tmp&0x0f;
  LCD_ADDR=8;
  tmp1=lcd_ram[tmp1];
  LCD_DB=tmp1;
  LCD_ADDR=7;
  _asm
  {
   swap %tmp1
  }
  LCD_DB=tmp1;  
}

/*void lcd_on_off(void)
{ 
    uchar i;
 for(i=0;i<32;i++)
 {
  LCD_ADDR=i;
  LCD_DB=0xff;
 }
 
 for(dly=0x00ff;dly;dly--)
 {
  WDTC();
 }
  
 for(i=32;i;i--)
 {
  LCD_ADDR=i;
  LCD_DB=0;
 }
 
 for(dly=0x1fff;dly;dly--)
 {
  WDTC();
 }
 
}*/

/******************************按键扫描************************/
/*****************************按键处理************************/
void KeyDo(uchar key)
{ 
    uchar fan_temp;
    if (key == ON_OFF){
      if(mode_on_off==0)
        {
         key_flag=1;
         mode_on_off=1;
        }
      else
        {
         mode_on_off=0;
        }

    }
    else if (key == FAN)
    {
     timer1=0;
      key_flag=1;
        if(mode_on_off==1)
         {
         fan_temp=fan_st&0xe0;
         if(fan_temp==0x80)
          {
           fan_st|=0x40;
           fan_st&=0x7f;
          }
         else if(fan_temp==0x40)
          {
           fan_st|=0x20;
           fan_st&=0xbf;
          }
         else if(fan_temp==0x20)
          {
           fan_st|=0x80;
           fan_st&=0xdf;
          }
         }
    }
   else if (key == MODE)
   {
    timer1=0;
     key_flag=1;
     if(mode_on_off==1)
      {
        fan_temp=fan_st&0x03;
        if(fan_temp==0x01)
           fan_st++;
           else
           {
           fan_st|=0x01;
           fan_st&=0xfd;
           }    
      }
    }
    else if (key == DECREASE)
    {     
           timer1=0;
           key_flag=1;
            if (set_temper == 10)
            {
                set_temper = 10;
            }
            else
            {
                set_temper--;
            }
    }
    else if (key == INCREASE)
    {       timer1=0;
           key_flag=1;
            set_temper++;
            if (set_temper > 30)
            {
               set_temper = 30;
            }

    }

}
uchar KeyScan(void)
{
      uchar temp = 0;
      temp = PORT8;
      temp&=0x1f;
      if(temp!=0x1f)
      return temp;
    return 0x1f;
}

void _intcall counter1_l(void) @ 0x0C:low_int 3
{
 
}

void _intcall counter1(void) @ int 3
{
  //backup R4
  _asm
   {
     SWAPA 0x04
     MOV 0x1F,A
   }  
 
   //backup C system
  _asm
    {
    BS 0X4,6
    BS 0X4,7  
 MOV A,0X10 // USE 1 BYTE C TYPE,C SYSTEM BACKUP
 MOV 0X3C+1,A
 MOV A,0X14
 MOV 0X3B+1,A
 MOV A,0X18
 MOV 0X3A+1,A
 MOV A,0X1B
 MOV 0X39+1,A
 MOV A,0X1C
 MOV 0X38+1,A
    }
  
            ISR=0;
            timer_2ms_ok=1;
            if (key_state == 0)
           {
            new_key = KeyScan();
            if (new_key != 0x1f)
            {
                key_state++;
            }
           }
        else if (key_state < 5)
        {
            if (KeyScan() == new_key)
            {
                key_state++;
            }
            else
            {
                key_state = 0;
            }
        }
        else if (key_state == 5)
        {
            key_state++;
            KeyDo(new_key);
        }
        else if (key_state == 6)
        {
            key_temp = KeyScan();
            if (key_temp == 0x1f)
            {
                key_state ++;
            }
            else if (key_temp == DECREASE || key_temp == INCREASE)
            {
                if (key_tcc >= 10)
                {
                    key_tcc = 5;
                    KeyDo(key_temp);
                }
                else
                {
                    key_tcc++;
                }
            }
        }
        else if (key_state < 10)
        {
            if (KeyScan() == 0x1f)
            {
                key_state ++;
            }
            else
            {
                key_state = 6;
            }
        }
        else if (key_state == 10)
        {
            key_state = 0;
            key_tcc = 0;
      
        }
     if(mode_on_off)
     {
     times++;
     timer1++;
     //rst_tim++;
     }
 
  // Write your code (inline assembly or C) here
 
   //restore C system
  _asm
    {
    BS 0X4,6
    BS 0X4,7
 MOV A,0X3C+1 // USE 1 BYTE C TYPE,C SYSTEM RESTORE
 MOV 0X10,A
 MOV A,0X3B+1
 MOV 0X14,A
 MOV A,0X3A+1
 MOV 0X18,A
 MOV A,0X39+1
 MOV 0X1B,A
 MOV A,0X38+1
 MOV 0X1C,A
    }

 
  //restore R4
  _asm
   {
     SWAPA 0x1F
     MOV 0X04,A
   }
 
}

void  main()
  {
  uchar temp1,temp2;
  uchar i,j;
  uchar *r;
     uchar b;
     uchar c;
     uchar stst;
     uchar *w;
     uchar x;
     uchar y;
       DISI();
    tms(10);
    sys_init();
    //lcd_init(0xf7);
       r_buf[0]=0;
       r_buf[1]=0;

     r=r_buf; //读参数
     b=0x00;
     c=2;

     w=w_buf; //写参数
     x=0x00;
     y=2;
   
     //w_buf[0]=0x81;
     //w_buf[1]=0x19;
     // wt24c(w,x,y); //出厂写EEPROM

     rd24c(r,b,c); //初始读EEPROM
     fan_st=r_buf[0];
     set_temper=r_buf[1];
     temp1=test_temperature();
  for(i=0;i<32;i++)// 清屏
 {
  LCD_ADDR=i;
  LCD_DB=0;
 }
  for(dly=0x1fff;dly;dly--)
 {
  WDTC();
 }
 //LED=1;
 ENI();
 while(1)
 { 
     //key_find();
   while(timer_2ms_ok)
   {
   timer_2ms_ok=0;
   if(mode_on_off==1)
    {
     lcd_init(0xf7);
     if(key_flag)
     {
     LED=1;
     if(timer1>=200)
      {
      timer1=0;
      LED=0;
      if((r_buf[0]!=fan_st)||(r_buf[1]!=set_temper))
      {
      r_buf[0]=fan_st;
      r_buf[1]=set_temper;
      w_buf[0]=fan_st;
      w_buf[1]=set_temper;
      wt24c(w,x,y); //写
      }
      key_flag=0;     
         }
      }
        if(times>=250)
         {
          temp1=test_temperature();
       times=0;
      }
       temp2=Bin1toBcd(set_temper);
    display(temp1,fan_st,temp2);
    PORT6=fan_st&0xe0;
    stst=fan_st&0x01;
    if(stst==0x01)
    {
       COOL=1;
       HOT=0;
       tms(1);
       if((temp1>temp2)&&(COL_RST_FLAG==0))
         {
            j=0;
          while((COOL_IF_L)&&(j<=3))
            {
             j++;
             COL_RST=1;
                   tms(10);
                   COL_RST=0;
             COL_RST_FLAG=1;                 
             }       
                   j=0;
          }
        else if((temp1<temp2)&&(COL_RST_FLAG==1))
         { 
            j=0;
        while((COOL_IF_H)&&(j<=3))
             {
             j++; 
             COL_RST=1;
                   tms(10);
                   COL_RST=0;
             COL_RST_FLAG=0;                 
             }       
                  j=0;
         }        
    }
        //stst=fan_st&0x02;
    else
     {
        COOL=0;
         if((temp1<temp2)&&(HEAT_IF_H))
         HOT=1;
         else
         HOT=0;
      }
      
    }
    else
    {
     LED=0;
     lcd_init(0x00);
     LOW=0;
     MID=0;
     HI=0;
     COOL=0;
     HOT=0;
     }

 WDTC();
   }
 WDTC();
 }
  }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -