/********** * Polprog 2018 * 3 clause BSD licence * http://polprog.net */ #define F_CPU 1000000 #include #include #include #include #include #include "HD44780.h" #define DELIMETER 0x0D #define BUFSIZE (27) #define DERE 2 #define BEEP 3 //we need a place to keep the incoming data and an index to access it volatile uint8_t buffer[BUFSIZE]; volatile uint8_t idx; volatile uint8_t address; //flag indicating that a complete number was received volatile uint8_t process_flag = 0; void uart_init(); void gpio_init(); void uart_print(volatile uint8_t*); /* * Interrupt subroutine for UART receive interrupt. */ ISR(USART_RXC_vect){ //store our character for further processing uint8_t c = UDR; if(process_flag != 0) return; //do nothing if last data was not processed yet //check if the character is our message delimeter if(c == DELIMETER){ buffer[idx] = 0; //null terminate our string process_flag = 1; //flag that we need to process the data idx = 0; //restore index to zero for next message PORTB ^= 1; //debug }else if(idx < BUFSIZE) { //otherwise if there is space in the buffer store it buffer[idx] = c; //write the character to the buffer //UDR = c; //echo the character back idx++; //increment index } } void uart_init(){ // set baudrate to 9600 (U2X enabled, 1MHz clock) UBRRH = 0; UBRRL = 12; // enable 2x speed mode UCSRA |= (1<> 4) ^ 0x0F; PORTD |= (1<