⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 TLS35协议转换成MODBUS ASCII协议
💻 C
字号:
/*
+---------------------------------------------------------------------------+
| Project:  Modbus conventor with ATmega64					                |
|                                                                        	|
| File:   	Main.c                                                      	|
| Date:  	2007-9-10                                                   	|
| Version: 	V 1.0                                                       	|
| Initial Editor: Wu Wei                                          			|
+---------------------------------------------------------------------------+
| following 	environments are supported                                  |
| Processor: 	ATmega64						                            |
| Compiler: 	ICCAVR 														|
| hardware:		Protocol convertor v1.0										|
+---------------------------------------------------------------------------+
| 版权声明: 最终版权归优必得(OPW)有限公司      								|
|                              												|
+-------------------------------------------------------------------------	+
| 基本功能简介: 															|
|	将TLS-350协议转换为modbus协议ASCII方式,最大支持16个从机,分配1700byte做	|
|	数据缓冲,用从机地址做索引在查询数据										|
|  																			|
+---------------------------------------------------------------------------+
*/	

#include".\Globle.h"
#include".\Uart_modbus.h"
#include".\Uart_tls.h"
#include".\Function.h"
#include<EEPROM.h>
#include <macros.h>
extern void init_devices(void);

void main()
{
	uchar i,j,gvc_tmp;
	init_devices();				//init 
	gvc_tmp=EEPROMread(EEPROM);		//read the eeprom flag
	if(gvc_tmp==0x55)					//judge the flag
		{
			gvc_slave_addr=EEPROMread(SLAVER_ADDR);		//read address
			
		}
	else
		{
			gvc_slave_addr=0x01;							//default address
			EEPROMwrite(SLAVER_ADDR,0x01);
			EEPROMwrite(EEPROM,0x55);
		}
	DIR|=DIR_V;											//send the slaver address
	M_uart_send(gvc_slave_addr);			
	DIR&=~DIR_V;
	
		

	

	for(i=0;i<17;i++)											//init all of the buffer
		{
		for(j=0;j<100;j++)
			{
				gvc_data_buf[i][j]=0x31;
			}

		}

/*
	for(i=0,j=0;100;i++)
		{
			gvc_data_buf[1][i]=30;
		
		}
*/	/*************WDT**************/
	WDR(); //this prevents a timout on enabling
	WDTCR = 0x1f;
 	WDTCR = 0x0f; //WATCHDOG ENABLED - dont forget to issue WDRs	
	
	gvc_slaver_addr=1;
	while(1)
		{
			
			WDR();							//clear the wdt
			
	//---------------------------------------------------------------
			if(gvc_tls_flg)					//receive the whole frame of tls
				{
					gvc_tls_flg=0;
					//PORTD|=0x10;
					//M_uart_send(0x55);
					Tls_analyse();			//analyse the frame
					//PORTD&=~0x10;
				}
	//--------------------------------------------------------------
			if(gvc_100ms_flg)				//time to send the commad of tls
				{
					//PORTD|=0x10;
					//M_uart_send(0x55);
					//PORTD&=~0x10;
					gvc_100ms_flg=0;
					Tls_com(1,gvc_slaver_addr);
					gvc_slaver_addr++;				//address
					if(gvc_slaver_addr>=17)
						gvc_slaver_addr=1;
				}
	//-------------------------------------------------------------		
			if(gvc_mod_flg)					//receive the whole frame of modbus
				{
					DIR|=DIR_V;
					gvc_mod_flg=0;
					//M_uart_send(0x66);
					Modbus_analyse();		//analyse the modbus frame
					DIR&=~DIR_V;
				}
			
		}


}

⌨️ 快捷键说明

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