📄 main.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协议RTU方式,最大支持16个从机,分配1700byte做 |
| 数据缓冲,用从机地址做索引在查询数据 |
| |
+---------------------------------------------------------------------------+
*/
#include".\Globle.h"
#include".\Uart_tls.h"
#include".\Function.h"
#include".\Modbus_RTU.h"
#include<EEPROM.h>
#include <macros.h>
extern void init_devices(void);
extern uchar gvc_uart_flg;
extern uchar gvc_num_tmp;
void main()
{
uchar i,j;
uchar gvc_tmp;
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]=0x35; //init the buffer
}
}
gvc_slaver_addr=1;
gvc_timer_flg=0;
cy_uartnumber=0;
DIR&=~DIR_V;
WDR(); //this prevents a timout on enabling
WDTCR = 0x1F;
WDTCR = 0x0f; //WATCHDOG ENABLED - dont forget to issue WDRs
while(1)
{
WDR(); //clear the watch dog
if(gvc_tls_flg)
{
gvc_tls_flg=0;
WDR();
Tls_analyse(); //tls protocol analyse
//PORTD&=~0x10;
}
if(gvc_100ms_flg)
{
WDR();
//PORTD|=0x10;
//M_uart_send(0x55);
//PORTD&=~0x10;
gvc_100ms_flg=0;
Tls_com(1,gvc_slaver_addr); //send the ptl commad
gvc_slaver_addr++;
if(gvc_slaver_addr>=17)
gvc_slaver_addr=1;
}
Add_analyse(); //analyse the address
uart_run(); //modbus RTU protocol analyse
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -