本课程设计借助电路仿真软件Protues对基于AT89C51单片机的温度报警器的设计,设计的内容是由单片机、ADC0808作为温度调节器、并由数码管显示的温度报警器。当调节温度小于60摄氏度或者高于160摄氏度,系统将产生不同频率的声音,并且对应的LED等闪烁。
- #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(intnb 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[i] ];
- P2 = DSY_IDX[i];
- 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);
- }
复制代码 |