/** * RFIDTest * * Takes the serial data sent to it from the RFID on the RXD pin and output it * over the TXD pin. */#include <stdlib.h>#include <avr/io.h>void RFID_Initialize(){ // Disable Interrupts for the UART initialization. /** * Refer to data sheet for correct calculation for the baud clock. * This must be changed everytime the main oscillator is changed. */ UBRRH = 0; UBRRL = 12; // 103 // Set the frame format: 8 data, no parity, 1 stop, no flow control. UCSRC |= (1<<URSEL)|(3<<UCSZ0); // Enable double data rate to get a smaller margin of error in baud rate. UCSRA = (1<<U2X); // Enable the transmitter. UCSRB = (1<<TXEN)|(1<<RXEN); // Enable Interrupts.}void echo (uint8_t* msg){ uint8_t i = 0; while (msg[i] != 0) { while (! (UCSRA & (1<<UDRE))); UDR = msg[i++]; } return;}void showHourGlass(){ uint8_t frames[] = "-\b\\\b|\b/\b"; echo (frames);}/** * Main */int main() { /** * RFID Variables */ const uint8_t rfidTagSize = 10; // The RFID tag is twelve bytes long, but only the first ten matter. e.g. 041580983C36 uint8_t rfidTagBuffer[rfidTagSize]; uint8_t rfidTag[rfidTagSize]; // Initialize RFID_Initialize(); /** * Send a statup message. */ uint8_t startupMsg[] = "Watching for RFID tags.........\r\n"; echo (startupMsg); while (1) { /** * Wait for RFID via serial, and store it. Then wait for the rest of the RFID. * RXC */ if ((UCSRA & (1<<RXC))) { //uint8_t msg[] = "Receiving RFID tag."; //echo (msg); // Reset the character counter. uint8_t totalCharsReceived = 0; /** * Continue to receive all the characters. */ while (totalCharsReceived < rfidTagSize) { if ((UCSRA & (1<<RXC))) { // Wait for data to be received. while (!(UCSRA & (1<<RXC))); // Store the received byte. rfidTagBuffer[totalCharsReceived] = UDR; totalCharsReceived++; echo (totalCharsReceived); } } // Print the RFID tag. echo (rfidTagBuffer); uint8_t endMsg[] = "Received the tag."; echo (endMsg); } } return 0;}