電腦可調(diào)溫度控制器源程序
if (SetTF) IntNum2 = IntNum2 + 1; //用于閃爍計(jì)數(shù)
if (IntNum2 > 50 ) IntNum2 = 0;
if (KeyTF) IntNum3 = IntNum3 + 1; //用于防止按鍵連按
if (IntNum3 > 25)
{
IntNum3 = 0;
KeyTF = 0;
}
if ((SetTF) (IntNum2 25)) goto InitEnd; //計(jì)數(shù)在后半段時(shí)顯示
LEDPort = LED_One;
LEDOneC = 0;
Delay_510();
LEDOneC = 1; //顯示百位數(shù)
LEDPort = LED_Two;
LEDTwoC = 0;
Delay_510();
LEDTwoC = 1; //顯示十位數(shù)
LEDPort = LED_Three;
LEDThreeC = 0;
Delay_510();
LEDThreeC = 1; //顯示個(gè)位數(shù)
}
InitEnd:;
}
void V2ToV(void) //數(shù)值轉(zhuǎn)換
{
TLV = TLV >> 4;
THV = THV 4; //讀出的高低位數(shù)值移位
TMV = TLV | THV; //合并高低位放入TM為實(shí)際溫度值
Sign = 0;
if (SetTF || !Key_SET)
Sign = TMSetV >> 7; //取符號
else
Sign = TMV >> 7;
if (Sign)
{
if (SetTF || !Key_SET)
{
LED_One = (~(TMSetV-1)) / 100; //SET狀態(tài)下顯示設(shè)定值
LED_Two = ((~(TMSetV-1)) - LED_One * 100)/10;
LED_Three = (~(TMSetV-1)) - LED_One * 100 - LED_Two * 10;
}
else
{
LED_One = (~TMV) / 100; //轉(zhuǎn)換百位值
LED_Two = ((~TMV) - LED_One * 100)/10;
LED_Three = (~TMV) - LED_One * 100 - LED_Two * 10;
}
}
else
{
if (SetTF || !Key_SET)
{
LED_One = (TMSetV) / 100; //SET狀態(tài)下顯示設(shè)定值
LED_Two = (TMSetV - LED_One * 100)/10;
LED_Three = TMSetV - LED_One * 100 - LED_Two * 10;
}
else
{
LED_One = (TMV) / 100; //轉(zhuǎn)換百位值
LED_Two = (TMV - LED_One * 100)/10;
LED_Three = TMV - LED_One * 100 - LED_Two * 10;
}
}
//轉(zhuǎn)LED字段
if (LED_One) //超過百時(shí)十位的處理
LED_Two = LEDDis[LED_Two];
else
{
if (LED_Two == 0)
LED_Two = LEDDis[10];
else
LED_Two = LEDDis[LED_Two];
}
if (Sign)
LED_One = LEDDis[11];
else
{
if (LED_One == 0)
LED_One = LEDDis[10];
else
LED_One = LEDDis[LED_One];
}
LED_Three = LEDDis[LED_Three];
}
void InitDS1820(void) //初始化DS1820
{
TMPort = 1; //拉高TMPort
_nop_(); //保持一個(gè)周期
TMPort = 0; //拉低TMPort
Delay_510(); //延時(shí) DS1820復(fù)位時(shí)間要500us的低電平
TMPort = 1; //拉高TMPort
_nop_(); //保持
_nop_();
_nop_();
Delay_110(); //延時(shí)110us 等待DS1820回應(yīng)
if (!TMPort) //回應(yīng)信號為低電平
DS1820ON = 1;
else
DS1820ON = 0;
Delay_110(); //延時(shí)
Delay_110();
TMPort = 1; //拉高TMPort
}
void ROMDS1820(void) //跳過ROM匹配
{
#pragma asm
MOV A,#0CCH
MOV R2,#8
CLR C
WR1:
CLR P3_7
MOV R3,#6
DJNZ R3,$
RRC A
MOV P3_7,C
MOV R3,#23
DJNZ R3,$
SETB P3_7
NOP
DJNZ R2,WR1
SETB P3_7
#pragma endasm
}
void TMVDS1820(void) //溫度轉(zhuǎn)換指令
{
#pragma asm
MOV A,#44H
MOV R2,#8
CLR C
WR2:
CLR P3_7
MOV R3,#6
DJNZ R3,$
RRC A
MOV P3_7,C
MOV R3,#23
DJNZ R3,$
SETB P3_7
NOP
DJNZ R2,WR2
SETB P3_7
#pragma endasm
}
void TMRDS1820(void) //讀出溫度指令
{
#pragma asm
MOV A,#0BEH
MOV R2,#8
CLR C
WR3:
CLR P3_7
MOV R3,#6
DJNZ R3,$
RRC A
MOV P3_7,C
MOV R3,#23
DJNZ R3,$
SETB P3_7
NOP
DJNZ R2,WR3
SETB P3_7
#pragma endasm
}
評論