全部文件:提取码:azxy 直接看题目吧。我感觉这一届的主要考点是如何用定时器读取10个温度值。
#include "STC15F2K60S2.h"
#include "intrins.h"
#include "ds1302.h"
#include "onewire.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
extern unsigned char time[3];
u8 code duan[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
u8 temp_cc[10];
u8 temp=0;
u8 time_xz=1;
u8 num=0;
u8 model=0;
u8 led_flag=0;
u8 count=0;
u8 count1=0;
void delay(u16 i)
{
while(i--);
}
void Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xA0;
TH0 = 0x15;
TF0 = 0;
ET0 = 1;
EA = 1;
}
void Service_T0() interrupt 1
{
count++;
if(count==200)
{
count=0;
count1++;
}
if(count1==time_xz)
{
count1=0;
temp_cc[num]=temp;
num++;
}
if(num==10)
{
TR0=0;
model=2;
num=0;
led_flag=1;
}
}
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;
}
}
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<<com;
Chan_hc573(7);
P0=dat;
}
void Close_smg()
{
Chan_hc573(6);
P0=0x00;
Chan_hc573(7);
P0=0xff;
}
void Display_stat()
{
if(model==0)
{
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
Smg_display(2,duan[10]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[time_xz/10]); delay(1000);
Smg_display(7,duan[time_xz%10]); delay(1000);
Close_smg();
}
else if(model==1)
{
Smg_display(0,duan[time[0]/16]); delay(1000);
Smg_display(1,duan[time[0]%16]); delay(1000);
if(time[2]%16%2==0)
{
Smg_display(2,duan[11]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
}
else
{
Smg_display(2,duan[10]); delay(1000);
Smg_display(5,duan[10]); delay(1000);
}
Smg_display(3,duan[time[1]/16]); delay(1000);
Smg_display(4,duan[time[1]%16]); delay(1000);
Smg_display(6,duan[time[2]/16]); delay(1000);
Smg_display(7,duan[time[2]%16]); delay(1000);
Close_smg();
}
if(model==2)
{
Smg_display(0,duan[11]); delay(1000);
Smg_display(1,duan[0]); delay(1000);
Smg_display(2,duan[num]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[temp_cc[num]/10]); delay(1000);
Smg_display(7,duan[temp_cc[num]%10]); delay(1000);
Close_smg();
}
}
void Key_down()
{
if(S4==0)
{
delay(100);
if(S4==0)
{
while(S4==0) {Display_stat();}
if(model==0)
{
if(time_xz==1) {time_xz=5;}
else if(time_xz==5) {time_xz=30;}
else if(time_xz==30) {time_xz=60;}
else if(time_xz==60) {time_xz=1;}
}
}
}
if(S5==0)
{
delay(100);
if(S5==0)
{
while(S4==0) {Display_stat();}
if(model==0) {TR0=1;model=1;}
}
}
if(S6==0)
{
delay(100);
if(S6==0)
{
while(S6==0) {Display_stat();}
if(model==2)
{
led_flag=0;
num++;
if(num==10) {num=0;}
}
}
}
if(S7==0)
{
delay(100);
if(S7==0)
{
while(S7==0) {Display_stat();}
if(led_flag==0)
{
if(model==2) {model=0;}
}
}
}
}
void LED()
{
Chan_hc573(4);
if(led_flag==1)
{
if(time[2]%16%2==0) {P00=0;}
else {P00=1;}
}
else {P00=1;}
}
void main()
{
Init_system();
Timer0Init();
Wire_time();
while(1)
{
LED();
Key_down();
Read_time();
Display_stat();
temp=DS18B20_Read();
}
}
|