全部文件:提取码:azxy
这一届我感觉的难点应该是温度设置时的按键处理吧。不过每个人的理解不一样,难点感觉也不一样。还是直接看题目吧。
#include "stc15f2k60s2.h"
#include "onewire.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit H1=P3^0;
sbit H2=P3^1;
sbit H3=P3^2;
sbit H4=P3^3;
sbit L1=P4^4;
sbit L2=P4^2;
sbit L3=P3^5;
u8 code duan[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
u8 temp_setup[4];//温度设置储存数组
u8 model=1;//1为温度显示 2为温度设置
u8 qujian=0;//区间
u8 temp=0;//当前温度
u8 temp_sx=30;//温度上限
u8 temp_xx=20;//温度下限
u8 key_num=0;//按键值
u8 flag=0;//按键标志
u8 mi=0;//温度设置暂存值
u8 num=0;//温度设置时按键按下次数
u8 i=0;//刚进温度设置界面时等待设置温度数码管熄灭
u8 count=0;//定时器累加
u8 led_flag=0;//led标志
void delay(u16 i)
{
while(i--);
}
void Timer0Init(void) //5ms 12.000MHz
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xA0;
TH0 = 0x15;
TF0 = 0;
TR0 = 1;
ET0=1;
EA=1;
}
void Service_T0() interrupt 1
{
count++;
if(count==160/(2^qujian))
{
count=0;
led_flag=~led_flag;
}
}
void Chan_hc573(chose)
{
switch(chose)
{
case 4:
P2 = (P2 & 0x1f) | 0x80; break;
case 5:
P2 = (P2 & 0x1f) | 0xa0; break;
case 6:
P2 = (P2 & 0x1f) | 0xc0; break;
case 7:
P2 = (P2 & 0x1f) | 0xe0; break;
case 0:
P2 = (P2 & 0x1f) | 0x00; break;
}
}
void Init_system()
{
Chan_hc573(5);
P0=0x00;
Chan_hc573(4);
P0=0xff;
}
void Smg_display(u8 com,u8 dat)
{
Chan_hc573(7);
P0=0xff;
Chan_hc573(6);
P0=0x01<=temp_xx&&temp<=temp_sx) {qujian=1;}
else if(temp>temp_sx) {qujian=2;}
if(qujian==0)
{
Chan_hc573(4); if(led_flag==0) {P00=0;}//L1
Chan_hc573(5); P04=0; Chan_hc573(0);
}
else if(qujian==1)
{
Chan_hc573(4); if(led_flag==0) {P00=0;}//L1
Chan_hc573(5); P04=0; Chan_hc573(0);
}
else if(qujian==2)
{
Chan_hc573(4); if(led_flag==0) {P00=0;}//L1
Chan_hc573(5); P04=1; Chan_hc573(0);
}
if(temp_xx>temp_sx)
{
Chan_hc573(4); P01=0;//L2
}
}
void main()
{
Init_system();
Timer0Init();
while(1)
{
Temp_qj();
Key_down();
Setup_temp();
Temp_display_setup();
temp=DS18B20_Read();
}
}



