![](/media/cache/group/nUCLEO.png.50x50_q85.jpg)
hmc5883l
Dependencies: HMC5883L LCD4884 MFRC522 eeprom mbed
project.cpp@0:930d2bc16788, 2015-12-06 (annotated)
- Committer:
- 1918june
- Date:
- Sun Dec 06 13:10:54 2015 +0000
- Revision:
- 0:930d2bc16788
- Child:
- 1:7556e9c47b98
555
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1918june | 0:930d2bc16788 | 1 | #include "mbed.h" |
1918june | 0:930d2bc16788 | 2 | #include "LCD4884.h" |
1918june | 0:930d2bc16788 | 3 | #include "MFRC522.h" |
1918june | 0:930d2bc16788 | 4 | #include "eeprom.h" |
1918june | 0:930d2bc16788 | 5 | #include "string.h" |
1918june | 0:930d2bc16788 | 6 | |
1918june | 0:930d2bc16788 | 7 | |
1918june | 0:930d2bc16788 | 8 | // KL25Z Pin for MFRC522 reset |
1918june | 0:930d2bc16788 | 9 | #define MF_RESET D9 |
1918june | 0:930d2bc16788 | 10 | |
1918june | 0:930d2bc16788 | 11 | |
1918june | 0:930d2bc16788 | 12 | EEPROM eeprom(I2C_SDA,I2C_SCL,0); |
1918june | 0:930d2bc16788 | 13 | Serial pc(SERIAL_TX,SERIAL_RX); |
1918june | 0:930d2bc16788 | 14 | LCD4884 lcd; |
1918june | 0:930d2bc16788 | 15 | MFRC522 RFID(D11, D12, D13, D10, MF_RESET); |
1918june | 0:930d2bc16788 | 16 | |
1918june | 0:930d2bc16788 | 17 | |
1918june | 0:930d2bc16788 | 18 | int main() |
1918june | 0:930d2bc16788 | 19 | { |
1918june | 0:930d2bc16788 | 20 | pc.baud(9600); |
1918june | 0:930d2bc16788 | 21 | int8_t recieve[12]={0}; |
1918june | 0:930d2bc16788 | 22 | int8_t cmd[12]; |
1918june | 0:930d2bc16788 | 23 | cmd[0] = 186; |
1918june | 0:930d2bc16788 | 24 | cmd[1] = 23; |
1918june | 0:930d2bc16788 | 25 | cmd[2] = 37; |
1918june | 0:930d2bc16788 | 26 | cmd[3] = 231; |
1918june | 0:930d2bc16788 | 27 | cmd[4] = 57; |
1918june | 0:930d2bc16788 | 28 | cmd[5] = 3; |
1918june | 0:930d2bc16788 | 29 | cmd[6] = 106; |
1918june | 0:930d2bc16788 | 30 | cmd[7] = 224; |
1918june | 0:930d2bc16788 | 31 | cmd[8] = 37; |
1918june | 0:930d2bc16788 | 32 | cmd[9] = 231; |
1918june | 0:930d2bc16788 | 33 | cmd[10] = 57; |
1918june | 0:930d2bc16788 | 34 | cmd[11] = 23; |
1918june | 0:930d2bc16788 | 35 | char name[ |
1918june | 0:930d2bc16788 | 36 | //char name[ |
1918june | 0:930d2bc16788 | 37 | eeprom.write(100,cmd,24); |
1918june | 0:930d2bc16788 | 38 | wait_ms(10); |
1918june | 0:930d2bc16788 | 39 | eeprom.read(100,recieve,24); |
1918june | 0:930d2bc16788 | 40 | wait_ms(100); |
1918june | 0:930d2bc16788 | 41 | /*for(i=0;i<=11;i++) |
1918june | 0:930d2bc16788 | 42 | { |
1918june | 0:930d2bc16788 | 43 | pc.printf("%d\n",cmd[i]); |
1918june | 0:930d2bc16788 | 44 | pc.printf("recieve = %d\n",recieve[i]); |
1918june | 0:930d2bc16788 | 45 | }*/ |
1918june | 0:930d2bc16788 | 46 | RFID.PCD_Init(); |
1918june | 0:930d2bc16788 | 47 | lcd.LCD_init(); |
1918june | 0:930d2bc16788 | 48 | lcd.backlight(ON); |
1918june | 0:930d2bc16788 | 49 | lcd.LCD_write_string(0,0,"SCAN ID CARD",0); |
1918june | 0:930d2bc16788 | 50 | wait(1); |
1918june | 0:930d2bc16788 | 51 | lcd.LCD_clear(); |
1918june | 0:930d2bc16788 | 52 | while(1) |
1918june | 0:930d2bc16788 | 53 | { |
1918june | 0:930d2bc16788 | 54 | // if( |
1918june | 0:930d2bc16788 | 55 | |
1918june | 0:930d2bc16788 | 56 | if ( ! RFID.PICC_IsNewCardPresent()) // Look for new cards |
1918june | 0:930d2bc16788 | 57 | { |
1918june | 0:930d2bc16788 | 58 | wait_ms(500); |
1918june | 0:930d2bc16788 | 59 | continue; |
1918june | 0:930d2bc16788 | 60 | } |
1918june | 0:930d2bc16788 | 61 | if ( ! RFID.PICC_ReadCardSerial()) // Select one of the cards |
1918june | 0:930d2bc16788 | 62 | { |
1918june | 0:930d2bc16788 | 63 | wait_ms(500); |
1918june | 0:930d2bc16788 | 64 | continue; |
1918june | 0:930d2bc16788 | 65 | } |
1918june | 0:930d2bc16788 | 66 | //for(i=0;i<=11;i++){ |
1918june | 0:930d2bc16788 | 67 | // pc.printf("%d\n",cmd[i]); |
1918june | 0:930d2bc16788 | 68 | // pc.printf("%d\n",recieve[i]);} |
1918june | 0:930d2bc16788 | 69 | pc.printf("Card UID: "); |
1918june | 0:930d2bc16788 | 70 | for (uint8_t i = 0; i < RFID.uid.size; i++) |
1918june | 0:930d2bc16788 | 71 | { |
1918june | 0:930d2bc16788 | 72 | pc.printf(" %d", RFID.uid.uidByte[i]); |
1918june | 0:930d2bc16788 | 73 | } |
1918june | 0:930d2bc16788 | 74 | printf("\n\r"); |
1918june | 0:930d2bc16788 | 75 | |
1918june | 0:930d2bc16788 | 76 | if( RFID.uid.uidByte[0]==recieve[0] && RFID.uid.uidByte[1]==recieve[1] && RFID.uid.uidByte[2]==recieve[2] && RFID.uid.uidByte[3]==recieve[3] ) |
1918june | 0:930d2bc16788 | 77 | { |
1918june | 0:930d2bc16788 | 78 | pc.printf("Kritayos Thongtem\t\t%d3405000%d\n",recieve[4],recieve[5]); |
1918june | 0:930d2bc16788 | 79 | lcd.LCD_write_string(0,0,"Tuek",0); |
1918june | 0:930d2bc16788 | 80 | } |
1918june | 0:930d2bc16788 | 81 | if( RFID.uid.uidByte[0]==recieve[6] && RFID.uid.uidByte[1]==recieve[7] && RFID.uid.uidByte[2]==recieve[8] && RFID.uid.uidByte[3]==recieve[9] ) |
1918june | 0:930d2bc16788 | 82 | { |
1918june | 0:930d2bc16788 | 83 | pc.printf("Natthanicha Jamroonpan\t\t%d3405000%d\n",recieve[10],recieve[11]); |
1918june | 0:930d2bc16788 | 84 | char C[2]; |
1918june | 0:930d2bc16788 | 85 | C[0]=recieve[5]; |
1918june | 0:930d2bc16788 | 86 | C[1]=recieve[6]; |
1918june | 0:930d2bc16788 | 87 | lcd.LCD_write_string(0,0,C,0); |
1918june | 0:930d2bc16788 | 88 | } |
1918june | 0:930d2bc16788 | 89 | |
1918june | 0:930d2bc16788 | 90 | } |
1918june | 0:930d2bc16788 | 91 | |
1918june | 0:930d2bc16788 | 92 | } |
1918june | 0:930d2bc16788 | 93 |