?? lna3.c
字號:
{
buf=Query_csd(1,tn);
}
else if (receive_buf[8]==0x04)//查詢所有頻補參數編碼
{
buf=Query_csd(2,pn);
}
else if (receive_buf[8]==0x05)//查詢所有標稱值參數編碼
{
buf=Query_csd(3,zyn);
}
else if (receive_buf[8]==0x06)//查詢所有溫補參數表內容
{
buf=Query_cszd(tempcszd,tn);
}
else if (receive_buf[8]==0x07)//查詢所有頻補參數表內容
{
buf=Query_cszd(freqcszd,pn);
}
else if (receive_buf[8]==0x08)//查詢所有標稱值參數表內容
{
buf=Query_cszd(bczcszd,zyn);
}
send_reply_flag(0x00,buf);
goto go_return;
}
else if(receive_buf[5]==0xd2)//設置表格參數
{
if (receive_buf[8]==0x01)//設置所有溫度值
{
buf=Set_tp(tempd);
}
else if (receive_buf[8]==0x02)//設置所有頻率值
{
buf=Set_tp(freqd);
}
else if (receive_buf[8]==0x06)//設置所有溫補參數表內容
{
buf =Set_cszd(tempcszd,tn);
}
else if (receive_buf[8]==0x07)//設置所有頻補參數表內容
{
buf =Set_cszd(freqcszd,pn);
}
else if (receive_buf[8]==0x08)//設置所有標稱值參數表內容
{
buf =Set_cszd(bczcszd,zyn);
}
send_reply_flag(0x00,buf);
goto go_return;
}
else
{
send_reply_flag(0x09,0x00); //命令編號錯
goto go_return;
}
}
else if(receive_over == 0 && receive_time_on == 1)
{
if(receive_time_count >= 200)
{
headend_flag=0x00;
tran_flag=0x00;//轉義標志,=0為沒有轉義,=1為轉義過了
receive_time_on = 0;
receive_time_count = 0;
receive_free();
receive_cnt = 0x00;
CREN = 1;
RCIE = 1;
return;
}
else
{
receive_time_count++;
return;
}
}
// T1CON=0x31;
return;
go_return:
headend_flag=0x00;
tran_flag=0x00;//轉義標志,=0為沒有轉義,=1為轉義過了
receive_free();
receive_over = 0;
receive_cnt = 0;
CREN = 1;
RCIE = 1;
// T1CON=0x31;
return;
}
/**********************************************************
** 功能說明: 基本數據查詢函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
*********************************************************/
uchar Query_Basic_Parameter()
{
uchar buf;
uchar i ;
uint j ;
j = 0x0700;
buf=receive_buf[8];//BUF為上位機下傳的第幾包數據;命令體的第1個字節為我應傳給上位機第幾包數據
receive_buf[8]=2;//PIC需上傳總包數為2包;所以命令體的第1個字節變成了總包數.
if(buf==1)
{
receive_buf[9]=1;//表示PIC發送第1包數據
for(i=0; i<44; i++)
{
receive_buf[i+10] = basic_table[i];
}
return 46;
}
else if(buf==2)//
{
receive_buf[9]=2;//表示PIC發送第2包數據
for(i=0; i<37; i++)
{
receive_buf[i+10] = rrom(j + i);
}
return 39;
}
else
{
return 0;
}
}
/**********************************************************
** 功能說明: 基本信息參數設置函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
*********************************************************/
uchar Set_Basic_Parameter()
{
auto union buf_union comm;
uint i;
uchar length;
uchar buf;
uchar *P = 0;
length = receive_buf[7];
P = receive_buf+8;
erro = 0;
while(length)
{
comm.buf2[0] = *P++;
comm.buf2[1] = *P++;
length = length - 2 ;
switch(comm.buf1)
{
case 0xf000: //模塊ID號
for(i=0;i<10;i++)
{
buf=*P++;
// dog();
wrom(mod_idadd+2+i,buf);
}
length=length-10;
break;
case 0xf002: Prmter1.ADDR=*P++ ;//模塊地址
wrom(mod_add_add+2,Prmter1.ADDR);
length--;
break;
case 0xf019: //生產序列號
for(i=0;i<20;i++)
{
buf=*P++;
// dog();
wrom(product_add+2+i,buf);
}
length=length-20;
break;
default: receive_buf[9] = *--P;
receive_buf[8] = *--P;
erro = erro | 0x02;
length = 0;
break;//特殊處理
}
}
if(erro & 0x02)
{
length = 2;//設置參數失敗
}
else
{
length = receive_buf[7];
}
return length;
}
/**********************************************************
** 功能說明: 參數地址查詢函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
*********************************************************/
uchar Query_Address()
{
uchar i,buf;
uchar length;
buf = receive_buf[8];
switch(buf)
{
case 1: for(i=0; i<Para_Num; i++)
{
receive_buf[i+8]= Para_Num_Conf[i];
length = Para_Num;
}
break;
default: receive_buf[8] = buf;
length = 1;
break;
}
return length;
}
/**********************************************************
** 功能說明: 增益實際值補償函數(校準值)
** 輸入參數: attin 類型:uchar :標稱值
attnb 類型:uchar :=1,代表第1個增益,=2,代表第2個增益等
** 輸出參數:
** 返 回 值: 無
** 引用函數:
*********************************************************/
uchar ATTBU(char attin,uchar attnb)
{
uchar i;
uchar buf;
//buf=attin;//如果比較沒有結果,則返回標稱值原值
buf=0;//如果比較沒有結果,則返回0
for (i=0;i<bcnumb;i++)
{
B[0]=rrom(bczcszd+zyn*i+attnb-1);//參數值首地址+偏置
if (attin==i)
{
//buf=B[0]+buf4;
buf=B[0];
break;
}
}
B[0]=0;
return buf;
}
/**********************************************************
** 功能說明: 頻響實際值補償函數(其實是增益補償)DB/2
關于頻率值計算,設信道號為X,頻點寬為100K,二分頻,則頻率值=信道0時頻率值+信道×0.025
** 輸入參數: freqin 類型:uchar :信道值
freqnb 類型:uchar :代表第幾個本振器件。
** 輸出參數:
** 返 回 值: 頻響補償實際值 buf,如果返回值為0,則為沒有補償值
** 引用函數:
*********************************************************/
uchar FREQBU(uchar freqin,uchar freqnb)
{
uchar i;
uchar buf;
uchar P[2];//EEPROM中信道值1byte
buf=0;//如果比較沒有結果,則返回0
for (i=0;i<fnumb;i++)//頻率
{
P[0]=rrom(freqd+i);
if (i<(fnumb-1))
{
P[1]=rrom(freqd+i+1);
}
else
{
P[1]=P[0];
}
if (freqin==P[0])
{
B[0]=rrom(freqcszd+pn*i+freqnb-1);
buf=B[0];
break;
}
else if((freqin>P[0])&&(freqin<P[1]))
{
B[0]=rrom(freqcszd+pn*i+freqnb-1);
B[1]=rrom(freqcszd+pn*(i+1)+freqnb-1);
if (B[1]>B[0])
{
B[2]=B[0]+(((B[1]-B[0])*(freqin-P[0]))/(P[1]-P[0]));
}
else
{
B[2]=B[0]-(((B[0]-B[1])*(freqin-P[0]))/(P[1]-P[0]));
}
buf=B[2];
break;
}
}
return buf;
}
/**********************************************************
** 功能說明: 溫度補償函數(溫補參數占1個字節,補償電壓為mV單位,增益為DB/2單位等)
** 輸入參數: // buf3 類型:uchar :buf3=1,表示溫補參數占1個字節;buf3=2,表示溫補參數占2個字節
tempnb 類型:uchar :在溫補表中是第幾個參數,=1,是第1個參數;=2,第2個參數
// buf7 類型:uchar :在tn中參數是第幾個字節開始的參數
// buff: 類型:uchar :=0:溫度補償函數是△值,=1:溫度補償函數是實際值
** 輸出參數:
** 返 回 值: 無
** 引用函數:
*********************************************************/
uchar TEMP(uchar tempnb)
{
uchar i;
uchar buf;
char T[2];//EEPROM?D???è?μ
uchar buff;
uchar buf1;
uchar buf2;
uchar buf3;
buf=0;//è?1?±è????óD?á1?£??ò·μ??0
buf3=0;
for (i=0;i<tpnumb;i++)
{
dog();
T[0]=rrom(tempd+i);
if(i<tpnumb-1)
{
T[1]=rrom(tempd+i+1);
}
else
{
T[1]=T[0];
}
if (Prmter1.TEMP==T[0])
{
B[0]=rrom(tempcszd+tn*i+tempnb-1);
buf=B[0];
break;
}
if ((Prmter1.TEMP>T[0])&&(Prmter1.TEMP<T[1]))
{
buf3=1;
}
if ((Prmter1.TEMP>T[0])&&(Prmter1.TEMP>T[1])&&(T[1]<0x80)&&(T[0]>0x80))
{
buf3=1;
}
if(buf3==1)
{
B[0]=rrom(tempcszd+tn*i+tempnb-1);
B[1]=rrom(tempcszd+tn*(i+1)+tempnb-1);
buff=B[1]-B[0];
if (buff<0x80)
{
buf1=(Prmter1.TEMP-T[0]);
buf2=T[1]-T[0];
buf1=(B[1]-B[0])*buf1;
buf1=buf1/buf2;
buf1=buf1;
B[2]=B[0]+buf1;
}
else
{
buf1=(Prmter1.TEMP-T[0]);
buf2=T[1]-T[0];
buf1=(B[0]-B[1])*buf1;
buf1=buf1/buf2;
buf1=buf1;
B[2]=B[0]-buf1;
}
buf=B[2];
break;
}
}
return buf;
}
/**********************************************************
** 功能說明: 增益校準函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
*********************************************************/
void gcu_jz()
{
char GCU1JZ;//增益1的溫補
char GCU2JZ;//增益2的溫補
char GCU1ACT;//增益1的標稱值補償
char GCU2ACT;//增益2的標稱值補償
GCU1JZ=TEMP(1);//增益1的溫度補償(校準值)
GCU2JZ=TEMP(2);//增益2的溫度補償(校準值)
GCU1ACT=ATTBU(Prmter1.GCU1,1);//增益1的標稱值補償(校準值)
GCU2ACT=ATTBU(Prmter1.GCU2,2);//增益2的標稱值補償(校準值)
GCU1JZ=GCU1JZ+GCU1ACT;//增益1的溫補+標稱值補償
GCU2JZ=GCU2JZ+GCU2ACT;//增益1的溫補+標稱值補償
//if (GCU1JZ<0)
//{
// GCU1JZ=0;
//}
//if (GCU2JZ>=0x80)
//{
// GCU2JZ=0;
//}
sumgcu=Prmter1.GCU1+Prmter1.GCU2;
if (sumgcu<=10)
{
gcu_ctl(0x00,(sumgcu+GCU1JZ));
gcu_ctl(0x01,GCU2JZ);
}
else if ((sumgcu>10) &&(sumgcu<=20))
{
gcu_ctl(0x00,(10+GCU1JZ));
gcu_ctl(0x01,(sumgcu-10+GCU2JZ));
}
else if ((sumgcu>20) &&(sumgcu<=25 ))
{
gcu_ctl(0x00,(sumgcu-10+GCU1JZ));
gcu_ctl(0x01,(10+GCU2JZ));
}
else if(sumgcu>25)
{
gcu_ctl(0x00,(15+GCU1JZ));
gcu_ctl(0x01,(sumgcu-15+GCU2JZ));
}
}
/**********************************************************
** 功能說明: 參數設置函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
**********************************************************/
uchar Set_Parameter()
{
auto union buf_union comm;
uchar length;
uchar *P = 0;
// uchar buff;
uchar buf;
// erro=0;
length = receive_buf[7];
P = receive_buf+8;
while(length)
{
comm.buf2[0] = *P++;
comm.buf2[1] = *P++;
length = length - 2 ;
switch(comm.buf1)
{
case maxpwr: Prmter1.max = *P++;
wrom(maxpwradd,Prmter1.max);
buf=Prmter1.max+Prmter1.POFFSET2;
if(buf>=0x80)
{
buf=256-buf;
Prmter1.maxu =250-buf * 5;
}
else if(buf<0x80)
{
Prmter1.maxu =buf * 5+250;
}
// buff=rrom(maxpwradd);
// if(buff!=Prmter1.max)
// {
// wrom(maxpwradd,Prmter1.max);
// }
length--;
wrom(maxpuadd,Prmter1.maxu);
DAC(1,Prmter1.maxu);
break;
case maxpu: Prmter1.maxu = *P++;
wrom(maxpuadd,Prmter1.maxu);
// buff=rrom(maxpuadd);
// if(buff!=Prmter1.maxu)
// {
// wrom(maxpuadd,Prmter1.maxu);
// }
P++;
length=length-2;
DAC(1,Prmter1.maxu);
Prmter1.max =Prmter1.maxu/5-50-Prmter1.POFFSET2;
wrom(maxpwradd,Prmter1.max);
break;
case gcu1: Prmter1.GCU1 = *P++;
wrom(gcu1add,Prmter1.GCU1);
// buff=rrom(gcu1add);
// if(buff!=Prmter1.GCU1)
// {
// wrom(gcu1add,Prmter1.GCU1);
// }
length--;
gcu_jz();
break;
case gcu2: Prmter1.GCU2 = *P++;
wrom(gcu2add,Prmter1.GCU2);
// buff=rrom(gcu2add);
// if(buff!=Prmter1.GCU2)
// {
// wrom(gcu2add,Prmter1.GCU2);
// }
length--;
gcu_jz();
break;
case poffset1: Prmter1.POFFSET1=*P++ ;
wrom(poff1add,Prmter1.POFFSET1);
// buff=rrom(poff1add);
// if(buff!=Prmter1.POFFSET1)
// {
// wrom(poff1add,Prmter1.POFFSET1);
// }
length--;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -