#include <control.H>
ulong systick;
uchar POS;
uchar data_dly;
uchar key_dly;
uint temperture;
uint AD_read;
uchar mode_flage;
uchar old_num=1;
uchar new_num=1;
uchar Timer_num = 17;
uchar Led_num = 4;
uchar temp_num = 25;
uchar Rtc_time;
uchar key_num;
uchar key4_flage;
uchar key5_flage1;
uchar key5_flage2;
uchar key8_flage;
uchar key9_flage;
uint count1=0;
uint count2=0;
bit Buzzer;
bit Relay;
bit read_flage;
bit bright_flage;
//*******************************************
void devies_init() //外设初始化
{
if(data_dly < 50) return;
else data_dly = 1;
temperture = ds18b20_read_temp(1);
AD_read = PCF8591_Read(0x01)*100/51.0;
}
//*******************************************
void smg_working(uchar channel) //显示任务
{
switch(channel)
{
case 0:
SMG[0] = Timer_Read[2]/16;
SMG[1] = Timer_Read[2]%16;
SMG[2] = 10;
SMG[3] = Timer_Read[1]/16;
SMG[4] = Timer_Read[1]%16;
SMG[5] = 10;
SMG[6] = Timer_Read[0]/16;
SMG[7] = Timer_Read[0]%16;
DOT[6] = 0,DOT[2] = 0;
break;
case 1:
SMG[0] = 13;
SMG[1] = 12;
SMG[2] = 12;
SMG[3] = 12;
SMG[4] = 12;
SMG[5] = temperture/100;
SMG[6] = temperture/10%10;
SMG[7] = temperture%10;
DOT[6] = 1,DOT[2] = 0;
break;
case 2:
SMG[0] = 14;
SMG[1] = 12;
SMG[2] = AD_read/100;
SMG[3] = AD_read/10%10;
SMG[4] = AD_read%10;
SMG[5] = 12;
SMG[6] = 12;
SMG[7] = mode_flage;
DOT[6] = 0,DOT[2] = 1;
break;
case 3:
SMG[0] = 14;
SMG[1] = 4;
SMG[2] = 12;
SMG[3] = 12;
SMG[4] = 12;
SMG[5] = 12;
SMG[6] = Timer_num/10;
SMG[7] = Timer_num%10;
DOT[6] = 0,DOT[2] = 0;
break;
case 4:
SMG[0] = 14;
SMG[1] = 5;
SMG[2] = 12;
SMG[3] = 12;
SMG[4] = 12;
SMG[5] = 12;
SMG[6] = temp_num/10;
SMG[7] = temp_num%10;
DOT[6] = 0,DOT[2] = 0;
break;
case 5:
SMG[0] = 14;
SMG[1] = 6;
SMG[2] = 12;
SMG[3] = 12;
SMG[4] = 12;
SMG[5] = 12;
SMG[6] = 12;
SMG[7] = Led_num%10;
DOT[6] = 0,DOT[2] = 0;
break;
}
}
//*******************************************
void key_working()
{
if(key_dly <10) return;
else key_dly = 1;
key_num = key_2x2_scan();
switch(key_num)
{
case 4: key4_flage = 1 - key4_flage;
break;
case 5:
if(key4_flage == 0) {key5_flage1 = (1+key5_flage1)%3;}
if(key4_flage == 1) {key5_flage2 = (1+key5_flage2)%3;}
break;
case 8: key8_flage = 1;
break;
case 9: key9_flage = 1;
break;
}
if(key4_flage == 0)
{
key5_flage2 = 0;
if(key5_flage1 == 0) smg_working(0);
else if(key5_flage1 == 1) smg_working(1);
else if(key5_flage1 == 2) smg_working(2);
}
else if(key4_flage == 1)
{
key5_flage1 = 0;
if(key5_flage2 == 0)
{
smg_working(3);
if(key8_flage == 1)
{
if(Timer_num>0)Timer_num = Timer_num - 1;
// if(Timer_num<1)Timer_num = 0;
key8_flage = 0;
}
if(key9_flage == 1)
{
if(Timer_num<23)Timer_num = Timer_num + 1;
// if(Timer_num>=23)Timer_num = 23;
key9_flage = 0;
}
}
else if(key5_flage2 == 1)
{
smg_working(4);
if(key8_flage == 1)
{
if(temp_num>0)temp_num = temp_num - 1;
key8_flage = 0;
}
if(key9_flage == 1)
{
if(temp_num<99)temp_num = temp_num + 1;
key9_flage = 0;
}
}
else if(key5_flage2 == 2)
{
smg_working(5);
if(key8_flage == 1)
{
if(Led_num>4)Led_num = Led_num - 1;
key8_flage = 0;
}
if(key9_flage == 1)
{
if(Led_num<8)Led_num = Led_num + 1;
key9_flage = 0;
}
}
}
}
*******************************************
void task_slove()
{
Rtc_time = Timer_Read[2]/16*10 + Timer_Read[2]%16;
if(AD_read > 100)
{
mode_flage = 0;
LED[Led_num-1] = 0;
}
else if(AD_read <= 100)
{
mode_flage = 1;
LED[Led_num-1] = 1;
}
if(Rtc_time>=Timer_num) LED[0] = 1;
else if(Rtc_time<Timer_num && Rtc_time>8) LED[0] = 0;
if(temperture < temp_num*10) LED[1] = 1;
else if(temperture >= temp_num*10) LED[1] = 0;
}
//*******************************************
void task_working()
{
ds1302_timer_read();
task_slove();
devies_init();
key_working();
}
//*******************************************
void system_init()
{
Timer1_Init();
EA = 1;
HC138_Init(0,0x00);
HC138_Init(5,0x00);
HC138_Init(4,0xff);
ds1302_timer_write();
ds18b20_read_begin();
}
//*******************************************
void Timer1_server() interrupt 3
{
systick ++;
data_dly ++;
key_dly ++;
led_display(LED,POS);
smg_display(SMG,DOT,POS);
if(++POS == 8) POS = 0;
if(read_flage == 0)
{
old_num = mode_flage;
read_flage = 1;
}
else
{
if(systick%50 == 0){new_num = mode_flage;}
if(new_num > old_num) {bright_flage=0,old_num=new_num;}
if(new_num < old_num) {bright_flage=1,old_num=new_num;}
}
if(bright_flage == 0)
{
count2 = 0;
count1 ++;
if(count1>3000){LED[2] = 1;count1=0;}
}
if(bright_flage == 1)
{
count1 = 0;
count2 ++;
if(count2>3000){LED[2] = 0;count2=0;}
}
}
第十一届蓝桥杯大赛电子赛国赛代码
于 2024-05-14 08:07:37 首次发布