#include #include #include #include #define queueDataInSize 8 struct queue { char * data; volatile unsigned char begin; volatile unsigned char end; unsigned char size; }; struct queue dataIn; unsigned char nextQueueIndex(unsigned char i, unsigned char n) { if(i==n-1) i=0; else i++; return i; } ISR(USART_RXC_vect) { volatile unsigned char tmp=nextQueueIndex(dataIn.end,dataIn.size); unsigned char data=UDR; if(tmp!=dataIn.begin) { dataIn.data[dataIn.end]=data; dataIn.end=tmp; PORTA=PORTA&0xf8|dataIn.end; } } int main(void) { dataIn.data=malloc(queueDataInSize); dataIn.size=queueDataInSize; dataIn.begin=0; dataIn.end=0; DDRA=0xff; UBRRL=51; //UCSRA=0; UCSRB=0x98; UCSRC=0x86; SREG|=1<