?? 新建_文本文檔_(2).txt
字號:
SendBuff[4]=RecvBuff[1];//序號
SendBuff[5]=00;
SendBuff[6]=00;//上限
SendBuff[7]=00;
SendBuff[8]=00;//下限
CRC_Assign(&SendBuff[2],7,&SendBuff[9],&SendBuff[10]);//CRC校驗
sendComm();
}
break;
//-----------------------------------------------------------------------------
//功 能:設置轉換比例
//上位機:AA 0F 組號 XX XX XX XX CRC1 CRC2
// |整數| . |小數|
//下位機: 5個字節
// 正確:BB 0F 00 00 00
// CRC錯誤: BB 0F FF 00 00
//-----------------------------------------------------------------------------
case 0x0F:
for(i=0;i<7;i++)
{
Temp=getuchar();
RecvBuff[i+1]=Temp;//數據
}
if (CRC_Check(&RecvBuff[0],6,RecvBuff[6],RecvBuff[7]))//CRC校驗
{
//BytesToFloat44
//設置電流數據的參照值比例 ADValue[]
ADValue[RecvBuff[1]-1]=BytesToFloat44(RecvBuff[2],RecvBuff[3],RecvBuff[4],RecvBuff[5]);
SendBuff[0]=0x05;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0x0F;
SendBuff[3]=0x00;
SendBuff[4]=0x00;
SendBuff[5]=0x00;
sendComm();
NeedSaveFlag=0x0F;
}
else
{
SendBuff[0]=0x05;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0x0F;
SendBuff[3]=0xFF;
SendBuff[4]=0x00;
SendBuff[5]=0x00;
sendComm();
}
break;
//-----------------------------------------------------------------------------
//功 能:讀取轉換比例
//上位機:AA 10 XX CRC1 CRC2
// |組|
//下位機: 10個字節
// 正確:BB 10 00 XX XX XX XX XX CRC1 CRC2
// |組| |整數|. |小數|
// CRC錯誤: BB 10 FF 00 00 00 00 00 CRC1 CRC2
//-----------------------------------------------------------------------------
case 0x10:
for(i=0;i<3;i++)
{
Temp=getuchar();
RecvBuff[i+1]=Temp;//數據
}
if (CRC_Check(&RecvBuff[0],2,RecvBuff[2],RecvBuff[3]))//CRC校驗
{
SendBuff[0]=0x10;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0x10;
SendBuff[3]=0x00;
//FloatToBytes44_Assign
SendBuff[4]=RecvBuff[1];//序號
FloatToBytes44_Assign(&ADValue[RecvBuff[1]-1],&SendBuff[5],&SendBuff[6],&SendBuff[7],&SendBuff[8]);
CRC_Assign(&SendBuff[2],7,&SendBuff[9],&SendBuff[10]);//CRC校驗
sendComm();
}
else
{
SendBuff[0]=0x10;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0x10;
SendBuff[3]=0xFF;
SendBuff[3]=0x00;//序號
SendBuff[4]=0x00;
SendBuff[5]=0x00;
SendBuff[6]=0x00;
SendBuff[7]=0x00;
CRC_Assign(&SendBuff[2],7,&SendBuff[9],&SendBuff[10]);//CRC校驗
sendComm();
}
break;
//-----------------------------------------------------------------------------
//功 能:發送一個不定長度的操作序列
//描 述: 調試使用,所以沒有進行CRC校驗!!!!
//上位機:DD ............. FE
// 開始 結束
//下位機: 5個字節
// 正確:BB DD 00 00 00
//-----------------------------------------------------------------------------
case 0xDD:
for(;;)
{
i=getuchar();
if (i==0xFE)
break;
else
sendkey(i,0);
}
SendBuff[0]=0x05;//發送長度05 DD 01 00 00
SendBuff[1]=0xBB;
SendBuff[2]=0xDD;
SendBuff[3]=0x00;
SendBuff[4]=0x00;
SendBuff[5]=0x00;
sendComm();
break;
//-----------------------------------------------------------------------------
//功 能:設置發送模式
//上位機:AA B1 XX 00 00
//下位機: 5個字節
// 正確:BB B1 00 00 00
// CRC錯誤:BB B1 FF 00 00
//-----------------------------------------------------------------------------
case 0xB1:
for(i=0;i<3;i++)
{
Temp=getuchar();
RecvBuff[i+1]=Temp;//數據
}
//處理命令
if (RecvBuff[0]==0xB1&&RecvBuff[2]==0x00&&RecvBuff[3]==0x00)//校驗
{
SendBuff[0]=0x06;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0xB1;
SendBuff[3]=0x00;
F_SendMode=RecvBuff[1];
CRC_Assign(&SendBuff[2],3,&SendBuff[5],&SendBuff[6]);//CRC校驗
sendComm();
NeedSaveFlag=0xB1;
}
else
{
SendBuff[0]=0x06;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0xB1;
SendBuff[3]=0xFF;
SendBuff[4]=0x00;
SendBuff[5]=0x00;
SendBuff[6]=0x00;
sendComm();
}
break;
//-----------------------------------------------------------------------------
//功 能:設置掃描碼延時
//上位機:AA B2 XX 00 00
//下位機: 5個字節
// 正確:BB B2 00 00 00
// CRC錯誤:BB B2 FF 00 00
//-----------------------------------------------------------------------------
case 0xB2:
for(i=0;i<3;i++)
{
Temp=getuchar();
RecvBuff[i+1]=Temp;//數據
}
//處理命令
if (RecvBuff[0]==0xB2&&RecvBuff[2]==0x00&&RecvBuff[3]==0x00)//校驗
{
SendBuff[0]=0x06;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0xB2;
SendBuff[3]=0x00;
key_Delay=RecvBuff[1];
CRC_Assign(&SendBuff[2],3,&SendBuff[5],&SendBuff[6]);//CRC校驗
sendComm();
NeedSaveFlag=0xB2;
}
else
{
SendBuff[0]=0x06;//發送長度
SendBuff[1]=0xBB;
SendBuff[2]=0xB2;
SendBuff[3]=0xFF;
SendBuff[4]=0x00;
SendBuff[5]=0x00;
SendBuff[6]=0x00;
sendComm();
}
break;
}
}
SEI();
}
//串口數據發送中斷服務程序
#pragma interrupt_handler uart0_tx_isr:14
void uart0_tx_isr(void)
{
//character has been transmitted
}
//串口空閑中斷服務程序
#pragma interrupt_handler uart0_udre_isr:13
void uart0_udre_isr(void)
{
//character transferred to shift register so UDR is now empty
}
//******************************************************************************
//子函數
//******************************************************************************
void display_Dat(uchar Index,float Dat)
{
float DisplayDat;
uchar BitDat;
//先換算成實際數據
DisplayDat=Dat;
if(DisplayDat>9999.99)
DisplayDat=9999.99;
//組
putled(1,0,Index);//顯示0
putled(2,0,0x12);//0x12
//數據
BitDat=(int)(DisplayDat/1000);
putled(3,0,BitDat);
DisplayDat=DisplayDat-BitDat*1000;
BitDat=(int)(DisplayDat/100);
putled(4,0,BitDat);
DisplayDat=DisplayDat-BitDat*100;
BitDat=(int)(DisplayDat/10);
putled(5,0,BitDat);
DisplayDat=DisplayDat-BitDat*10;
BitDat=(int)(DisplayDat);
putled(6,1,BitDat);
DisplayDat=DisplayDat-BitDat;
BitDat=(int)(DisplayDat*10);
putled(7,0,BitDat);
DisplayDat=DisplayDat-BitDat*0.1;
BitDat=(int)(DisplayDat*100);
putled(8,0,BitDat);
DisplayDat=DisplayDat-BitDat*0.01;
}
// 顯示電流數據
void display_electricity()
{
float DisplayDat;
uchar BitDat;
//先換算成實際數據
DisplayDat=AD[E_Index]*ADValue[E_Index]/0x3FF;
if(DisplayDat>9999.99)
DisplayDat=9999.99;
//組
putled(1,0,0);//顯示0
putled(2,0,E_Index+1);//0x12
//數據
BitDat=(int)(DisplayDat/1000);
putled(3,0,BitDat);
DisplayDat=DisplayDat-BitDat*1000;
BitDat=(int)(DisplayDat/100);
putled(4,0,BitDat);
DisplayDat=DisplayDat-BitDat*100;
BitDat=(int)(DisplayDat/10);
putled(5,0,BitDat);
DisplayDat=DisplayDat-BitDat*10;
BitDat=(int)(DisplayDat);
putled(6,1,BitDat);
DisplayDat=DisplayDat-BitDat;
BitDat=(int)(DisplayDat*10);
putled(7,0,BitDat);
DisplayDat=DisplayDat-BitDat*0.1;
BitDat=(int)(DisplayDat*100);
putled(8,0,BitDat);
DisplayDat=DisplayDat-BitDat*0.01;
}
// 顯示配比
void display_percent()
{
if(DataBuff[0]!=0x09)
{
if(timer<=30)
{
putled(1,0,0);
putled(2,0,0x10);
}
if(timer>=30)
{
putled(1,0,0x10);
putled(2,0,0);
}
putled(3,0,0);
putled(4,0,0);
putled(5,0,0);
putled(6,0,0);
putled(7,0,0);
putled(8,0,0);
return;
}
if(DataBuff[0]==0x09)//說明緩沖內有數據
{
// 包頭 命令 長度 配比數據串 校驗碼
// -----------------------------------------------
// AA 09 LEN1 LEN2 3XX 3XX 3XX 3XX 3XX 3XX 3XX 3XX 操作碼..... CRC1 CRC2
// 2 | 2 | 24 | ......| 2 |
// LEN=2+2+24+N+2;LEN-包頭
//BB 09 00 CRC1 CRC2
//顯示哪一組 11 二個 2,9 11 11
//ab cd.ef
putled(1,0,0);
putled(2,0,P_Index+1);//0x12-
//顯示數據
putled(3,0,(int)(DataBuff[3+P_Index*3]/10));//a
putled(4,0,DataBuff[3+P_Index*3]-(int)(DataBuff[3+P_Index*3]/10)*10);//b
putled(5,0,(int)(DataBuff[3+P_Index*3+1]/10));//c
putled(6,1,DataBuff[3+P_Index*3+1]-(int)(DataBuff[3+P_Index*3+1]/10)*10);//d
putled(7,0,(int)(DataBuff[3+P_Index*3+2]/10));//e
putled(8,0,DataBuff[3+P_Index*3+2]-(int)(DataBuff[3+P_Index*3+2]/10)*10);//f
}
}
// 重發-發送
void send_buff_key(uchar WithDog)
{
int DataLen=0;//長度
uchar Temp=0;
//檢查密碼單元
if(DataBuff[0]==0x09)//說明緩沖內有數據
{
DataLen=BytesToInt(DataBuff[1],DataBuff[2]);
if(DataLen==0)
return;
if (CRC_Check(&DataBuff[0],DataLen-3,DataBuff[DataLen-3],DataBuff[DataLen-2]))//CRC校驗
{
sendkeys(&DataBuff[27],DataLen-30,WithDog);
}
}
}
//*
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -