📄 moudlebus.c.svn-base
字号:
#include<msp430x13x.h>
#include"..\inc\resources.h"
#include"..\inc\const_def.h"
extern unsigned char rcv[50],trn[30],dt[30];//transmit receive buffer
extern unsigned char txnumber; //receive number
extern unsigned char rcv_pkg_ok; //receive pakage flag
extern unsigned int ack_out_f;
unsigned char const comman_tbl[] = {
//0 run Frontad
':', 0x01, 0x03, 0x01, 0x03,0xff,
//6 run reversal
':', 0x01, 0x03, 0x01, 0x14,0xff,
//12 stop
':', 0x01, 0x03, 0x01, 0x08,0xff,
//18 ack out f
':', 0x01, 0x04, 0x01, 0x01,0xff,
//24 set f
':', 0x01, 0x05, 0x02, 0xff,
//29 set parameter
':', 0x01, 0x02, 0x03, 0xff};
#define RUNFR 0
#define RUNREV 6
#define STOP 12
#define ACKOUTF 18
#define SETF 24
#define SETP 29
#define NONE_P 0xffff
#define MB_ATIME 12 // 0.1~6500.0
#define MB_DTIME 13 // 0.1~6500.0
#define MB_PLOCK 10 //1 lock; 0 no lock
/////////////////////////////////////
unsigned char get_low_char(unsigned char ch)
{
unsigned char i;
i = ch & 0x0f;
if( i < 10 )
i += 0x30;
else i += (0x41-10);
return (i);
}
unsigned char get_hi_char(unsigned char ch)
{
unsigned char i;
i = (ch & 0xf0) >> 4;
if( i < 10 )
i += 0x30;
else i += (0x41-10);
return (i);
}
unsigned char get_dnumber(unsigned char ch)
{
unsigned char i;
if( ch > 0x40 )
i = ch - (0x41 - 0x0a);
else i = ch - 0x30;
return (i);
}
void comm_bld( unsigned int comm,unsigned int p1,unsigned int p2 )
{
unsigned char lcr,k;
unsigned int i,j;
rcv_pkg_ok = FALSE;
lcr = 0;
j = 0;
//trn[j++] = ':';
//command
i = 1;
k = comman_tbl[ comm + i ];
do{
lcr += k;
trn[j++] = get_hi_char(k);
trn[j++] = get_low_char(k);
i++;
k = comman_tbl[ comm + i ];
}while( k != 0xff);
//p1
if( p1 != NONE_P ){
k = p1;
lcr += k;
trn[j++] = get_hi_char(k);
trn[j++] = get_low_char(k);
}
//p2
if( p2 != NONE_P ){
k = ( p2 & 0xff00) >> 8;
lcr += k;
trn[j++] = get_hi_char(k);
trn[j++] = get_low_char(k);
k = p2 & 0xff;
lcr += k;
trn[j++] = get_hi_char(k);
trn[j++] = get_low_char(k);
}
k = ~lcr + 1;
trn[j++] = get_hi_char(k);
trn[j++] = get_low_char(k);
trn[j++] = 0x0d;
trn[j++] = 0x0a;
trn[j++] = 0x00;
trn[j++] = '.';
rs485out_(); //out
txnumber = 0;
U0TXBUF = ':';
}
unsigned int check_pkg_lcr( unsigned int n)
{
unsigned char lcr;
unsigned int i,j;
if( rcv[0] != ':')
return(1);
i =1;
j =0;
lcr = 0;
while( rcv[i] != 0x0d){
dt[j] = get_dnumber( rcv[i] )*16 + get_dnumber( rcv[i+1] );
lcr += dt[j];
i += 2;
j++;
}
if( lcr != 0 )
return (1);
switch(n){
case SETP:
if( dt[1] == 0x81 )
return(1);
break;
case SETF:
if( (dt[1] != 0x05) || (dt[2] != 0x02) )
return(1);
break;
case STOP:
case RUNFR:
if( dt[1] == 0x83 )
return(1);
break;
case ACKOUTF:
if( (dt[1] != 0x04) || (dt[3] != 0x01) )
return(1);
ack_out_f = dt[4] * 256 + dt[5];
break;
default:
break;
}
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -