void Auto_Reader(void) { while(1) { if(PcdRequest(0x52,Temp)==MI_OK) { if(Temp[0]==0x04&&Temp[1]==0x00) PutString("MFOne-S50"); else if(Temp[0]==0x02&&Temp[1]==0x00) PutString("MFOne-S70"); else if(Temp[0]==0x44&&Temp[1]==0x00) PutString("MF-UltraLight"); else if(Temp[0]==0x08&&Temp[1]==0x00) PutString("MF-Pro"); else if(Temp[0]==0x44&&Temp[1]==0x03) PutString("MF Desire"); else PutString("Unknown"); if(PcdAnticoll(UID)==MI_OK) { PutString0("Card Id is:"); tochar(UID[0]); tochar(UID[1]); tochar(UID[2]); tochar(UID[3]); while (!(IFG1 & UTXIFG0)); TXBUF0 = '\n'; //发送换行指令 RED_LED_ON ; Delay(200) ; RED_LED_OFF ; Delay(200) ; } } else GRE_LED_OFF ; } }
/*--- MAIN -------------------------------------------------------------------*/ int main(void) { char temp_char; uint16_t loop = 1; uint8_t bootFlag = TRUE; cli(); /* the following code moves the interrupt vector pointer to the bootloader section. The problem is the compiler doesn't understand where to put the IV table. */ GICR = _BV(IVCE); GICR |= _BV(IVSEL); //move interruptvectors to the Boot sector /* The slow baud rate is required because of the intel hex parsing overhead. If I could figure out how to enable interrupts in the BLS (compiler issue) then a higher speed could be used by switching to an interrupt based UART ISR. The code could also be optimized. */ SerCom0Init(BAUD_2400); // NOTE, the baud rates are constants defined in // sercom.h. You need to adjust those constants // to fit your MCU speed // poll USART receive complete flag 64k times to catch the 'i' reliably // test if flash is empty (i.e. flash content is 0xff) if(pgm_read_byte_near(0x0000) != 0xFF) { bootFlag = FALSE; } do { if(bit_is_set( UCSRA, RXC)) if( UDR == 'i') { bootFlag = TRUE; PutString0("Boot V "); PutChar0(VER_HIGH_BYTE); PutChar0(VER_LOW_BYTE); PutString0("\r\n"); } } while(loop++); /* this main loop is the user 'menu'. */ while(bootFlag) { if( Hit0() ) // more necessary for UART code running interrupts { temp_char=GetChar0(); switch(temp_char) { case 'u': // download new program { /* erase the main flash excepting BLS */ buf_address = 0; while ( APP_END > buf_address ) { boot_page_erase(buf_address); // Perform page erase boot_spm_busy_wait(); // Wait until the memory is erased. buf_address += SPM_PAGESIZE; } buf_address = 0; /* load new program */ PutString0("READY"); if(( temp_char = ihex_load())) { PutString0("ERR "); PutInt0(temp_char); } else {( PutString0("OK") ); bootFlag = FALSE ; // Exit to run } } break; case 'x': //Exit upgrade { GICR = _BV(IVCE); GICR &= ~_BV(IVSEL); //move interruptvectors to the Application sector jump_to_app(); // Jump to application sector // wdt_enable(WDTO_15MS); // Enable Watchdog Timer to give reset } break; default: { PutString0("u - Upload or x - Execute\r\n"); } } // end switch } // end if( Hit0() ) } // end while(1) // Start to application GICR = _BV(IVCE); GICR &= ~_BV(IVSEL); //move interruptvectors to the Application sector jump_to_app(); // Jump to application sector return 0; }