📄 main.c
字号:
//ICC-AVR application builder : 2004-10-27 10:06:29
// Target : M16
// Crystal: 8.0000Mhz
/*****************************************************
微控电子 www.mcuc.cn
modbus RTU 的mega16程序,使用ICCAVR编译
单片机mega16
通信波特率 9600 8位数据 1位停止位 偶校验 485通位接口
单片机控制板地址 localAddr(变量)
通信可设置数据的地址:
字地址 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数据
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置为接收状态
receCount = 0; //将接收地址偏移寄存器清零
checkoutError = 0;
}
}
c200ms++;
if(c200ms > 100)
{
c200ms = 0;
blinkLed(); //运行指示灯闪烁
}
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -