?? main.c
字號:
//ICC-AVR application builder : 2004-10-27 10:06:29
// Target : M16
// Crystal: 8.0000Mhz
/*****************************************************
微控電子 www.mcuc.cn
modbus RTU 的mega16程序,使用ICCAVR編譯
單片機(jī)mega16
通信波特率 9600 8位數(shù)據(jù) 1位停止位 偶校驗(yàn) 485通位接口
單片機(jī)控制板地址 localAddr(變量)
通信可設(shè)置數(shù)據(jù)的地址:
字地址 0 - 255 (只取16位的低8位)
位地址 0 - 255 (只取16位的低8位)
******************************************************/
#include "main.h"
uint32 tickCount,intTickCount;
uint8 flag1ms,c200ms;
#pragma interrupt_handler timer0_ovf_isr:10
//定時器0 1ms定時中斷
void timer0_ovf_isr(void)
{
TCNT0 = 0x83;
intTickCount++;
flag1ms = 1; //1ms 時間到
/*
if(adcCount<=SAMPLECOUNT-1 && adcCount>=0)
adcData[adcCount] = ADC & 0x3ff; //讀取AD數(shù)據(jù)
if(adcCount >= 0)
{
ADMUX = 0xc0 |(adcMux&0x0f);
ADCSR |= 1 << ADSC; //啟動ADC
adcCount--;
}
*/
}//void timer0_ovf_isr(void)
void timeProc(void)
{
static uint16 second;
static uint8 i;
if(flag1ms == 1)
{
flag1ms = 0;
CLI();
tickCount = intTickCount;
SEI();
if(receTimeOut>0)
{
receTimeOut--;
if(receTimeOut==0 && receCount>0) //判斷通訊接收是否超時
{
receEnable(); //將485置為接收狀態(tài)
receCount = 0; //將接收地址偏移寄存器清零
checkoutError = 0;
}
}
c200ms++;
if(c200ms > 100)
{
c200ms = 0;
blinkLed(); //運(yùn)行指示燈閃爍
}
second++;
if(second > 10000)
{
second = 0;
}
}
}//void timeProc(void)
void main(void)
{
int16 i;
varInit();
init_devices();
//重新采樣
CLI();
SEI();
for(i=0;i<400;i++)
{
}
while(1)
{
WDR(); //this prevents a timout on enabling
timeProc();
checkComm0Modbus();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -