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

📄 ds1821_1.c

📁 PIC HiTech_C_Mike_Pearces_DS1821_thermostatwith Dallas DS1821 Programmer and schematic. Tested on P
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Write Current Temperature settings from the thermo device
//************************************************************************
void WriteCurrent(void)
{

 if(TempH >MAXTEMP) TempH=MAXTEMP;
 if(TempL < MINTEMP ) TempL= MINTEMP;

 D_Reset();          //-- Reset the Bus
 D_Write(0x01);      //-- Issue Write Temp High Command
 D_Write(TempH);     //-- Write the "High Temp"

 D_Reset();          //-- Reset the Bus
 D_Write(0x02);      //-- Issue Write Temp Low Command
 D_Write(TempL);     //-- Write the "Low Temp"

 D_Reset();          //-- Reset the bus
 D_Write(0x0C);      //-- Write Write Status Command
 D_Write(STATUS_CURRENT); //-- Write the status Byte
 //D_Write(TempS);     //-- Write the status Byte

}
//*********** END OF ReadCurrent


//************************************************************************
//                        DisplayCurrent
//Display current settings of the Buffer
//************************************************************************
void DisplayCurrent(void)
{
 ConvertForDisplay();
 
 DisplayBuff[0]=0;      //-- Command Byte

 switch(Edit.Area.Hundreds)   //-- Select '0','1' or '-'
 {
  case 0:
  case 1:
   DisplayBuff[2]=Digits[Edit.Area.Hundreds];
   break;
  case T_NEGATIVE:
   DisplayBuff[2]=MINUS;
   break;
  default:
   DisplayBuff[2]=ERROR;
   break;
 }

 DisplayBuff[3]=Digits[Edit.Area.Tens];   //-- The tens digit
 DisplayBuff[4]=Digits[Edit.Area.Ones];   //-- The Ones Digit

 switch(Edit.Area.Type) //-- Current Edit Mode
 {
  case T_HIGH:
   DisplayBuff[1]=THIGH;
   break;
  case T_LOW:
   DisplayBuff[1]=TLOW;
   break;

  case T_CLRL:
  case T_CLRH:
   DisplayBuff[1]=CLRC;
   DisplayBuff[2]=CLRL;
   DisplayBuff[3]=CLRR;
   if(Edit.Area.Type==T_CLRL)
   {
    if(ClrL)
    {
     DisplayBuff[4]=Digits[0];
    }
    else
    {
     DisplayBuff[4]=TLOW;
    }
   }
   else
   {
    if(ClrH)
    {
     DisplayBuff[4]=Digits[0];
    }
    else
    {
     DisplayBuff[4]=THIGH;
    }
   }
   break;


  case T_PROG:
   DisplayBuff[1]=PROGP;
   DisplayBuff[2]=PROGR;
   DisplayBuff[3]=PROGG;
   if(Programmed)
   {
    DisplayBuff[4]=PRGDONE;
   }
   else
   {
    DisplayBuff[4]=MINUS;
   }
   break;
  default:
   DisplayBuff[1]=ERROR;
   break;
 }

 //-- Write the buffer to the LCD module for displaying
 DisplayBuff[0]=0;
 I2C_Send(0x74,DisplayBuff,5);
}
//*********** END OF DisplayCurrent

//************************************************************************
//                          DoUserIO
// read keys and do what is required
//************************************************************************
void DoUserIO(void)
{

 switch(GetKeyPressed())
 {
  //*********** Minus Pressed **************
  case KEY_MINUS:
   switch(Edit.Area.Type)
   {
    case T_CLRL:
     TempL=0;
     ClrL=1;
     break;

    case T_CLRH:
     TempH=0;
     ClrH=1;
     break;

    case T_HIGH:
     TempH--;
     if(TempH < MINTEMP) TempH=MINTEMP;
     Programmed=0;
     ClrH=0;
     break;

    case T_LOW:
     TempL--;
     if(TempL < MINTEMP) TempL=MINTEMP;
     Programmed=0;
     ClrL=0;
     break;

    case T_PROG:
     WriteCurrent();
     Programmed=1;
     break;
   }
   break;

  //*********** Plus Pressed **************
  case KEY_PLUS:
   switch(Edit.Area.Type)
   {
    case T_CLRL:
     TempL=0;
     ClrL=1;
     break;

    case T_CLRH:
     TempH=0;
     ClrH=1;
     break;

    case T_HIGH:
     TempH++;
     if(TempH > MAXTEMP) TempH=MAXTEMP;
     Programmed=0;
     ClrH=0;
     break;

    case T_LOW:
     TempL++;
     if(TempL > MAXTEMP) TempL=MAXTEMP;
     Programmed=0;
     ClrL=0;
     break;

    case T_PROG:
     WriteCurrent();
     Programmed=1;
     break;
   }
   break;

  //*********** Select Pressed **************
  case KEY_SELECT:
   Edit.Area.Type++;
   if(Edit.Area.Type>T_PROG)Edit.Area.Type=0;
   break;
 }
 Current=Edit.Data[EditPosition];        //-- Ensure current data loaded
}
//*********** END OF DoUserIO

//************************************************************************
//GetKeyPressed
//************************************************************************
char GetKeyPressed(void)
{
 char pos,done=0;
 pos=4-EditPosition;
 temp=DisplayBuff[pos];
 while(!done)
 {
  DelayMs(250);
  if(Flash)
  {
   DisplayBuff[pos]=LBLANK;
   I2C_Send(0x74,DisplayBuff,5);  //-- Blank the Digit
  }
  if(!SW1)
  {
   done+=1;
  }
  if(!SW2)
  {
   done+=2;
  }
  DelayMs(250);
  if(Flash)
  {
   DisplayBuff[pos]=temp;
   I2C_Send(0x74,DisplayBuff,5); //-- Reshow the digit
  }
  switch(done)
  {
   case 1:
    if(SW1) done=0;            //-- Check if key still Held Down
    break;
   case 2:
    if(SW2) done=0;            //-- Check if key still Held Down
    break;
   case 3:
    if(SW1 | SW2) done=0;      //-- Check if both keys still Held Down
    break;
   default:
    done=0;
    break;
  }
 }
 return(done);
}
//*********** END OF GetKeyPressed

//************************************************************************
//                       ConvertForDisplay
//************************************************************************
void ConvertForDisplay(void)
{
 signed char temp=0;
 //---- Clear all values to start with -----
 Edit.Area.Hundreds=0;
 Edit.Area.Tens=0;
 Edit.Area.Ones=0;
 //---- Convert values to Editable Digits ----
 switch(Edit.Area.Type)
 {
  case T_HIGH:
   temp=TempH;
   break;

  case T_LOW:
   temp=TempL;
   break;

  default:
   return;
 }
 if(temp <0)
 {
  temp=0-temp;    //-- Convert all values to +ve Digits
  if(temp > 99) temp=99;
  Edit.Area.Hundreds=T_NEGATIVE;
 }
 else
 {
  if(temp >99)
  {
   Edit.Area.Hundreds=(temp/100);
   temp-=(Edit.Area.Hundreds*100);
  }
 }
 if(temp >9)
 {
  Edit.Area.Tens=(temp/10);
  temp-=(Edit.Area.Tens*10);
 }
 Edit.Area.Ones=temp;
 if(Edit.Area.Hundreds > 2)Edit.Area.Hundreds=0;
 if(Edit.Area.Tens > 9)Edit.Area.Tens=9;
 if(Edit.Area.Ones > 9)Edit.Area.Tens=9;
}
//*********** END OF ConvertForDisplay


//************************************************************************
//
//************************************************************************


//*********** END OF

//************************************************************************
//
//************************************************************************










⌨️ 快捷键说明

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