/*--------函数申明--------*/
void mode_change();
void Init_timer0(void);
void Init_Timer1(void);
int main()
{
LCD_Init();
WRITE_Str(1,3,"Hello World",11);
WRITE_Str(2,1,"Welcome to Use",14);
sys_delays(5);
LCD_Clear();
WRITE_Str(1,3,"Choose mode",11);
mode_change();
WRITE_Str(2,3,"Tempture:",9);
WRITE_COM(0x80+0x40+12);
WRITE_DATA(0xdf);
WRITE_DATA(0x43);
Init_Timer0();
Init_Timer1();
while(1)
{
while(mode == 1)
{
IF(GD == 0)
{
sys_delayxms(200);
Counter=0;
L1=0;
L2=1;
L3=1;
TR1=1;
FS=0;
while(Flag_5s == 0);
TR1=0;
FS=1;
Flag_5s=0;
}
if(K1 == 0)
{
sys_delayxms(10);
if(K1 == 0)
{
mode=1;
LCD_Clear();
WRITE_Str(1,7,"Mode:1",6);
}
}
if(K2 == 0)
{
sys_delayxms(10);
if(K2 == 0)
{
mode=2;
LCD_Clear();
WRITE_Str(1,7,"Mode:2",6);
}
}
if(K3 == 0)
{
sys_delayxms(10);
if(K3 == 0)
{
mode=3;
LCD_Clear();
WRITE_Str(1,7,"Mode:3",6);
}
}
}
while(mode == 2)
{
if(GD == 0)
{
sys_delayxms(200);
Counter=0;
L1=0;
L2=0;
L3=1;
TR1=1;
FS=0;
while(Flag_10s == 0);
TR1=0;
FS=1;
Flag_10s=0;
}
if(K1 == 0)
{
sys_delayxms(10);
if(K1 == 0)
{
mode=1;
LCD_Clear();
WRITE_Str(1,7,"Mode:1",6);
}
}
if(K2 == 0)
{
sys_delayxms(10);
if(K2 == 0)
{
mode=2;
LCD_Clear();
WRITE_Str(1,7,"Mode:2",6);
}
}
if(K3 == 0)
{
sys_delayxms(10);
if(K3 == 0)
{
mode=3;
LCD_Clear();
WRITE_Str(1,7,"Mode:3",6);
}
}
}
while(mode == 3)
{
if(GD == 0)
{
sys_delayxms(200);
Counter=0;
L1=0;
L2=0;
L3=0;
TR1=1;
FS=0;
while(Flag_15s == 0);
TR1=0;
FS=1;
Flag_15s=0;
}
if(K1 == 0)
{
sys_delayxms(10);
if(K1 == 0)
{
mode=1;
LCD_Clear();
WRITE_Str(1,7,"Mode:1",6);
}
}
if(K2 == 0)
{
sys_delayxms(10);
if(K2 == 0)
{
mode=2;
LCD_Clear();
WRITE_Str(1,7,"Mode:2",6);
}
}
if(K3 == 0)
{
sys_delayxms(10);
if(K3 == 0)
{
mode=3;
LCD_Clear();
WRITE_Str(1,7,"Mode:3",6);
}
}
}
}
}
//模式选择
void mode_change()
{
mode=0;
while(mode == 0)
{
if(K1 == 0)
{
sys_delayxms(10);
if(K1 == 0)
{
mode=1;
LCD_Clear();
WRITE_Str(1,7,"Mode:1",6);
}
}
if(K2 == 0)
{
sys_delayxms(10);
if(K2 == 0)
{
mode=2;
LCD_Clear();
WRITE_Str(1,7,"Mode:2",6);
}
}
if(K3 == 0)
{
sys_delayxms(10);
if(K3 == 0)
{
mode=3;
LCD_Clear();
WRITE_Str(1,7,"Mode:3",6);
}
}
}
}
void Init_Timer0(void)
{
TMOD |= 0x01 ; //使用模式1,16位计数器,使用"|"符号可以在使用多个定时器时不受影响
TH0=(65535-50000)/256; //给定初值
TL0=(65535-50000)%256;
EA=1; //总中断打开
ET0=1; //定时器中断打开
TR0=1; //定时器开关关闭
}
void Timer0_IRS() interrupt 1
{
TH0=(65535-60000)/256; //给定初值
TL0=(65535-60000)%256;
Tem_Counter++;
if(Tem_Counter >= 25)
{
Tem_Counter=0;
ReadTemperature();
WRITE_Num(2,10,Tempture%100/10);
WRITE_Num(2,11,Tempture%10);
if(Tempture > 30)
BZ=0;
else
BZ=1;
}
}
void Init_Timer1(void)
{
TMOD |= 0x10 ; //使用模式1,16位计数器,使用"|"符号可以在使用多个定时器时不受影响
TH1=(65535-50000)/256; //给定初值
TL1=(65535-50000)%256;
EA=1; //总中断打开
ET1=1; //定时器中断打开
TR1=0; //定时器开关关闭
}
void Timer1_IRS() interrupt 3
{
TH1=(65535-50000)/256; //给定初值
TL1=(65535-50000)%256;
Counter++;
if(mode == 1 && Counter == 100)
{
Counter=0;
Flag_5s=1;
}
if(mode == 2 && Counter == 200)
{
Counter=0;
Flag_10s=1;
}
if(mode == 3 && Counter == 300)
{
Counter=0;
Flag_15s=1;
}
}
下面是仿真图
|