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

📄 main.c

📁 PV4协议转换为MODBUS RTU协议的程序
💻 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)有限公司      								|
|                              												|
+-------------------------------------------------------------------------	+
| 基本功能简介: 															|
|	将PV4协议转换为modbus协议RTU方式,最大支持16个从机,分配1700byte做		|
|	数据缓冲,用从机地址做索引在查询数据										|
|  																			|
+---------------------------------------------------------------------------+
*/

#include".\Globle.h"
#include".\Uart_Pv4.h"
#include".\Function.h"
#include".\Modbus_RTU.h"
#include<EEPROM.h>
#include <macros.h>
extern void init_devices(void);
extern uchar gvc_tmp;
extern uchar gvc_num_tmp;

	
void main()
{
	uchar i,j;

	init_devices();					//init
	
	gvc_tmp=EEPROMread(EEPROM);				//read the address 
	if(gvc_tmp==0x55)
		{
			gvc_addr=EEPROMread(SLAVER_ADDR);
			
		}
	else
		{
			gvc_addr=0x01;
			EEPROMwrite(SLAVER_ADDR,0x01);
			EEPROMwrite(EEPROM,0x55);
		}
	DIR|=DIR_V;
	uart_send(gvc_addr);						//send the address	
	DIR&=~DIR_V;
	
	for(i=0;i<17;i++)
		{
		for(j=0;j<100;j++)
			{
				gvc_data_buf[i][j]=0x00;
			}

		}
	
	//gvc_addr=2;
	gvc_slaver_addr=1;
	gvc_timer_flg=0;
	cy_uartnumber=0;
	DIR&=~DIR_V;
	//PORTC|=0x20;
	WDR(); //this prevents a timout on enabling
	WDTCR = 0x1F;
 	WDTCR = 0x0f; //WATCHDOG ENABLED - dont forget to issue WDRs	
	while(1)
		{
			WDR();
	
			PV4_analyse();							//pv4 analyse
			if(gvc_100ms_flg)
				{
					gvc_100ms_flg=0;
					PV4_com(0x4c,gvc_slaver_addr);		//send pv4 commad
					gvc_slaver_addr++;
					if(gvc_slaver_addr>=17)
						gvc_slaver_addr=1;
				}
				
			Add_analyse();							//analyse the address commad
			
			uart_run();								//modbus RTU analyse
			

		
		}


}

⌨️ 快捷键说明

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