Home > other >  Emergency 51 single-chip microcomputer and 18 b20 temperature alarm
Emergency 51 single-chip microcomputer and 18 b20 temperature alarm

Time:10-05

#include #include <18 b20. H> #include P1 sbit KEY1=^ 0; P1 sbit KEY2=^ 1; Sbit KEY3=p ^ 2; P1 sbit KEY4=^ 3; Sbit KEY5=P1 ^ 4; Sbit KEY6=P1 ^ 5; Sbit KEY7=P1 ^ 6; Sbit KEY8=P1 ^ 7; # define DataPort P0 # define KeyPort P1sbit LATCH1=P2 ^ 0; Sbit LATCH2=P2 ^ 1; Sbit alert1=P2 ^ 4; Sbit alert2=P2 ^ 5; Sbit work1=P2 ^ 6; Sbit work2=P2 ^ 7; Bit ReadTempFlag; Bit updownFlag; Unsigned char code dofly_DuanMa [10]={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f}; Unsigned char code dofly_weiMa [8]={XFD 0 xfe, 0, 0 XFB, 0 xf7, 0 xef, 0 XDF, 0 XBF, 0 x7f}; Unsigned char TempData [8]. Int Temp [6]={- 55-10, 9,60,61,125}; Unsigned long count=0; Unsigned int h=0; Unsigned char fushu=0, fuxian=0; Void the Display (unsigned char FirstBit, unsigned char num); Void Init_Timer0 (void); Unsigned char Keyscan (void); Void dly (int m, int k); Void ReadTemp (void); Void main (void) {int num, k; Init_Timer0 (); While (1) {if (! UpdownFlag) ReadTemp (); Num=Keyscan (); If (num>=1 & amp; & Num<=6) {count=0; K=num - 1; Dly (Temp [k], k); } else if (updownFlag==1 & amp; & Num==7) {count=0; \ [k] + +; Dly (Temp [k], k); } else if (updownFlag==1 & amp; & Num==8) {count=0; \ [k] -; Dly (Temp [k], k); }}} to void the Display (unsigned char FirstBit, unsigned char num) {static unsigned char I=0; DataPort=0; LATCH1=1; LATCH1=0; DataPort=dofly_weiMa + FirstBit [I]; LATCH1=1; LATCH2=0; DataPort=dofly_DuanMa [I]; LATCH1=1; LATCH1=0; i++; If (I=num) I=0; } void Init_Timer0 (void) {TMOD |=0 x01; TH0=0 x00; TL0=0 x00; EA=1; ET0=1; TR0=1; 1 {} void Timer0_isr (void) interrupt the static unsigned int num. TH0=(65536-2000)/256; TL0=(65536-2000) % 256; The Display (0, 8); num++; If (num==300) {num=0; ReadTempFlag=1; } count++; If (count==5000) {count=0; UpdownFlag=0; } h++; If (h==500) {h=0; Alert2=1; {if}} unsigned char Keyscan (void) (! {KEY1) DelayMs (10); if(! {KEY1) while (! KEY1); {return 1; }}} else if (! {KEY2) DelayMs (10); if(! {KEY2) while (! KEY2); {return 2; }}} else if (! KEY3) {DelayMs (10); if(! {KEY3) while (! KEY3); {return 3; }}} else if (! KEY4) {DelayMs (10); if(! KEY4) {while (! KEY4); {return 4; }}} else if (! KEY5) {DelayMs (10); if(! {KEY5) while (! KEY5); {return 5; }}} else if (! KEY6) {DelayMs (10); if(! {KEY6) while (! KEY6); {return 6; }}} else if (! KEY7) {DelayMs (10); if(! {while (KEY7)! KEY7); {return 7; }}} else if (! KEY8) {DelayMs (10); if(! {KEY8) while (! KEY8); {return 8; }}} else return 0; M} void dly (int, int k) {updownFlag=1; If (m& 0 x8000) {TempData [0]=0 x40; M=~ m; M +=1; } the else TempData [0]=0; If (m/100==0) TempData [1]=0; The else TempData [1]=dofly_DuanMa [m/100]; If ((m/100==0) & amp; & (100) % (m/10==0)) TempData [2]=0; The else TempData [2]=dofly_DuanMa (100) m %/10; TempData [3]=dofly_DuanMa [10] (100) m % % | 0 x80. TempData [5]=0 x63; TempData [6]=0 x39; If (k % 2==0) TempData [7]=0 x38; The else TempData [7]=0 x76; } void ReadTemp (void) {unsigned int TempH, TempL, Temp [6], Temp1, Temp2; If (ReadTempFlag==1) {ReadTempFlag=0; Temp=ReadTemperature [] []; If (Temp2 & amp; 0 x8000 fuxian)=1; The else fuxian=0; If (Temp& 0 x8000) {TempData [0]=0 x40; Temp=~ Temp; Temp +=1; Fushu=1; } else {TempData [0]=0; Fushu=0; } TempH=Temp> 4. TempL=Temp& 0 x0f; TempL TempL *=6/10; If (fushu) {if (fuxian) {alert2=1; Work2=1; Temp1=~ Temp [2]. Temp1 +=1; If (TempH> Temp1) {alert1=0; Work1=0; } else {alert1=1; Work1=1; }} else {alert1=0; Work1=0; {}} else if (fuxian) alert1=1; Work1=1; } else {Temp2=Temp [2]. If (TempH=Temp [4]) {alert2=0; Work2=0; } else {alert2=1; Work2=1; }} if TempH/100==0) TempData [1]=0; The else TempData [1]=dofly_DuanMa TempH/100; If ((TempH/100==0) & amp; & (100) (TempH %/10==0)) TempData [2]=0; The else TempData [2]=dofly_DuanMa (TempH % 100)/10; TempData [3]=dofly_DuanMa [10] (100) TempH % % | 0 x80. TempData [4]=dofly_DuanMa [TempL]; TempData [5]=0 x63; TempData [6]=0 x39; TempData [7]=0; }}

CodePudding user response:

#include
#include <18 b20. H>
#include
P1 sbit KEY1=^ 0;
P1 sbit KEY2=^ 1;
Sbit KEY3=p ^ 2;
P1 sbit KEY4=^ 3;
Sbit KEY5=P1 ^ 4;
Sbit KEY6=P1 ^ 5;
Sbit KEY7=P1 ^ 6;
Sbit KEY8=P1 ^ 7;
# define DataPort P0
# define KeyPort P1
Sbit LATCH1=P2 ^ 0;
Sbit LATCH2=P2 ^ 1;

Sbit alert1=P2 ^ 4;
Sbit alert2=P2 ^ 5;
Sbit work1=P2 ^ 6;
Sbit work2=P2 ^ 7;
Bit ReadTempFlag;
Bit updownFlag;
Unsigned char code dofly_DuanMa [10]={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};
Unsigned char code dofly_weiMa [8]={XFD 0 xfe, 0, 0 XFB, 0 xf7, 0 xef, 0 XDF, 0 XBF, 0 x7f};
Unsigned char TempData [8].
Int Temp [6]={- 55-10, 9,60,61,125};
Unsigned long count=0;
Unsigned int h=0;
Unsigned char fushu=0, fuxian=0;
Void the Display (unsigned char FirstBit, unsigned char num);
Void Init_Timer0 (void);
Unsigned char Keyscan (void);
Void dly (int m, int k);
Void ReadTemp (void);
Void main (void)
{
Int num, k;
Init_Timer0 ();
While (1)
{
if(! UpdownFlag)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related