?? pump_watch.c
字號(hào):
comm_out_buf[k+5]=*(point+i*4+k);
comm_out_buf[3]= dt;
comm_out_buf[4]= i*4;
}
comm_out_buf[0]=0xff;
comm_out_buf[9]=comm_out_buf[0]|comm_out_buf[1]|comm_out_buf[2]|comm_out_buf[3]|comm_out_buf[4]|comm_out_buf[5]|comm_out_buf[6]|comm_out_buf[7]|comm_out_buf[8];
comm_send(10,comm_out_buf);
}
}
//系統(tǒng)初始化任務(wù) 初始化操作系統(tǒng)*************************************************
//******************************************************************************
void ini (void) _task_ INT{
init(); init1(); //初始化
os_create_task (MAIN); //按鍵任務(wù)
os_create_task (AD_CNV); //報(bào)警讀入
os_create_task (DISPLAY); //動(dòng)態(tài)顯示
os_create_task (ALARM); //報(bào)警輸出
os_create_task (serialer); //串行通訊
os_delete_task (INT);
}
//*******************************************************************************
//*******************************************************************************
//第一個(gè)任務(wù)*********************************************************************
//按鍵處理***********************************************************************
void ssc (void) _task_ MAIN{
uchar k ;
uchar count;
while(1){
if (match_number==0){ //0號(hào)機(jī)才可執(zhí)行讀取鍵值
key_read();
} //讀取按鍵狀態(tài)
if (key_buf==MUTE){ //如果是消音鍵
for (k=0;k<4;k++){MUTE_out[k]=alarm_data[k];} //消音處理
// os_wait(K_TMO,2,0);
FMQ=0;mu=1;//key_buf=0; //
if (power_fault){lpmute_f=1;} }
//消音鍵處理結(jié)束
if (key_buf==RESET){ //如果是復(fù)位鍵
init();
os_create_task (ALARM);
os_create_task (AD_CNV);
set =0;YS=0 ;FMQ=0;
} //復(fù)位鍵處理結(jié)束
if (key_buf==TEST){ //如果是按下了試燈鍵
os_delete_task (ALARM); //不允許報(bào)警輸出
for (k=0;k<4;k++){
dis_buf[k]=0xff; //點(diǎn)亮所有報(bào)警燈
}
FMQ = 1;YS=1; //使蜂鳴器發(fā)聲音,繼電器輸出
}
if (key_buf==SET_DAT){ //進(jìn)入設(shè)置狀態(tài)
os_delete_task (AD_CNV);
os_delete_task (ALARM);
}
for (count=0;count<4;count++){
if (MUTE_out[count]>alarm_data[count]){ //實(shí)現(xiàn)報(bào)警自動(dòng)恢復(fù)
MUTE_out[count]= alarm_data[count];
}
MUTE_out[count]= (alarm_data[count]&alarm_out_slect[count])|MUTE_out[count];//實(shí)現(xiàn)報(bào)警只顯示
// else {Alarm=match_number+1;mu=0;} //如果有新報(bào)警則置報(bào)警位同時(shí)清除消音標(biāo)志位
} //
if (MUTE_out[0]>=alarm_data[0] && MUTE_out[1]>=alarm_data[1]&&MUTE_out[2]>=alarm_data[2]&&MUTE_out[3]>=alarm_data[3]){
Alarm[match_number]=0; }
else {Alarm[match_number]=1;mu=0;} //新報(bào)警判斷
os_wait(K_TMO,2,0);
}
}
//******************************************************************************
//******************************************************************************
//第二個(gè)任務(wù)********************************************************************
//報(bào)警輸出任務(wù)******************************************************************
void BEEP (void) _task_ ALARM{
while(1){
alarm_out(); //調(diào)用報(bào)警輸出函數(shù)
//printf("%s\n",alarm_data);
os_wait(K_TMO,2,0);
}
}
//******************************************************************************
//******************************************************************************
//第三個(gè)任務(wù) 報(bào)警讀入任務(wù)
void AD_CN (void) _task_ AD_CNV{
while(1){
alarm_in(); //調(diào)用報(bào)警讀入函數(shù)
delay_alarm() ; //調(diào)用延時(shí)報(bào)警函數(shù)
os_wait(K_TMO,2,0);
}
}
//**********************************************************
//**********************************************************
////////////////////////動(dòng)態(tài)掃描顯示任務(wù)///////////////////////////////////
void disp (void) _task_ DISPLAY{
//掃描行
char i ;
while(1){
line=0xfe; //掃描行初值
for (i=4;i>0;i--){
XBYTE[0XA000]=line&COMM; //掃描行值輸出
if (!set) //非設(shè)置狀態(tài),輸出報(bào)警數(shù)據(jù)
XBYTE[0xc000]=~dis_buf[i-1]; //掃描列輸入顯示值
else XBYTE[0xc000]=0xfe; //設(shè)置狀態(tài),則亮指定的標(biāo)志燈
os_wait(K_TMO,5,0); //延時(shí)增加亮度
line=(line<<1)+1; //掃描行換行
XBYTE[0xc000]=0xff; //全滅
}
//os_wait(K_TMO,1,0);
}
} //任務(wù)結(jié)束
///////////////////////////////////////////////////////////////////////////
///串口發(fā)送及接收處理任務(wù)
void comm_out (void) _task_ serialer{
unsigned char temp, num;
while(1){
serial_cl(); //串口處理
comm_out_buf[0]=0xff; //存入幀起始
comm_out_buf[3]=key_buf; //將主機(jī)按鍵狀態(tài)存入緩存
comm_out_buf[1]=match_number; //存入本機(jī)號(hào)碼
comm_out_buf[4]=Alarm[match_number]; //存入報(bào)警狀態(tài)
comm_out_buf[5]=alarm_data[0]; //報(bào)警數(shù)據(jù)0
comm_out_buf[6]=alarm_data[1]; //報(bào)警數(shù)據(jù)1
comm_out_buf[7]=alarm_data[2]; //報(bào)警數(shù)據(jù)2
comm_out_buf[8]=alarm_data[3]; //報(bào)警數(shù)據(jù)3
if (!set){ //非設(shè)置狀態(tài)下
if (match_number==0){ //如果是主控板
if (power_up==1)os_wait(K_TMO,30,0);
power_up=0;
for (num=1;num<=8;num++){ //循環(huán)發(fā)送7個(gè)分機(jī)號(hào)和復(fù)示器號(hào)(8號(hào))
comm_out_buf[2]=num; //存入目標(biāo)機(jī)機(jī)號(hào)
//comm_send_over=0; //清除接收完畢信號(hào)
comm_out_buf[9]=comm_out_buf[0]^comm_out_buf[1]^comm_out_buf[2]^comm_out_buf[3]^comm_out_buf[4]^comm_out_buf[5]^comm_out_buf[6]^comm_out_buf[7]^comm_out_buf[8];
comm_send(10,comm_out_buf); //發(fā)送數(shù)據(jù)
if (key_buf==SET_DAT){ set =1;
comm_out_buf[3]=key_buf;
comm_send(10,comm_out_buf);
}
if (cnt++ >10)cnt=0;key_buf=0; //保證每次鍵值輪發(fā)后才清除
comm_send_over=1; //置發(fā)送完畢位
for (temp=30;temp>0;temp--){ //延時(shí)等待分機(jī)回應(yīng)
os_wait(K_TMO,3,0); } //延時(shí)
serial_cl(); //接受處理
}
os_wait(K_TMO,5,0);
}
if (match_number>0&&match_number<=7){ //如果是其它檢測(cè)板(不包括復(fù)示器)
comm_out_buf[0]=0xff;
comm_out_buf[1]=match_number;
comm_out_buf[2] = 0; //數(shù)據(jù)的發(fā)送對(duì)象是主控板
if (SEND){ //如果可以發(fā)送數(shù)據(jù)
os_wait(K_TMO,1,0); //延時(shí)等待穩(wěn)定
if (key_buf==SET_DAT) set =1;
comm_out_buf[4]=Alarm[match_number]; //存入報(bào)警狀態(tài)
comm_out_buf[9]=comm_out_buf[0]^comm_out_buf[1]^comm_out_buf[2]^comm_out_buf[3]^comm_out_buf[4]^comm_out_buf[5]^comm_out_buf[6]^comm_out_buf[7]^comm_out_buf[8];
comm_send(10,comm_out_buf); //發(fā)送數(shù)據(jù)
SEND =0; //發(fā)送完畢
}
// os_wait(K_TMO,10,0);
serial_cl(); } //進(jìn)行串口接收后的處理
}
else{ //設(shè)置狀態(tài)下
serial_cl();
if (SEND){
comm_out_buf[0] = 255;
comm_out_buf[1] = match_number;
comm_out_buf[2] = 9; //數(shù)據(jù)的發(fā)送對(duì)象是PC機(jī)
os_wait(K_TMO,200,0);
os_wait(K_TMO,200,0);
for (temp=0;temp<4;temp++){
comm_out_buf[temp+5]=slect_no_nc[temp]; //存入要回應(yīng)的輸入方式數(shù)據(jù)
}
comm_out_buf[3]=1;
comm_out_buf[4]=0;
comm_out_buf[9]=comm_out_buf[0]^comm_out_buf[1]^comm_out_buf[2]^comm_out_buf[3]^comm_out_buf[4]^comm_out_buf[5]^comm_out_buf[6]^comm_out_buf[7]^comm_out_buf[8];
comm_send(10,comm_out_buf); //發(fā)送數(shù)據(jù)
for (temp=0;temp<4;temp++){
comm_out_buf[temp+5]=alarm_out_slect[temp];//存入要回應(yīng)的報(bào)警鎖存數(shù)據(jù)
}
comm_out_buf[3]=2;
comm_out_buf[4]=0;
comm_out_buf[9]=comm_out_buf[0]^comm_out_buf[1]^comm_out_buf[2]^comm_out_buf[3]^comm_out_buf[4]^comm_out_buf[5]^comm_out_buf[6]^comm_out_buf[7]^comm_out_buf[8];
comm_send(10,comm_out_buf); //發(fā)送數(shù)據(jù)
for (temp=0;temp<4;temp++){
comm_out_buf[temp+5]=alarm_cou[temp]; //存入要回應(yīng)的報(bào)警鎖存數(shù)據(jù)
}
comm_out_buf[3]=3;
comm_out_buf[4]=0;
comm_out_buf[9]=comm_out_buf[0]^comm_out_buf[1]^comm_out_buf[2]^comm_out_buf[3]^comm_out_buf[4]^comm_out_buf[5]^comm_out_buf[6]^comm_out_buf[7]^comm_out_buf[8];
comm_send(10,comm_out_buf); //發(fā)送數(shù)據(jù)
RE32 (&delay_time[0],4 ) ;
SEND = 0;
comm_in_buf[3]=0;
}}
os_wait(K_TMO,2,0);}
}
////////外部信號(hào)讀入函數(shù)///////////////////////////////////////////////////
////輸入:無
////輸出:外部輸入狀態(tài)存于in_buf[]中,共四個(gè)字節(jié)
void alarm_in(void){
unsigned char temp1;
unsigned int temp2; //定義臨時(shí)變量
temp2=0x2000; //輸入首地址
for (temp1=0;temp1<4;temp1++){
in_buf[temp1]=XBYTE[temp2]; //讀入外部狀態(tài)
// dis_buf[temp1]=XBYTE[temp2]; //調(diào)試程序時(shí)使用直接存入顯示緩存
temp2 =temp2+0x2000; //地址偏移
} } //函數(shù)結(jié)速
///////////////////////////////////////////////////////////////////////////
/////////報(bào)警延時(shí)判斷函數(shù)//////////////////////////////////////////////////
////輸入:in_buf[]中的數(shù)據(jù)
////輸出:存入alarm_data[]中
void delay_alarm(void){
unsigned char temp1,temp2;
unsigned long temp4=0;
unsigned long temp5=0;
unsigned long temp6=0;
for (temp1=0;temp1<4;temp1++){ //共32路,4字節(jié)
temp4=temp4|(in_buf[temp1]&0xff); //將32路的數(shù)據(jù)存到一個(gè)長整型變量中
temp5=temp5|(slect_no_nc[temp1]&0xff);
if(temp1<3){ temp4=temp4<<8;temp5=temp5<<8;}
}
temp4=(~temp4)^temp5; //處理常開常閉輸入
os_wait(K_TMO,2,0);
temp5=1;
temp2=0;
for (temp1=0;temp1<32;temp1++){
temp6=temp4&temp5; //判斷第temp1路有沒有報(bào)警
os_wait(K_TMO,2,0);
if (temp6!=0){ //不為0則有報(bào)警發(fā)生
if (alarm_delay[temp1]>0){
alarm_delay[temp1]--;
}
else{ if(temp1<=7)
alarm_data[0]= alarm_data[0]&0xff|(temp6&0xff);
if(temp1>=8&&temp1<=15)
alarm_data[1]=alarm_data[1]| ((temp6>>8)&0xff);
if(temp1>=16&&temp1<=23)
alarm_data[2]=alarm_data[2]| ((temp6>>16)&0xff);
if(temp1>=24&&temp1<=31)
alarm_data[3]=alarm_data[3]| ((temp6>>24)&0xff);
alarm_delay[temp2]=delay_time[temp2]; //如果該路延時(shí)時(shí)間到則恢復(fù)初值
}
}
else { if(temp1<=7)
alarm_data[0]=alarm_data[0] ^ (alarm_cou[0]&(temp5&0xff))&alarm_data[0];
if(temp1>=8&&temp1<=15)
alarm_data[1]=alarm_data[1] ^ (alarm_cou[1]&((temp5>>8)&0xff)) &alarm_data[1];
if(temp1>=16&&temp1<=23)
alarm_data[2]=alarm_data[2] ^ (alarm_cou[2]&((temp5>>16)&0xff))&alarm_data[2];
if(temp1>=24&&temp1<=31)
alarm_data[3]=alarm_data[3] ^ (alarm_cou[3]&((temp5>>24)&0xff))&alarm_data[3];
alarm_delay[temp2]=delay_time[temp2]; //如果該路沒有報(bào)警則重新設(shè)定該路的定時(shí)初值
}
temp5<<=1;
temp2++; //當(dāng)前路數(shù)加一(0—31路)
os_wait(K_TMO,5,0);
}
os_wait(K_TMO,200,0); //設(shè)定每次檢測(cè)的時(shí)間
//os_wait(K_TMO,255,0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -