void buzzer_out(unsigned char times);
void led_change(void);
void function_loop(void);
void key_deal(void);
void scan_key(void);
void out_164(unsigned char in_data,unsigned char channel );
void k_control(unsigned char i);
void pan_test(void);
void error(unsigned char data1);
unsigned char get_AD_result(unsigned char channel);
#define IniT0Count ~3600 /*²úÉú62.5MSËùÐèÒªµÄʱ¼ä´ÎÊý,5ΪÎó²îµ÷Õû*/
sbit k1 =P3^0;
sbit k2 =P3^1;
sbit INT =P3^2;
sbit pan =P3^3;
sbit k =P3^4;
sbit buzzer =P3^5;
sbit pwm =P3^7;
sbit clk1 =P1^7;
sbit dat1 =P1^4;
sbit clk2 =P1^5;
sbit bit_clr =P1^6;
sbit t_m =P1^3;
sbit t_i =P1^2;
sbit v_ad =P1^1;
sbit i_ad =P1^0;
bit yuyue_flag,kaiguan_flag,dingshi_flag;//ÓÃÓÚ±íÃ÷µ±Ç°µÄ״̬
bit key_press;//´ú±íÓа´¼ü°´ÏÂ]
bit flash;//ÊýÂë¹ÜÁÁÃð±ê־λ
bit key_up,key_flag;//´ú±í°´¼üµ¯Æð״̬
bit point;//ÓÃÓÚÊýÂë¹ÜÁ½µãÉÁÃð
unsigned char min,sec,hour,set_min,set_hour;
unsigned char key_num,key_time,buzzer_times;
bit buzzer_flag;
//unsigned int timeup;
unsigned char min_m,sec_m,hour_m,min_old,interval;
unsigned char led_buffer[6]={0};//ÏÔʾ»º´æ
unsigned char code k1_data[8]={0x02,0x01,0x03,0x04,0x07,0x08,0x05,0x06};
unsigned char code k2_data[8]={1,2,9,10,13,14,11,12};
unsigned char key_set,key_set_old;
unsigned char T0Count,T1SCount,count,count1,flash_interval_old,flash_interval;//indivde
unsigned char code select_bit[6]={0x10,0x20,0x40,0x08,0x04,0x80};//ÏÈɨÃèËĸöÊýÂë¹Ü£¬ºóÔÙɨÃèl1~L8,L9-L15;
unsigned char code led_show[11]={0xdd,0x48,0xbc,0x7c,0x69,0x75,0xf5,0x4c,0xfd,0x7d,0xe5};//LEDΪ¹²Òõ¹Ü
unsigned char code l_show_p[6]={0x10,0x90,0xb0,0xb1,0xb3,0xb7};//µ÷½Ú¹¦ÂʵĵÆ
//unsigned char l2_show[8]={0x00,0x80,0x10,0x40,0x01,0x02,0x04,0x08};//±£ÎÂ----1900£¬¿ª¹Ø
//unsigned char code l_show[15]={0x00,0x20,0x00,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x02,0x04,0x08,0x80,0x40};
unsigned int code spower[6]={120,500,800,1300,1600,1900};
unsigned int set_p;//now_p;//ÉèÖù¦ÂÊ£¬µ±Ç°¹¦ÂÊ£¬
unsigned char f1s,f8s,f1s_old,f250ms;
unsigned char code temp_alarm[6]={0,0,0,0,0,0};
unsigned char set_temp_alarm;
unsigned char set_v_alrm;
/*________________kµÄ±äÁ¿______________________*/
unsigned char k_en;
bit k_finish_flag;
unsigned char no_pan;
unsigned char k_loop;
unsigned char k_count1;
unsigned int int1_count=0;//ÓÐÎÞ¹ø²¨ÐεĸöÊý
//unsigned char i_ad_value;
unsigned char count9;
/*___________ADζȵıäÁ¿_____________*/
unsigned char temp,current_i[4],current_v[4];
bit ad_finish_flag,f1s_ad;
unsigned char i_ad_value;
unsigned char v_ad_value;
unsigned char tm_value;
unsigned char ti_value;
/*__________·çÉȱäÁ¿_________*/
unsigned int t2_fan;
unsigned char f60;
/*_____________pwm____________*/
unsigned char pwm_value=0x80;
unsigned char op_set,op_mode,op_time,op_60s,op_count;//¹ý³Ì¿ØÖÆ
unsigned char tm_value_old;
/***************************************************
ÑÓʱ³ÌÐò
********************************************************/
void delay(unsigned int delay_time)
{
unsigned int i = delay_time;
while(i != 0)
{
unsigned char m = 1;
i--;
while(m--);
}
}
/*******************************************************
°´¼üÖµ´¦Àí
********************************************************/
void key_deal(void)
{
if(key_press==1)
{
key_press=0;//È¡Ïû°´¼ü¶¯×÷±ê־λ
if(key_set!=key_set_old || key_set==14 || key_set==3|| key_set==1)//µÈÓÚ¼Ó»òµÈÓÚ¼õ
{
key_set_old=key_set;
function_loop();
}
}
led_change();
// #pragma asm
// jmp $
// #pragma endasm
}
/*******************************************************
Ë¢ÐÂLED»º´æ
********************************************************/
void led_change(void)
{
hour_m=pwm_value;
led_buffer[3]=led_show[hour_m%10];
hour_m=hour_m/10;
led_buffer[2]=led_show[hour_m%10];
hour_m=hour_m/10;
led_buffer[1]=led_show[k_en];
hour_m=hour_m/10;
led_buffer[0]=led_show[no_pan];//led_show[hour_m%10];
/* min_m=no_pan;//count9;
// sec_m=sec;
hour_m=count9;//
led_buffer[1]=led_show[hour_m%10];
hour_m=hour_m/10;
led_buffer[0]=led_show[hour_m%10];
led_buffer[3]=led_show[min_m%10];
min_m=min_m/10;
led_buffer[2]=led_show[min_m%10];
/*/
}
/*******************************************************
¼ì²â°´¼ü³ÌÐò
********************************************************/
void scan_key(void)
{
unsigned char scan_data=0xfe;
unsigned char i;
bit_clr=0;
if(f250ms)
{
for(i=0;i<8;i++)
{
out_164(0x00,2);
out_164(scan_data,1);
scan_data=(scan_data<<1)|(scan_data>>7);//ʵÏÖ×óÒÆһλ
if(!k1)
{
delay(1000);//Ïû¶¶
if(!k1)
{
key_set=k1_data[i];
key_press=1;
key_time=0;
}
}
else if(!k2)
{
delay(1000);
if(!k2)
{
key_set=k2_data[i];
key_press=1;
key_time=0;
}
}
else
key_time++;
}
if(key_time<8){key_num++;}
else {key_num=0;}
key_deal();
f250ms=0;//Ò»ÃëɨÃèËÄ´Î
out_164(0x00,1);
bit_clr=1;
}
}
/*************************************************/
//Ëͳö8λ´®ÐÐÊý¾Ý¸ø164,,channelÊǵç·ÉÏÁ½¸öͨµÀµÄÑ¡Ôñ
/*************************************************/
void out_164(unsigned char in_data,unsigned char channel )//
{
unsigned char i;
if(channel==2)
{
for(i=0;i<8;i++)
{
if (in_data & 0x01)
{
dat1=1;
}
else
{
dat1=0;
}
clk2=0;
in_data>>=1;
clk2=1;
}
dat1=1;
}
if(channel==1)
{
for(i=0;i<8;i++)
{
if (in_data & 0x01)
{
dat1=1;
}
else
{
dat1=0;
}
clk1=0;
in_data>>=1;
clk1=1;
}
dat1=1;
}
}
/*******************************************************
¿ØÖÆÏÔʾ¹¦ÂʵÆ
********************************************************/
void display_p(void)
{
switch(set_p)
{
case 1900:led_buffer[5]=l_show_p[5];break;//ÏÔʾ¹¦ÂʵÆÁÁÎå¸ö
case 1600:led_buffer[5]=l_show_p[4];break;
case 1300:led_buffer[5]=l_show_p[3];break;
case 800:led_buffer[5]=l_show_p[2];break;
case 500:led_buffer[5]=l_show_p[1];break;
default :led_buffer[5]=l_show_p[0];break;//ÁÁ±£ÎµÆ
}
}
/*******************************************************
¿ØÖÆÏÔʾ³ÌÐò
********************************************************/
void display()
{
unsigned char i;
led_change();//Ë¢ÐÂLED»º´æ
display_p();
out_164(0x00,2);//¸´Î»164
out_164(0x00,1);
if(!kaiguan_flag){i=5;}
else {i=0;}
for(;i<6;i++)
{
delay(100);
out_164(0x00,1);
bit_clr=0;
if(i<4)
{
if(!flash)//É趨ʱ¼äÈ·¶¨ºó£¬¿ªÊ¼ÉÁµÄ±ê־λ
{
if(i==1 && point)
{
out_164(led_buffer[i]|0x02,1);
}
else
{
out_164(led_buffer[i],1);
}
}
else
{
if(i==1) {out_164(0x02,1);}
}
}
else
{
if(kaiguan_flag)
{
if(i==5)
{
out_164(led_buffer[i]|0x08,1);//ÏÔʾ·¢¹â¶þ¼«¹Ü,¿ª£¬Ò»Ö±ÁÁ
}
else
{
out_164(led_buffer[i],1);//i=4
}
}
else if(point && i==5) out_164(0x08,1);//¹Ø£¬µ«ÁÁ
else out_164(0x000,1);//¹Ø£¬ÇÒÃð
}
bit_clr=1;
out_164(select_bit[i],2);//ѡλ
delay(600);
//bit_clr=0;
//out_164(0x00,2);
//delay(100);//????????????????????????????????????????????????????????????????????????????
}
}
/**************************************************
¶¨Ê±Æ÷0µÄÖжϷþÎñ£¬256Hz
*************************************************/
void timer0(void) interrupt 1 using 1 /*T0ÖжÏ*/
{
TL0=IniT0Count; /*11.0592M*/
TH0=IniT0Count>>8;
T0Count++;
if(T0Count&0x0f){}//62.5*15 ????????
else
{
//f62_5ms=1;
//**********************¼ì²âÓÐÎÞ¹ø K Âö³å*****************************************
if(k_en)
{
k_count1++;
if(k_count1<=5)//300ms
{
k=1;
}
else if(k_count1<17)//700ms
{
k=0;
}
else
{
k_count1=0;
k_en--;//´ÎÊý
}
if(k_en==0)
{
k_finish_flag=1;
}
}
//********************************************************************************
count++;
if(count==3){ f250ms=1;count=0;}//Ò»ÃëɨÃè°´¼ü´ÎÊý16,8,4
count1++;
if(count1==12){flash_interval++;count1=0;}
if(T0Count==0)
{
f1s++; //led_buffer[5]=~led_buffer[5];//=~buzzer;
T1SCount++;
if(T1SCount==0x20)T1SCount=0;
if(T1SCount&0x07){}
else
{
f8s=1;//²ÉÑù£¬¼ì²âÖÜÆÚ
}
}
}
/***************************ʱ¼äµ¹¼Æʱ,?*******************/
if(f1s!=f1s_old)//µ±ÉÁ±ÏÈ·ÈÏÖ®ºó¼ÆÊý²Å¿ªÊ¼
{
/*________________________·äÃùÆ÷´¦Àí____________________________________*/
if(f1s%2)
{
if(buzzer_times!=0)
{
buzzer_flag=1;
buzzer_times--;
}
else
{
buzzer_flag=0;
}
}
else
{
buzzer_flag=0;
}
/*_______________________________________________________________________*/
sec++;
if(dingshi_flag){sec=0;}//µ±¶¨Ê±±ê־λΪÁãʱ²Å¿ªÊ¼¼ÆÊý
f1s_old=f1s;//¼ì²âÒ»Ãëʱ¼ä
if(f1s%2 && !dingshi_flag) {point=0;}
else {point=1;}//µãÁÁÊýÂëÁ½µã
if(sec==60)
{
sec=0;
if(min==0)
{
if(hour>0)
{
hour--;
min=59;
}
else
{
hour=0;
min=0;
}
}
else
{
min--;
}
}
if(yuyue_flag||dingshi_flag)
{
if(min_old!=min || key_num!=0)
{
min_old=min;
interval=0;//Óа´¼ü¶¯×÷µÄʱºò¾Í²»ÉÁ
}
else
{
if(key_num==0)
{interval++;}//ûÓа´¼ü¶¯×÷µÄʱºò£¬²Å¿ªÊ¼¼ÆÊý
}
}
}
if(flash_interval!=flash_interval_old)//ÉÁµÄʱ¼ä
{
flash_interval_old=flash_interval;
if(interval>=3&&interval<=9)//ÈýÃë¹ýºó£¬¿ªÊ¼ÉÁ,Ê®Ãë¹ýºó£¬Ä¬ÈÏÈ·¶¨
{
flash=~flash;
}
else
{flash=0;}
if(interval>=9)//
{
yuyue_flag=0;
dingshi_flag=0;
interval=0;//¸´Î»
flash=0;
flash_interval=0;
flash_interval_old=0;
}
}
}
/*******************************************************
Ô¤Ô¼³ÌÐò
********************************************************/
void yuyue(void)//Ô¤Ô¼
{
if(key_num<2)
{
yuyue_flag=~yuyue_flag;
//dingshi_flag=0;
}
}
/*******************************************************
¶¨Ê±³ÌÐò
********************************************************/
void dingshi(void)//¶¨Ê±
{
if(key_num<2)
{
dingshi_flag=~dingshi_flag;
set_hour=0;set_min=20;//ʱ¼ä¸´Î»
interval=0;
}
}
/*******************************************************
¿ª¹Ø¿ØÖÆ
********************************************************/
void kaiguan(void)
{
if(key_num<2)
{
kaiguan_flag=~kaiguan_flag;//È¡·´;kaiguan_flag=1;Ôò¿ª»ú״̬
yuyue_flag=0;
dingshi_flag=0;
key_set_old=0;
interval=0;//ÉÁ¼Æʱ¸´Î»
// flash=0;
if(kaiguan_flag)
{
k_control(3);//±ØÐë·¢ËÍÍê±ÏÖ®ºó²ÅÄÜÊÕµ½
}
if(kaiguan_flag)
{
key_set_old=11;//ĬÈÏ»ð¹ø
function_loop();
int1_count=0;//¼ì²âÓÐÎÞ¹øÖжÏÊý
no_pan=0;
k_loop=0;
f60=0;
pwm_value=0x80;//ÓÃÓÚ¼ì²âÓÐÎÞ¹ø
}
if(!kaiguan_flag)//¹Ø»úÖ®ºóµÄ¶¯×÷
{
f60=60;
k=0;
}
//buzzer_out(3);
}
}
/*******************************************************
ÖÇÄܳÌÐò
********************************************************/
void zheneng(void)
{;///////////////////////////////////£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿£¿
}
/*******************************************************
ÉÕË®³ÌÐò
********************************************************/
void saosui(void)//±ØÐèÒª¿¼Âǵ½²»¿ÉÒÔÿ´Î»·Ñ¶¼½øÀ´¡££¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//ÉýÎÂÌ«¿ìÈÏΪ¿ÕÉÕ
{ buzzer_out(1);
//goto error;
}
}
if(op_time>2)
{
if(tm_value>=0x4f)//Ë®ÒÑ·ÐÌÚ
{
op_mode++;
}
};
break;
case 1: if(op_time<=8)//ÉÕË®¹Ì¶¨8·ÖÖÓ,Ë®ÉÕ¿ªºó£¬½µµÍ¹¦ÂÊ£¬Î¬³ÖÒ»¶¨Ê±¼ä·ÐÌÚ
{
set_p=1300;
}
else
{
op_mode++;
}
break;
case 2: buzzer_out(1);//½áÊøÉÕË®£¬½øÈë¹Ø»ú״̬
kaiguan_flag=0;
k=0;
f60=60;
break;
default:;break;
}
}
/*******************************************************
»ð¹ø³ÌÐò
********************************************************/
void huoguo(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
//goto error;
}
}
if(tm_value>=0x56)//Ë®¿ªÊ¼·ÐÌÚ
{
op_mode++;
}
if(tm_value>=0xa3)//ζȹý¸ß
{
buzzer_out(1);
k=0;
//goto error;
}
break;
case 1:if(tm_value>=0x53)
{
k=0;//Í£Ö¹¼ÓÈÈ
}
else if(tm_value<=0x4c)
{
k=1;
}//
default:break;
}
}
/*******************************************************
ìÀÄ̳ÌÐò
********************************************************/
void duinai(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
//goto error;
}
}
if(tm_value<0x42)//1.3//ÏÈÓôó»ðÉÕ·ÐÌÚÈ»ºóÓÃÎÄ»ðÂýÂýìÀ
{
set_p=1300;
}
else
{
op_mode++;
}
break;
case 1: set_p=500;
if(tm_value<0x73)
{
if(k==1 && op_count==10)
{
k=0;
op_count=0;
}
else if(k==0 && op_count==10)
{
k=1;
op_count=0;
}
else
{
k=1;
op_count=0;
}
}
else
{
k=0;
}
break;
default:break;
}
}
/*******************************************************
°ýÌÀ³ÌÐò
********************************************************/
void baotang(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
//goto error
}
}
if(op_time>2 && tm_value<0x38)//Ë®²»·ÐÌÚ,,СÓÚad1.1//ÖлðÉýÎÂ
{
op_mode++;
}
break;
case 1:if(tm_value<0x53)//СÓÚ1¡£64
{
set_p=1300;//ÃÍ»ðÖó·Ð
}
else
{
op_mode++;
op_count=0;
}
break;
case 2:if(tm_value<0x99)//·Àֹˮ¸Éζȹý¸ß
{
set_p=800;
if(k==1 && op_count==12)//ÓÃÎÄ»ðÖó·¹
{
k=0;
op_count=0;
}
else if(k==0 && op_count==8)
{
k=1;
op_count=0;
}
else
{
op_count=0;
k=1;
}
}
else
{
buzzer_out(1);
error(1);
}
break;
default:break;
}
}
/*******************************************************
ÉÕ¿¾³ÌÐò
********************************************************/
void shaokao(void)
{
switch (op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
error(2);
}
}
if(tm_value>=0xa3)//3.2
{
op_mode++;
op_count=0;
}
break;
case 1:if(tm_value>=0xa3)//ά³ÖÓ͵ÄÒ»¶¨Î¶È
{
k=0;
}
else if(tm_value<=0x8E)//µÍÓÚ2.8
{
k=1;
}
break;
default:break;
}
}
/*******************************************************
ÖóÖà³ÌÐò
********************************************************/
void zhuzhou(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì±»ÈÏΪÊÇ¿Õ¹ø
{
buzzer_out(1);
k=0;
//error(2);
}
}
if(op_time>=2)
{
op_mode++;
}
break;
case 1:if(tm_value<0x38)//<1.1
{
set_p=1600;
}
if(tm_value>=0x47)//>1.4
{
set_p=800;
op_mode++;
op_count=0;
}
break;
case 2:if(tm_value<0x73)
{
if(k==1 && op_count==10)
{
k=0;
op_count=0;
}
else if(k==0 && op_count==10)
{
k=1;
op_count=0;
}
else
{
k=1;
op_count=0;
}
}
else//·Àֹζȹý¸ß2¡£2
{
buzzer_out(1);
k=0;
error(1);
}
break;
default:break;
}
}
/*******************************************************
ÕôÖó³ÌÐò
********************************************************/
void zhengzhu(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
error(2);
}
}
if(op_time<=4 && tm_value<0x27)//0.77
{
set_p=1300;
}
else if(op_time<=6 && tm_value<0x51)//1.6
{
set_p=1600;//Óôó»ðÖó¿ªË®
}
else
{
set_p=800;//ÓÃÖлðÂýÂýÕô£¬±£Ö¤ÓÐË®ÆûµÄÊä³ö
}
if(tm_value>=0xad)//3.4ζȹý¸ß
{
buzzer_out(1);
error(1);
}
break;
default:break;
}
}
/*******************************************************
³´²Ë³ÌÐò
********************************************************/
void chaochai(void)
{
switch(op_mode)
{
case 0:if(op_time<=2)
{
if(tm_value-tm_value_old>=0x50)//Éýιý¿ì
{
buzzer_out(1);
error(2);//¿ÕÉÕ´úºÅ
}
}
if(tm_value<0x73 && op_time<=2)//Õâ¸öÁ÷³ÌÓдýÈ·Ôä
{
set_p=800;//ÖлðÉÕÓÍÈȹø
}
else
{
op_mode++;
}
break;
case 1:if(tm_value<=0x5a)//ϲËζÈϽµ
{
set_p=1600;//´ó»ð³´²Ë
}
if(tm_value>=0x80)//2.6ζȹý¸ß
{
k=0;
buzzer_out(1);
error(1);
}
break;
default:break;
}
}
/*******************************************************
°´¼ü¼õ¿ØÖÆ
********************************************************/
/*void jian(void)//¼õ°´¼ü Óп¼Âǵ½Á¬Ðø°´µÄ¹¦ÄÜ????????
{
unsigned char i;
if(!dingshi_flag && key_num<2)
{
for(i=0;i<6;i++)//ÕÒµ½µ±Ç°ÓëÉèÖÃÏàͬµÄ¹¦ÂÊ
{
if(set_p==spower[i])
{
break;
}
}
if(i!=0){set_p=spower[i-1];}//½«µ±Ç°ÍËÒ»¸ñ
}
if(dingshi_flag)
{
if(min>0)
{
if(key_num<8){ min--;}//¶Ì°´Ôò¼õ·Ö
else
{
if(hour>0){hour--;}//³¤°´Ôò¼õʱ£¬Ê±¼õÍê¾Í¼õ·Ö
else
{
if(min>10){min-=10;}
else {min--;}
}
}
}
else if(hour>0)
{
hour--;
min=59;
}
}
}
*/
void jian(void)
{
if(key_num<2)
{
if(pwm_value>0)
{
pwm_value-=1;
}
}
else if(key_num<8)
{
if(pwm_value>5)
{
pwm_value-=5;
}
}
}
/*******************************************************
°´¼ü¼Ó¿ØÖÆ
********************************************************/
void jia(void)//pwmµÄ¼Ó³ÌÐò
{
if(key_num<2)
{
if(pwm_value<255)
{
pwm_value+=1;
}
}
else if(key_num<8)
{
if(pwm_value<250)
{
pwm_value+=5;
}
}
}
/*
void jia(void)
{
unsigned char i;
if( !dingshi_flag&& key_num<2)//ûÓа´¶¨Ê±»òÔ¤Ô¼µÄÇé¿öÏÂÔòµ÷¹¦ÂÊ´óС
{
for(i=0;i<6;i++)
{
if(set_p==spower[i])//ÕÒµ½Ó뵱ǰ¹¦ÂÊÏàͬµÄ´óС
{
break;
}
}
if(i!=5)//·ÀÖ¹Òç³ö
{
set_p=spower[i+1];//¼Ó´ó¹¦ÂÊ
}
}
if((!yuyue_flag) && (dingshi_flag) )//¿ØÖƹ¤×÷ʱ¼ä,×Ϊ3¸öСʱ
{
if(key_num<8){ min++;}
else
{
if(hour<3){hour++;}
}
if(min==60)
{
min=0;
hour++;
}
if(hour==3 && min>0)
{
hour=3;
min=0;
buzzer_out(1);
}
}
if(yuyue_flag && dingshi_flag )//ԤԼʱ¼ä£¬×Ϊ24¸öСʱ
{
if(key_num<8){ min++;}
else
{
if(hour<24){hour++;}
}
if(min==60)
{
min=0;
hour++;
}
if(hour==24 && min>0)//³¬Ôò¸´Î»
{
hour=24;
min=0;
buzzer_out(1);
}
}
}
/******************************************************
¹¦Äܹý³Ì¿ØÖÆ
*******************************************************/
void function(void)
{
if(kaiguan_flag==1 && no_pan==1)
{
switch(op_set)
{
case 2:duinai();
break;
case 9:zheneng();
break;
case 4:zhengzhu();
break;
case 5:chaochai();
break;
case 6:zhuzhou();
break;
case 11:huoguo();
break;
case 7:baotang();
break;
case 13:saosui();
break;
default:huoguo();
break;
}
}
}
void parameter_setup(void)
{
yuyue_flag=0;
dingshi_flag=0;
min=set_min;
hour=set_hour;//Ë͵½ÏÔʾÓ뿪ʼ¼Æʱ
op_set=key_set_old;
op_mode=0;
op_time=0;
op_count=0;
tm_value_old=tm_value;
}
/*******************************************************
°´¼üÑ¡Ôñ¹¦ÄÜ¿ØÖÆ
********************************************************/
void function_loop(void)
{
if(kaiguan_flag==1 || key_set_old==1)//Ö»ÓÐÔÚ¿ª¹Ø´ò¿ªÖ®ºó£¬²ÅÄܽøÐÐÆäËü¹¦ÄܵÄÉèÖÃ
{
switch(key_set_old)
{
case 2://duinai();
set_p=spower[1];
led_buffer[4]=0x40;//l_show[1];//Ñ¡µ½×ó±ß
set_min=20;
set_hour=0;
parameter_setup();
break;
case 1:kaiguan();
min=set_min;
hour=set_hour;//Ë͵½ÏÔʾÓ뿪ʼ¼Æʱ
break;
case 9:zheneng(); //?????????????????
break;
case 4://zhengzhu();
set_p=spower[2];//ÉèÖõŦÂÊ
led_buffer[4]=0x02;//l_show[10];//Ñ¡µ½×ó±ß
set_min=0;//ÉèÖõÄʱ¼ä
set_hour=2;
parameter_setup();
break;
case 5://chaochai();
set_p=spower[4];//ÉèÖÃĬÈϵŦÂÊ
led_buffer[4]=0x20;//l_show[14];//Ñ¡µ½×ó±ß¶ÔÓ¦µÄµÆÁÁ
set_min=0;
set_hour=1;
parameter_setup();
break;
case 6://zhuzhou();
set_p=spower[1];
led_buffer[4]=0x10;//l_show[6];//Ñ¡µ½×ó±ß
set_min=0;
set_hour=2;
parameter_setup();
break;
case 12:yuyue();min=set_min;
hour=set_hour;//Ë͵½ÏÔʾÓ뿪ʼ¼Æʱ
break;
case 8://shaokao();
set_p=spower[3];
led_buffer[4]=0x04;//l_show[11];//Ñ¡µ½×ó±ß
set_min=0;
set_hour=1;
parameter_setup();
break;
case 3:jia();
break;
case 11://huoguo();
set_p=spower[2];
led_buffer[4]=0x01;//l_show[8];//Ñ¡µ½×ó±ß//»ð¹øµÄµÆ
set_hour=2;//ÉèÖÃĬÈÏʱ¼ä
set_min=0;
parameter_setup();
break;
case 10:dingshi();
min=set_min;
hour=set_hour;//Ë͵½ÏÔʾÓ뿪ʼ¼Æʱ
break;
case 14:jian();
break;
case 13://saosui();
set_p=spower[5];
led_buffer[4]=0x80;//l_show[13];//Ñ¡µ½×ó±ß//ÉÕË®µÄµÆÁÁ
set_min=15;
parameter_setup();
break;
case 7://baotang();
set_p=spower[2];
led_buffer[4]=0x08;//l_show[12];//Ñ¡µ½×ó±ß
set_min=0;
set_hour=2;
parameter_setup();
break;
default://huoguo();
set_p=spower[2];
led_buffer[4]=0x01;//l_show[8];//Ñ¡µ½×ó±ß//»ð¹øµÄµÆ
set_hour=2;//ÉèÖÃĬÈÏʱ¼ä
set_min=0;
parameter_setup();
break;//ĬÈÏΪ»ð¹øÉèÖÃ
}
key_set_old=0;
}
}
/*******************************************************
×Ô¼ì³ÌÐò
********************************************************/
void test_self(void)
{
unsigned char i;
unsigned int j=2000;
while(j--)
{
for(i=0;i<6;i++)
{
out_164(select_bit[i],2);
delay(5);
out_164(0xff,1);
}
}
buzzer_out(1);
}
/*******************************************************
·äÃùÆ÷¿ØÖÆ,timesΪ·äÃùÆ÷ÏìµÄ´ÎÊý
********************************************************/
void buzzer_out(unsigned char times)
{
buzzer_times=times;
}
/*******************************************************
¹¤×÷ʱ¼ä½áÊø¿ØÖƳÌÐò
********************************************************/
void time_up()
{
if(!dingshi_flag && !yuyue_flag && kaiguan_flag)//¼Æʱʱ¼äµ½´¦Àí
{
if(!min&&!hour)
{
buzzer_out(1);
kaiguan_flag=0;
f60=60;//ʱ¼äµ½·çÉȼÌÐøת60Ãë
}
}
}
/******************************************************/
//²âÊÔÓÐÎÞ¹ø£¬ÕâÖÖ¼ì²â·½·¨Ê±¼äÌ«³¤ÁË¡£¡£Óдý¸Ä½ø
/*******************************************************/
void test_pan(void)
{
if(k_finish_flag)//Óв¨Ðη¢ËÍ£¬ÇÒ·¢ËÍÍê±Ïºó²ÅÄܽøÈëÕâÒ»¶Î³ÌÐòÖУ¬£¬£¬£¬£¬£¬
{
k_finish_flag=0;
count9=int1_count>>8;//È¡ÖмäÁ½¸öÎȶ¨Öµ
if(count9<=80)//Õý³£Çé¿öÏ£¬ÓÐÎÞ¹ø¶¼²»¿ÉÄÜСÓÚ80,ÈçÈô³öÏÖÕâÖÖÇé¿ö¶ø¼ÌÐøÅжÏ
{
no_pan=4;
if(k_loop>0)
{
k_loop--;
//buzzer_out(1);
}
}
else if(count9<=87)
{
no_pan=1;
k=1;
k_loop=0;
}
else if(count9<=90)
{
no_pan=2;
buzzer_out(1);//ÎÞ¹ø±¨¾¯
}
else
{
no_pan=3;
if(k_loop>0)
{
k_loop--;
buzzer_out(1);
}
}
int1_count=0;//¸´Î»
k_loop++;
/////////////ûÓйøµÄʱºò¾Í¼ÌÐø¼ì²â///////////
if(no_pan!=1 && kaiguan_flag==1)
{
//no_pan=0;//¸´Î»
pwm_value=0x80;
k_control(3);//·¢³öÈý¸ö¸ßµçƽ
}
if (k_loop>=4 && no_pan!=1)//¼ì²éÊ®´Î,Èç¹ûÎÞ¹øÖ»½øÈë¹Ø»ú״̬//´æÔÚÒªÊÇÎó¼ìÊÇ£¬¾Í±»ÎóÅÐΪÓйø??
{
kaiguan_flag=0;//¹Ø»ú
k_loop=0;
}
}
}
/******************************************************
//pan¹Ü½Å·µ»ØÐźÅ:¼ì²âÓÐÎÞ¹ø
/*****************************************************/
void pan_test()
{
}
/******************************************************
//k¹Ü½ÅµÄ¿ØÖÆ
/*******************************************************/
void k_control(unsigned char i)
{
k_en=i;
}
/*************************************************/
/*È¡µÃÒ»¸öͨµÀµÄA/DÖµ
/*************************************************/
unsigned char get_AD_result(unsigned char channel)
{
unsigned char AD_finished = 0; //
ADCV = 0;
ADCTL = channel; //
ADCTL |= 0x80; //start A/D conversion
delay(400); //
ADCTL |= 0x08; //start A/D conversion ??//
AD_finished = 0;
while ( AD_finished == 0 ) //
{
AD_finished = (ADCTL & 0x10); //0001,0000, ADC_FLAG ==1
}
ADCTL &= 0xF7; //1111,0111 ADC_START = 0, ¹Ø A/D
return (ADCV); // ·µ»Ø A/DÖµ
}
/***************************************************************
È¡¶à´ÎµÄζÈֵȻºóƽ¾ùµÃ³öµ±Ç°µÄµçÁ÷£¬µçѹֵ
***************************************************************/
void current_AD(void)
{
unsigned int t;
unsigned char i;
if(f1s_ad==1)
{
f1s_ad=0;
current_i[temp]=get_AD_result(0);
current_v[temp]=get_AD_result(1);
ti_value=get_AD_result(2);
tm_value=get_AD_result(3);
temp++;
if(temp==4) temp=0;
if(temp==3 && k==1)//²ÉÑùËÄ´ÎÍê³Éºó£¬½øÈëƽ¾ù
{
t=0;
for(i=0;i<=3;i++)
{
t+=current_i[i];
}
i_ad_value=t>>2;
///////////////////
t=0;
for(i=0;i<=3;i++)
{
t+=current_v[i];
}
v_ad_value=t>>2;
ad_finish_flag=1;//ad²ÉÑùÍê³É±ê־λ
}
// else if(k==0)
// {
// temp=0;//µ±K²»µÈÓÚ1ʱ£¬Ëù²É¼¯µÄADÎÞЧ
// ad_finish_flag=0;
// }
}
}
/*************************************************************
¹¤×÷¹ý³ÌÖÐͻȻÌá¹ø¡ª¡ª¡ª¡ªADµçÁ÷¼ì²â
**************************************************************/
void just_pan_ad(void)
{
if(no_pan==1 && kaiguan_flag==1)//ÔÚ¹¤×÷µÄÇé¿öÏ¿ªÊ¼²ÉÑù,²»¹ý£¬µ±no_pan ³ö´íµÄʱºî¾ÍÓпÉÄÜ£¬²úÉú£¬no_panÒ»Ö±¸øk_enÖµµÄÇé¿ö
{
current_AD();// AD¿ÉÄܷŵ½Ìõ¼þÍâÃæ¼ì²â»á±È½ÏºÃÒ»µã!!!!
if(ad_finish_flag )
{
ad_finish_flag=0;
if(i_ad_value<=38 && k_en ==0)//¼´Ð¡ÓÚ0.6VʱÎÞ¹ø31?????????????????????????????????
{
pwm_value=0x80;//Ôڴ˹¦ÂÊÉϸüÒ×ÓÚ¼ì²â
k_control(3);//k_finish_flag=1;//ʹÆäÖØнøÈëKÊä³ö¸ßµçƽ¼ì²â״̬
}
/* if(ti_value>=0x33)//µ±ÆäζÈADÖµ¸ßÓÚ78¶ÈµÄʱºò£¬¾Í±¨¾¯½øÈë´ý»ú״̬
{
k=0;
buzzer_out(1);
f60=60;
}
if(ti_value>=0x56)//IGBTζȳ¬¹ý120
{
k=0;
buzzer_out(100);//Ãù·äÆ÷³¤Ãù
error(4);
} */
}
}
else
{
f1s_ad=0;//²»²ÉÑù
}
}
/*******************************************************
PWM-IGBT¹¤×÷¿ØÖƳÌÐò
********************************************************/
void pwm_change(void)
{
if(no_pan==1 && i_ad_value>38)
{
switch(set_p)
{
case 120:pwm_value=50;//±£ÎÂ
// set_temp_alarm=temp_alarm[0];
break;
case 500:pwm_value=77;
// set_temp_alarm=temp_alarm[1];
break;
case 800:pwm_value=115;
// set_temp_alarm=temp_alarm[2];
break;
case 1300:pwm_value=156;
// set_temp_alarm=temp_alarm[3];
break;
case 1600:pwm_value=178;
// set_temp_alarm=temp_alarm[4];
break;
case 1900:pwm_value=196;
// set_temp_alarm=temp_alarm[5];
break;
default:pwm_value=128;
// set_temp_alarm=temp_alarm[0];//Õâ¸ö¿ÉÒÔµ±×÷¿ª»úµÄζÈÉ趨ֵ
break;
}
}
// CL=pwm_value;
// CH=pwm_value;
CCAP0L=255-pwm_value;
CCAP0H=255-pwm_value;
}
/*******************************************************
Ìá¹ø¼ìÑé
********************************************************/
/*void interrupt_0(void) interrupt 0 using 2 //INT½Å
//{
// EX0=0;//½ûµôÖжϣ¬²»»áÒ»Ö±½øÈ룬±ÜÃâ³öÏÖËÀ»úµÄ¼ÙÏñ
//int1_count++;
kaiguan_flag=0;
buzzer_out(3);
//} */
void time1(void) interrupt 3 using 3//256u ÖжÏÒ»´Î£¬Ò»¸ö·äÃùÆ÷¸ÕºÃ2KHz
{
t2_fan++;
if(t2_fan==1400 || t2_fan== 5)//Ò»Ãë²ÉÑùÁ½´Î
{
f1s_ad=1;//°ëÃëAD²ÉÑù
}
if(t2_fan>=3900)//Ò»Ãë½øÈëÒ»´Î
{
t2_fan=0;
if(f60>0) { f60--;}
op_count++;//¼ÆÊý¼Ó1
op_60s++;
if(op_60s==60)
{
op_60s=0;
op_time++;
}
}
if(buzzer_flag)
{
buzzer=~buzzer;
}
else
{ if(kaiguan_flag && !yuyue_flag)
{
buzzer=1;
}
else if(!kaiguan_flag && f60 )
{
buzzer=1;//¹Ø»úºó60ÃëÄÚ¶¼Òª¿ª·çÉÈ
}
else
{
buzzer=0;//°´ÏÂÔ¤Ô¼ºó£¬FAN²»×ª,µ«ÊÇÔ¤Ô¼±ê־λ¸´Î»Ö®ºóÄØ£¿·çÉÈÓÖÒª¿ªÊ¼×ªÁË?????????
}
}
}
void error(unsigned char data1)
{
while(kaiguan_flag)//³ö´í£¬µÈ´ýÖØÆô
{
k=0;
// min=0;
// hour=0;
led_buffer[4]=0x00;
led_buffer[5]=0x00;
led_buffer[2]=led_show[data1];
led_buffer[1]=led_show[10];
display();
}
}
/**********************************************************
pan½ÅµÄ²¨ÐÎÂö³å¼ì²â
***********************************************************/
void int_1(void) interrupt 2 using 2//pan½Å
{
int1_count++;
}
/*******************************************************
ϵͳ³õʼ»¯
********************************************************/
void System_Init()
{
TMOD=0x20;//16λ¶¨Ê±Æ÷//
TL1=0x00;
TH1=0x00;
TR1=1;//¿ªÊ¼¼ÆÊý
ET1=1;//¿ªÆôÖжÏ
TCON|=0X04;//ÍⲿÖжÏ1ÒÔÉÏÉýÑØ´¥·¢
CMOD=0x02;
CL=0;
CH=0;
CCAP0L=0X00;
CCAP0H=0X00;
CCAPM0=0X42;
CCON=0X40;
P1M0 = 0x0f; //P1.(0-3) set input (high-inpedance)
P1M1 = 0xf0; //P1.(4-7) set output (pull high)
P1 = 0x00; //
P3M0 = 0x0f; //P3.(0-3) set input (high-inpedance)
P3M1 = 0xf0; //P3.(4-7) set output (pull high)
P3 = 0x00; //
TMOD|=0x01; /*16λ¶¨Ê±Æ÷*/
TH0=IniT0Count>>8;
TL0=IniT0Count+1;/*11.0582M*/
TR0=1;
ET0=1;
// EX0=1;
EX1=1;// ÖжÏ1
EA=1;
i_ad=0;
v_ad=0;
}
/*******************************************************
Ö÷³ÌÐò
********************************************************/
void main()
{
System_Init();
bit_clr=1;
test_self();
while(1)
{
scan_key();
display();
time_up();
//no_pan=1;
test_pan();//¼ì²éÓÐÎÞ¹ø
//i_ad_value=102;
//ad_finish_flag=1;
just_pan_ad();
pwm_change();
function();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น