#define rxPin PORTF.B2 #define txPin PORTF.B8 #define LED PORTA.B2 #define LED2 PORTA.B3 #define LED3 PORTA.B5 #define Gomb PORTA.B4 sbit LCD_RS at LATD12_bit; sbit LCD_EN at LATD2_bit; sbit LCD_D4 at LATD3_bit; sbit LCD_D5 at LATD13_bit; sbit LCD_D6 at LATD5_bit; sbit LCD_D7 at LATD7_bit; sbit LCD_RS_Direction at TRISD12_bit; sbit LCD_EN_Direction at TRISD2_bit; sbit LCD_D4_Direction at TRISD3_bit; sbit LCD_D5_Direction at TRISD13_bit; sbit LCD_D6_Direction at TRISD5_bit; sbit LCD_D7_Direction at TRISD7_bit; // RFID R/W Module Commands // Number of bytes returned in () #define RFID_Read 0x01 // Read data from specified address, valid locations 1 to 33 (5) #define RFID_Write 0x02 // Write data to specified address, valid locations 3 to 31 (1) #define RFID_Login 0x03 // Login to tag with password (1) #define RFID_SetPass 0x04 // Change tag's password from old to new (1) #define RFID_Protect 0x05 // Enable/disable password protection (1) #define RFID_Reset 0x06 // Reset tag (1) #define RFID_ReadLegacy 0x0F // Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader #28140) (12) // Memory map/address locations for EM4x50 tag // Each address holds/returns a 32-bit (4 byte) value #define ADDR_Password 0 // Password (not readable) #define ADDR_Protect 1 // Protection Word #define ADDR_Control 2 // Control Word // ADDR 3-31 are User EEPROM area #define ADDR_Serial 32 // Device Serial Number #define ADDR_DeviceID 33 // Device Identification // Status/error return codes #define ERR_OK 0x01 // No errors #define ERR_LIW 0x02 // Did not find a listen window #define ERR_NAK 0x03 // Received a NAK, could be invalid command #define ERR_NAK_OLDPW 0x04 // Received a NAK sending old password (RFID_SetPass), could be incorrect password #define ERR_NAK_NEWPW 0x05 // Received a NAK sending new password (RFID_SetPass) #define ERR_LIW_NEWPW 0x06 // Did not find a listen window after setting new password (RFID_SetPass) #define ERR_PARITY 0x07 // Parity error when reading data // For use with RFID_ReadLegacy command #define LEGACY_StartByte 0x0A #define LEGACY_StopByte 0x0D void main() { int idx; char idd[16]; int rfidData[32]; //buffer for incoming data 12 bytes int a=0; CHECON = 0x32; AD1PCFG = 0xFFFF; TRISD = 0x0000; LATD = 0x0000; TRISF.B8=0; //TX LÁB KIMENET TRISF.B2=1; //RX LÁB BEMENET TRISA.B2=0; //LED KIMENET TRISA.B3=0; //LED KIMENET TRISA.B5=0; //LED KIMENET TRISA.B4=1; //gomb LATA = 0x0000; LATF = 0x0000; Lcd_Init(); // Initialize LCD UART1_Init(9600); //UART1 MODUL INIT delay_ms(100); UART2_Init(9600); //UART1 MODUL INIT delay_ms(100); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); delay_ms(10); while (1) { // Endless loop if(Gomb){ while(Gomb); UART1_Write_Text("!RW"); LED=1; //delay_ms(10); while(UART1_Tx_Idle() == 0); /*delay_ms(200); LED=0; delay_ms(100);*/ if (UART1_Tx_Idle() == 1) { UART1_Write(0x01); if (UART2_Data_Ready()){ LED2=1; } LED=1; } while(UART1_Tx_Idle() == 0); delay_ms(1); LED2=0; delay_ms(1); if (UART1_Tx_Idle() == 1) { UART1_Write(0x01); if (UART2_Data_Ready()){ LED2=1; } //LED2=1; } delay_ms(1); LED2=0; } //delay_ms(10); Lcd_Out(1,1,"ID: "); //while(!UART1_Data_Ready()); if (UART1_Data_Ready()) { // If data is received idx = UART1_Read(); // read the received data LED3=1; IntToStr(idx,idd); Lcd_Out(2,1,idd); } if (UART2_Data_Ready()){ LED2=1; } Delay_ms(10); LED=0; // LED2=0; LED2=0; //UART1_Write_Text("!RW"); delay_ms(1000); //Lcd_Cmd(_LCD_CLEAR); } }