#include <reg51.h> #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar Temperature[]={0,0,0}; sbit ST= P2^5; sbit OE= P2^7; sbit EOC =P2^6; sbit CLK =P2^4; sbit H_LED=P3^0; sbit L_LED=P3^1; sbit BEEP = P3^7; uchar t=0; void DelayMS(unit x) { uchar i; while(x--)for(i = 0;i< 120; i++); } void Show_Temperature() { uchar i,DSY_IDX[]= {0xF7,0xFB,0xFD}; for (i = 0;i < 3; i++)} { P0 = DSY_CODE[ Temperature ]; P2 &= DSY_IDX; DelayMS(5); P2 |= 0x0F; } } void main() { uchar d; IE = 0x8a; TMOD = 18; TH0 = 245; TL0 = 0; TH1 = (65536 -1000) /256; TL1 = (65536 -1000) &256; TR0 = 1; H_LED = L_LED = 1; while(1) { ST = 0; ST = 1; ST = 0; while(1) { if(EOC == 1) { OE = 1; d = P1; OE = 0; Temperature[2] = d/100; Temperature[1] = d%100/10; Temperature[0] = d%10; Show_Temperature(); if(d < 60) { TR1 = 1; L_LED = !H_LED; } else if(d > 160) { TR1 = 1; H_LED = !L_LED; } else { TR1 = 0; H_LED = L_LED = 1; } break; } } } } void T0_INT() interrupt 1 { CLK = ~CLK; } void T1_INT() interrupt 3 { TL1 = (65536 -1000) % 256; BEEP = ~BEEP; { if (++t !=150 ) return; } else { if (++t !=60 ) return; } t = 0; DelayMS(20); } |