?? 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)有限公司 |
| |
+------------------------------------------------------------------------- +
| 基本功能簡介: |
| 將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 + -