void tmpwrite (unsigned char dat)  //写一个字节
{   
 uint i;
 uchar j;
 bit testb; 
 for (j=1;j<=8;j++)
 { 
  testb = dat & 0x01;
  dat = dat >> 1; 
  if (testb)
  { 
   P3_5 = 0;       // 写0 
   i++; i++;  
   P3_5 = 1; 
   i=8; while (i>0) i--; 
  }
  else 
  {
   P3_5 = 0;       // 写0 
   i=8; while (i>0) i--; 
   P3_5 = 1;
   i++; i++;  
  }
 }
}
void tmpchange(void) // ds1820 开始转换
{  
 tmreset ();        // 复位
 //tmpre ();        // 等待存在脉冲 
 delay (1);        // 延时
 tmpwrite (0xcc);       // 跳过序列号命令
 tmpwrite (0x44);       // 发转换命令 44H, 
}
void tmp (void) // 读取温度
{ 
 uchar a,b;
 tmreset ();        // 复位
 delay (1);        // 延时
 tmpwrite (0xcc);       // 跳过序列号命令
 tmpwrite (0xbe);       // 发送读取命令
 a=tmpread2 ();       // 读取低位温度 
 b=tmpread2 ();        //读取高位温度 
 flag1=b;        //若b为1则为负温
 if(flag1)
 {
  TEMP=~a+1;      //如果为负温则去除其补码
 }
 else 
 {
  TEMP=a; 
 }
}
rom()          // 读取器件序列号子程序
{
 tmreset ();        //复位
 delay (1);            //延时
 tmpwrite(0x33);       //发送读序列号子程序
}
fengmingqi()                                         //温度判断函数
{ P0_5=0;                                           //蜂鸣器正常不鸣叫
   do{
if((TEMP<=(E-0X0A))&&(TEMP>=(F|0X0A))&&(P3_5==0))// X-0X0AH为所要的温度减5度B|0X0AH为所要的温度加5度
    P0_5=1;                                           //蜂鸣器异常
      }while(1);
}
wendushuru()                                         //键盘设置理想温度
{uchar KEY1,KEY2,KEY3,i=1;
  P2=0xff;
  KEY1=Getch(); i++;
  KEY2=Getch(); i++;
  KEY3=Getch(); i++;
  if((i=2)&&(KEY2=='*'))                       //*号表示输入温度下限值
     E=KEY1;
  if((k=3)&&(KEY3=='*'))
     E=M*KEY1+KEY2;
     i=1;
  if((i=2)&&(KEY2=='#'))                         //#号表示输入温度上限值
     F=KEY1;
  if((k=3)&&(KEY3=='#'))
    F=M*KEY1+KEY2;
   
}
 temp_control()
{  P0_6=0;                                             //接风机
   P0_7=0;                                             // 接加热炉 
   Getch();
   if(TEMP<E)    
   P0_7=1;                             //当温度低于温度下限时,进行升温
   Getch();
   if(TEMP>E)    
   P0_6=1;                             //当温度高于温度上限时,进行降温
}
bit lcd_busy()   //检查LCD 忙状态
//lcd_busy 为1 时,忙,等待。lcd-busy 为0 时,闲,可写指令与数据
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (bit)(P0&0x80);
LCD_EN = 0;
return result;
}
void lcd_wcmd(uchar cmd)        //写指令数据到LCD
//RS=L,RW=L,E=高脉冲,D0-D7=指令码。
{while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
_nop_();
_nop_();
P0 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN = 1;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN = 0;
<< 上一页 [11] [12] [13] [14] [15] [16] 下一页