原代码来了,里面加入了好多冗余标志位,但没效。
#include
#include
#include
#include
#define CLI() do { __asm__ __volatile__ ("cli"); } while (0)
#define SEI() do { __asm__ __volatile__ ("sei"); } while (0)
#define NOP() do { __asm__ __volatile__ ("nop"); } while (0)
#define uchar unsigned char
#define uint unsigned int
volatile uchar wdt1=1;
volatile uchar RE_rcorrect[128]; //正确接收到的新码;
volatile uchar wdt2=1;
//------------------------
volatile uchar RD_count;
volatile uchar Rdata;
volatile uchar usart0_Rbuff[128]; //接收缓冲器
volatile uchar usart0_REflag=0;
volatile uchar usart0_RSflag=0;
volatile uchar wdt3=1;
volatile uchar send_flag=0;
volatile uchar send_Tflag=0;
volatile uchar Send_buff[128]; //发送缓冲器
volatile uchar REtime=0;
volatile uchar RecDataBCC=0;
volatile uchar IN_BCC=0;
volatile uchar OUT_BCC=0;
volatile uchar Send_buff[128]; //发送缓冲器
volatile uchar wdt4=1;
volatile uchar temA=0;
volatile uchar temB=0;
volatile uchar temA1=0;
volatile uchar temB1=0;
volatile uchar Send_buff[128]; //发送缓冲器
volatile uchar PasttemA=0;
volatile uchar PasttemB=0;
volatile uchar passmark=0;
volatile uchar passcount=0;
volatile uchar wdt5=1;
volatile uchar Send_tem[128]; //T发送缓冲器
void usart0_send(uchar sdata);
void String_send(uchar *p,uchar Lenth);
volatile uchar wdt6=1;
volatile uchar t1=0;
volatile uchar t2=0;
volatile uchar t3=0;
volatile uchar t4=0;
volatile uchar usart0_ST1buff[128]; //T发送缓冲器
volatile uchar send_INmark=0;
volatile uchar send_OUTmark=0;
void timer1_init(void)
{
TCCR1A=0x00; //普通模式,不与OCnA相连。
TCCR1B=0x03; //Clk/64
TCCR1C=0x00; //不设置强制输出通道
TCNT1H=0xEC; //定时20ms=次数/每秒次数=(FFFF-初值)/(F_CU/分频)
TCNT1L=0x77;
// TCNT1H=0xF6; //定时10ms=次数/每秒次数=(FFFF-初值)/(F_CU/分频)
// TCNT1L=0x3B;
TIMSK|=_BV(TOIE1);//使能定时器1;
}
ISR(SIG_OVERFLOW1)//定时器1中断
{
uchar i=0;
NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
wdt1=0;
TCNT1H=0xEC; //定时20ms=次数/每秒次数=(FFFF-初值)/(F_CU/分频)
TCNT1L=0x77;
//--------------------------------------
if(REtimei)&0x01)==0x01)
{
Send_tem[2+i]=0x30;
}
else
{
Send_tem[2+i]=0x31;
}
IN_BCC=IN_BCC^Send_tem[2+i];
}
for(i=0;i>i)&0x01)==0x01)
{
Send_tem[10+i]=0x30;
}
else
{
Send_tem[10+i]=0x31;
}
IN_BCC=IN_BCC^Send_tem[10+i];
}
Send_tem[14]=IN_BCC;
Send_tem[15]=0x03;
if((PasttemA!=temA)||(PasttemB!=temB))
{
PasttemA=temA;
PasttemB=temB;
send_Tflag=1; //注销这一行即可取消主动反馈
send_INmark=1;//注销这一行即可取消主动反馈
}
}
wdt1=1;
}
void usart0_init()
{
UCSR0B=0x00; //close USART
UCSR0A=0x00;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67;
UCSR0B=0xd8; //open USARTd8
}
ISR(USART0_TX_vect)
{
NOP();
UCSR0A |= (1