📄 modbus.c
字号:
n =1;
uCol -=0x40;
l_cs = 0x02;
}
LCD_C_D(1,uRow);
LCD_C_D(1,uCol);
c1 = 0x2e;
for (k =0; k <2; k++)
{
for(j=0;j<8;j++)
{
LCD_C_D(0,~ASC_MSK[(c1-0x20)*16 +j+(k*8)]);
}
LCD_C_D(1,uRow+1);
LCD_C_D(1,uCol);
}
}
uCol +=8;
if ( ((uCol-0x40) >=64) && (n==0) )
{
n =1;
uCol -=0x40;
l_cs = 0x02;
}
LCD_C_D(1,uRow);
LCD_C_D(1,uCol);
}
}
//****************************************数字到ASCII*****************
void compose_data(uchar *pstr,uchar j)
{
ulong xdata i=0;
if ( j == 2 )
{
i = ((ulong)(pstr[0]) <<8)+(ulong)(pstr[1]);
if ( ((uint)i &0x8000)==0x8000 )
{
pstart[0] = 0x2d;
i =(ulong)(~(uint)i+1);
}
else
{
pstart[0] = (uchar)(i/10000)+0x30;
}
i = i%10000;
pstart[1] = (uchar)(i/1000)+0x30;
i = i%1000;
pstart[2] = (uchar)(i/100)+0x30;
i = i%100;
pstart[3] = (uchar)(i/10)+0x30;
i = i%10;
pstart[4] = (uchar)i+0x30;
}
else if ( j == 4 )
{
i = ((ulong)(pstr[0])<<24)+((ulong)(pstr[1])<<16)+((ulong)(pstr[2])<<8)+(ulong)(pstr[3]);
pstart[0] = (uchar)(i/100000)+0x30;
i = i%100000;
pstart[1] = (uchar)(i/10000)+0x30;
i = i%10000;
pstart[2] = (uchar)(i/1000)+0x30;
i = i%1000;
pstart[3] = (uchar)(i/100)+0x30;
i = i%100;
pstart[4] = (uchar)(i/10)+0x30;
i = i%10;
pstart[5] = (uchar)i+0x30;
}
else if ( j == 1)
{
i =(ulong)pstr[0];
pstart[0] = (uchar)(i/10)+0x30;
i = i%10;
pstart[1] = (uchar)i+0x30;
}
else
{
i = (ulong)pstr[0];
pstart[0] = (uchar)(i/100)+0x30;
i = i%100;
pstart[1] = (uchar)(i/10)+0x30;
i = i%10;
pstart[2] = (uchar)i+0x30;
}
}
void zero_data(uchar *pstr,uchar opt,uchar att)
{
uchar xdata i;
if ( att>0)
att = opt -att;
for ( i =0; i<(opt-att); i++ )
{
if ( (*(pstr+i) == 0x30)||(*(pstr+i) == 0x2d) )
{
if ( i >=(opt-att-1) )
{
if (*(pstr+i) == 0x2d)
{
*(pstr+i) = 0x2d;
}
else
{
*(pstr+i) = 0x30;
}
}
else
{
if ( (*(pstr+i) == 0x2d) )
{
*(pstr+i)=0x2d;
}
else
{
*(pstr+i)=0x20;
}
}
}
else
{
break;
}
}
}
void loop_data(uchar *ploop,uchar att)
{
uchar xdata i=0;
bit ov_flag =0;
if ( att>0)
att = 5 -att;
for ( i =0; i<(5-att); i++ )
{
if ( (*(ploop+i) == 0x30)||(*(ploop+i) == 0x2d) )
{
if ( i >=(4-att) )
{
if ( *(ploop+i) == 0x2d )
{
*(ploop+i)=0x2d;
}
else
{
*(ploop+i)=0x30;
}
}
else
{
if ( *(ploop+i) == 0x2d )
{
*(ploop+i)=0x2d;
ov_flag =1;
}
else
{
*(ploop+i)=0x20;
}
}
}
else
{
i++;
break;
}
}
if ( ov_flag )
{
ov_flag =0;
loop =5;
}
else
{
loop =(6-i);
}
switch(loop)
{
case 1 :
ploop[0] = ploop[4];
loop_dot = 0;
break;
case 2 :
ploop[0] = ploop[3];
ploop[1] = ploop[4];
loop_dot = 3;
break;
case 3 :
ploop[0] = ploop[2];
ploop[1] = ploop[3];
ploop[2] = ploop[4];
loop_dot = 2;
break;
case 4 :
ploop[0] = ploop[1];
ploop[1] = ploop[2];
ploop[2] = ploop[3];
ploop[3] = ploop[4];
loop_dot = 1;
break;
case 5 :
loop_dot = 0;
default:
break;
}
}
void change_data(uint addr,uchar *pstr,uchar size)
{
ulong xdata j ;
uchar xdata ph[4];
for (j =0; j<6; j++ )
{
if ( pstr[j] ==0x20 )
{
pstr[j] =0x30;
}
else if ( pstr[j] ==0x2d )
{
pstr[j] =0x30;
net_data =1;
}
else
{
j =0;
break;
}
}
if ( size == 2 )
{
j =(ulong)(pstr[0]-0x30)*10000+(ulong)(pstr[1]-0x30)*1000+(ulong)(pstr[2]-0x30)*100+(ulong)(pstr[3]-0x30)*10+(ulong)(pstr[4]-0x30);
if ( net_data )
j = (~j+1);
ph[0] = (uchar)(((uint)j&0xff00)>>8);
ph[1] = (uchar)((uint)j&0x00ff);
xjb_buf[addr-0x10]= ph[0];
xjb_buf[addr-0x10+1]= ph[1];
nbyteWrite(addr,2,ph);
}
else if ( size == 1 )
{
j =(ulong)(pstr[0]-0x30)*100+(ulong)(pstr[1]-0x30)*10+(ulong)(pstr[2]-0x30);
if ( net_data )
j = (~j+1);
ph[0] = (uchar)((uint)j&0x00ff);
xjb_buf[addr-0x10]= ph[0];
nbyteWrite(addr,1,ph);
}
else if ( size == 4 )
{
j =(ulong)(pstr[0]-0x30)*100000+(ulong)(pstr[1]-0x30)*10000+(ulong)(pstr[2]-0x30)*1000+(ulong)(pstr[3]-0x30)*100+(ulong)(pstr[4]-0x30)*10+(ulong)(pstr[5]-0x30);
ph[0] = 0x00;
ph[1] = (uchar)((j&0x000f0000)>>16);
ph[2] = (uchar)((j&0x0000ff00)>>8);
ph[3] = (uchar)((j&0x000000ff));
xjb_buf[addr-0x10]= ph[0];
xjb_buf[addr-0x10+1]= ph[1];
xjb_buf[addr-0x10+2]= ph[2];
xjb_buf[addr-0x10+3]= ph[3];
nbyteWrite(addr,4,ph);
}
net_data =0;
}
int char_int(uchar *pchar)
{
uint i;
i = ((int)(pchar[0])<<8)+(int)pchar[1];
return (int)i;
}
void int_char(int opt,char *pint)
{
pint[0] = (char)((opt&0xff00)>>8);
pint[1] = (char)(opt&0x00ff);
}
//********************************************清屏*******************
void CLRLCD(uchar number)
{
uchar i,j;
l_cs = 0x03;
for (i = 0xb8; i < 0xc0;i++)
{
LCD_C_D(1,i);
LCD_C_D(1,0x40);
for (j = 0; j < 0x40; j++)
LCD_C_D(0,number);
}
l_cs =0;
}
void CLRLCD2(uchar number)
{
uchar i,j;
l_cs = 0x03;
for (i = 0xba; i < 0xc0;i++)
{
LCD_C_D(1,i);
LCD_C_D(1,0x40);
for (j = 0; j < 0x40; j++)
LCD_C_D(0,number);
}
l_cs =0;
}
//**************************************显示英文***********************
void lcd_mode_english(unsigned char i)
{
uchar j=0;
switch( i )
{
case 0 :
if ( english_china )
{
display_lcd(0,2,"组 态",1);
if ( lcd_first_one ==0 )
{
display_lcd(1,0,"通道",0);
}
else
{
display_lcd(1,0,"通道",1);
}
if ( lcd_first_one ==1 )
{
display_lcd(1,3,"报警",0);
}
else
{
display_lcd(1,3,"报警",1);
}
if ( lcd_first_one ==2 )
{
display_lcd(1,6,"输出",0);
}
else
{
display_lcd(1,6,"输出",1);
}
if ( lcd_first_one ==3 )
{
display_lcd(2,0,"设定",0);
}
else
{
display_lcd(2,0,"设定",1);
}
if ( lcd_first_one ==4 )
{
display_lcd(2,3,"控制",0);
}
else
{
display_lcd(2,3,"控制",1);
}
if ( lcd_first_one ==5 )
{
display_lcd(2,6,"语言",0);
}
else
{
display_lcd(2,6,"语言",1);
}
if ( lcd_first_one ==6 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -