main.c

来自「modbus modbus modbus」· C语言 代码 · 共 51 行

C
51
字号
#include "reg52.h"
#include<modbus.h>
/*==============*/
/*==系统主函数==*/
/*==============*/

unsigned char idata MBFrame_OK=0;//接收到一个命令结束,等待处理时为1;否则为0.
unsigned char idata test[5]={0xff,0x00,0x00,0x00,0x00};
int Parameter_Table[10]={0,1,2,3,4,5,6,7,8,9,};
#define Parameter_Num 10 

void main (void)
    {
     unsigned int temp;
     MBSerialInit();
//	 IE    =0x92;
//   IP    =0x00;
	 TR0=1;
     while(1)
         {
		 if(MBFrame_OK==1)
		   {
 			 ModBusProtocolProcess();
             temp=Parameter_Table[0];
			 if((temp&0x8000)==0x8000)
			    {
			     test[1]=27;//显示负号
		         temp=temp-1;
			     temp=~temp;
                 test[2] = (unsigned char)(temp/100);
                 temp=temp-test[2]*100;
			     test[3] = (unsigned char)(temp/10);
			     temp=temp-test[3]*10;
			     test[4] = (unsigned char)(temp%10);
                 test[0] = 0xff;
				}
			 else
			    { 
			     test[1]= (unsigned char)(temp/1000);
                 temp=temp-test[1]*1000;
                 test[2] = (unsigned char)(temp/100);
                 temp=temp-test[2]*100;
			     test[3] = (unsigned char)(temp/10);
			     temp=temp-test[3]*10;
			     test[4] = (unsigned char)(temp%10);
                 test[0] = 0x00;
			     }
		   }
         }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?