?? g1.c
字號:
PLL_count11=0;
PLL_count12++;
}
if (PLL_count1>=80)
{
PLL_count1=0;
if((PLL_count11<20)||(PLL_count12<20))
{
Prmter1.PLL_STATE1 = 0x00;
PLL_count12=0;
PLL_count11=0;
TRISB5 = 0x00;//LO1LE
set_pll(FR1,0,0x20,0x02);//最后一個數2代表選用PORTB端口
TRISB5 = 0x01;
//init_freq(9,0x20,0x02,FR1);
}
}
PLL_count1++;
}
/**********************************************************
** 功能說明: 鎖相環3的檢測
** 輸入參數:
** 輸出參數:
** 返 回 值: 無
** 引用函數:
************************************************************/
void CHECK_PLL3()
{
uchar buf13;
buf13 = PORTD & 0x01;//3
if(buf13)
{
if(PLL_count31>=20)
{
Prmter1.PLL_STATE3 = 0x01;
PLL_count31=20;
PLL_count3=0;
}
PLL_count32=0;
PLL_count31++;
}
else
{
if(PLL_count32>=20)
{
Prmter1.PLL_STATE3 = 0x00;
PLL_count32=20;
//PLL_count3=0;
}
PLL_count31=0;
PLL_count32++;
}
if (PLL_count3>=80)
{
PLL_count3=0;
if((PLL_count31<20)||(PLL_count32<20))
{
Prmter1.PLL_STATE3 = 0x00;
PLL_count32=0;
PLL_count31=0;
TRISC0 = 0x00;//LO3LE
set_pll(FR3,0,0x01,0x01);//最后一個數1代表選用PORTC端口
TRISC0 = 0x01;
//init_freq(10,0x01,0x01,FR3);;
}
}
PLL_count3++;
}
/**********************************************************
** 功能說明: 鎖相環選擇端口PORTB,PORTC OR PORTD
** 輸入參數:buf4 類型uchar :某端口的通道號
** 輸入參數:buf 類型uchar :端口號,buf=1為PORTC,buf=2為PORTB
** 輸入參數:buf8 類型uchar :buf8=0為不鎖定,buf8=1為鎖定
** 輸出參數:
** 返 回 值: 無
** 引用函數:
************************************************************/
void PLL_PORT(uchar buf4,uchar buf,uchar buf8)
{
if (buf8==0)
{
switch(buf)
{
case 1: portc_wbuf = portc_wbuf & (~buf4);
PORTC = portc_wbuf;
break;
case 2: portb_wbuf = portb_wbuf & (~buf4);
PORTB = portb_wbuf;
break;
default: break;
}
}
else
{
switch(buf)
{
case 1: portc_wbuf = portc_wbuf | buf4;
PORTC = portc_wbuf;
break;
case 2: portb_wbuf = portb_wbuf | buf4;
PORTB = portb_wbuf;
break;
default: break;
}
}
}
/**********************************************************
** 功能說明: 鎖相環的控制(一、三級是ADF4360-7,12.8M晶振,起始頻點為885MHZ~915MHZ,中頻=140MHZ
** 輸入參數: freq 類型 uint :信道號
** 輸出參數: buf3 類型 uchar :上下行選擇,buf3=0為上行,buf3=1為下行
** 輸出參數: buf4 類型 uchar :某端口的通道號
** 輸出參數: buf6 類型 uchar :端口號,buf6=0為PORTD,buf6=1為PORTC,buf6=2為PORTB
** 返 回 值: 無
** 引用函數:
****/
void set_pll(uint freq,uchar buf3,uchar buf4,uchar buf6)
{
auto uchar reg_n_a;
auto uint reg_n_b,buf1,buf2;
auto union reg_n_buf reg_n_union;
SSPSTAT = 0x40;
SSPCON = 0x20;
PLL_PORT(buf4,buf6,0);
send(2,0x00000201);
// send(2,0x00000191);
PLL_PORT(buf4,buf6,1);
PLL_PORT(buf4,buf6,0);
send(2,0x004fe120);
// if (buf4==0x20)//LO1LE
// {
// send(2,0x008fc128);
// }
// else if (buf6==0x01)//LO3LE
// {
// send(2,0x008fc128);
// }
PLL_PORT(buf4,buf6,1);
delay_unit(1000);
dog();
if(freq > 300)//最大信道號的判斷
{
buf2 = 300;
}
else
{
buf2 = freq;
}
buf1 = buf2 + 10;
if (buf6==0x02)
{
reg_n_a = buf1 % 16;
reg_n_b = 465 + buf1 / 16;
}
else if (buf6==0x01)//LO3LE
{
reg_n_a = buf1 % 16;
reg_n_b = 465 + buf1 / 16;
}
reg_n_union.buf1 = 0x00000000;
reg_n_union.buf2[1] = reg_n_b%256;
reg_n_union.buf2[2] = reg_n_b/256;
//reg_n_union.buf2[2] = reg_n_union.buf2[2] | 0x40; //2分頻
reg_n_a = (reg_n_a << 2) | 0x02;
reg_n_union.buf2[0] = reg_n_union.buf2[0] | reg_n_a;
PLL_PORT(buf4,buf6,0);
send(2,reg_n_union.buf1);
PLL_PORT(buf4,buf6,1);
return;
}
/**********************************************************
** 功能說明: 發送數據
** 輸入參數: k 類型 uint :發送的次數
** 輸入參數: buf 類型 ulong :發送的數據
** 輸出參數:
** 返 回 值: 無
** 引用函數:
************************************************************/
void send(int k,ulong buf6)
{
auto union reg_n_buf reg_n_union1;
SSPIF = 0;
reg_n_union1.buf1 = buf6;
for(k = 2;k >= 0;k--)
{
SSPBUF = reg_n_union1.buf2[k];
while(SSPIF == 0)
{
;
}
SSPIF = 0;
}
return;
}
/**********************************************************
** 功能說明: 485串口數據處理
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 無
** 引用函數:
**********************************************************/
void serial_data()
{
auto uchar start,length,buf,buf1;
uchar bufver;//接收到的版本號
if(receive_over == 1)//如果接收完畢(包頭,包尾都收到)
{
length = receive_cnt - 2;
//if(Prmter1.TYPE != receive_buf[1]) //判斷協議類型
// if(TYPE != receive_buf[1]) //判斷協議類型
// {
// send_reply_flag(0x10,0x00);//協議類型錯誤
// goto go_return;
// }
if((Prmter1.ADDR != receive_buf[4]) && (receive_buf[4] != 0xff))//模塊地址錯(0xff為廣播群發)0X00為沒有設置地址
{
goto go_return; //模塊地址不符合,沒返回
}
dog();
bufver=receive_buf[2] & 0x0f;//取緩沖數組的第二個字節的低4位字節,高4位是信息來源
if(bufver!= PROTL)//協議版本號判斷
{
send_reply_flag(0x02,0x00);//0X02表示版本錯誤
goto go_return;
}
// if(receive_buf[7] > 69) //命令體長度不能大于69
// {
// send_reply_flag(0x05,0x00);
// goto go_return;
// }
if(receive_buf[6]!= 0xff) //命令頭應答標志錯
{
send_reply_flag(0x06,0x00);
goto go_return;
}
length =receive_cnt-4; //長度=命令體長度+……(不包括起始、結束、ASCII校驗這4個字節)
//length = receive_buf[7] + 7; //長度=命令體長度+……(不包括起始、結束、ASCII校驗這4個字節)
start = 1;
CheckCRC(receive_buf,length,start,pChecksum);
buf1 = length + 1;
if((pChecksum[0] != receive_buf[buf1]) || (pChecksum[1] != receive_buf[buf1+1]))//CRC檢驗判斷
{
send_reply_flag(0x03,0x00);
goto go_return;
}
if(receive_buf[5] == 0x40)//查詢基本參數
{
buf = Set_Basic_Parameter();//模塊基本信息參數查詢
if(erro&0x01)//查詢出錯
{
receive_buf[6] = 0x08;
erro = erro & 0xfe;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
if(receive_buf[5] == 0x60)//設置基本信息項
{
buf = Set_Basic_Parameter();//模塊基本信息參數設置
if(erro&0x02)//設置出錯
{
receive_buf[6] = 0x07;
erro = erro & 0xfd;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
if(receive_buf[5] == 0xc1)//設置參數
{
buf = Set_Parameter();//設置參數
if(erro&0x02)//設置出錯
{
receive_buf[6] = 0x07;
erro = erro & 0xfd;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
else if(receive_buf[5] == 0xc2)//查詢參數
{
buf =Set_Parameter();
if(erro&0x01)//查詢出錯
{
receive_buf[6] = 0x08;
erro = erro & 0xfe;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
else if(receive_buf[5] == 0x50)//查詢模塊參數地址
{
buf = Query_Address();
send_reply_flag(0x00,buf);
goto go_return;
}
else if(receive_buf[5]==0xd1)//查詢表格參數
{
if (receive_buf[8]==0x01)//查詢所有溫度值
{
buf=Query_tp(tempd,0x01);
}
else if (receive_buf[8]==0x02)//查詢所有頻率值
{
buf=Query_tp(freqd,0x02);
}
else if (receive_buf[8]==0x03)//查詢所有溫補參數編碼
{
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);
}
receive_buf[7]=buf;//命令體長度
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);
}
receive_buf[7]=buf;//命令體長度
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;
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;
receive_free();
receive_over = 0;
receive_cnt = 0;
CREN = 1;
RCIE = 1;
// T1CON=0x31;
return;
}
/**********************************************************
** 功能說明: 基本信息參數設置/查詢函數
** 輸入參數: 無
** 輸出參數:
** 返 回 值: 參數個數
** 引用函數:
**********************************************************/
uchar Set_Basic_Parameter()
{
auto union buf_union comm;
uint i;
uchar length;
uchar para_len;//參數值長度
uchar buf;
uchar *P = 0;
length = receive_cnt-10;//命令體長度
P = receive_buf+7;
erro = 0;
while(length)
{
comm.buf2[0] = *P++;
comm.buf2[1] = *P++;
para_len=*P++;//參數值長度
length = length - 3 ;
switch(comm.buf1)
{
case 0xf000: //模塊ID號
if(receive_buf[5]==0x60)//設置命令
{
for(i=0;i<para_len;i++)
{
buf=*P++;
wrom(mod_idadd+i,buf);
}
}
else
{
for(i=0;i<para_len;i++)
{
*P++=rrom(mod_idadd+i);
}
}
length=length-para_len;
break;
case 0xf001: //模塊類型
if(receive_buf[5]==0x60)//設置命令
{
for(i=0;i<para_len;i++)
{
buf=*P++;
wrom(mod_typeadd+i,buf);
}
}
else
{
for(i=0;i<para_len;i++)
{
*P++=rrom(mod_typeadd+i);
}
}
length=length-para_len;
break;
case 0xf002: //模塊地址
if(receive_buf[5]==0x60)//設置命令
{
Prmter1.ADDR=*P++ ;
wrom(mod_add_add,Prmter1.ADDR);
}
else
{
*P++=Prmter1.ADDR;
}
length--;
break;
case 0xf003: //協議版本
*P++=PROTL;
length--;
break;
// case 0xf004: //模塊參數個數
// *P++=MOD_Num;
// length--;
// break;
case 0xf005: //溫補參數個數
*P++=tn;
length--;
break;
case 0xf006: //頻響補償參數個數
*P++=pn;
length--;
break;
case 0xf007: //增益標稱值補償參數個數
*P++=zyn;
length--;
break;
case 0xf008: //增益刻度
*P++=bcnumb;
length--;
break;
case 0xf017: //程序ID號
for(i=0;i<para_len;i++)
{
*P++=PRO_ID[i];
}
length=length-para_len;
break;
case 0xf018: //程序版本號
*P++=0x01;
*P++=0x00;
length=length-2;
break;
case 0xf019: //生產序列號
if(receive_buf[5]==0x60)//設置命令
{
for(i=0;i<para_len;i++)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -