ATMEGA8 MFRC522 RFID

Ola,

Como não podia deixar de ser apos ter apresentado um dispositivo RFID em arduino tinha de conseguir fazer algo em AVR, neste caso usei o ATMEGA8.

A ideia é ter vários utilizadores autenticados associados aos IDs das Tags, neste caso foi configurado para 2, embora seja possível ter vários utilizadores.

As ligações do trabalho:

EsquemaRFIDRC522

 

Neste video podem verificar que duas tags são autenticadas a terceira esta negada.

 

 

Codigo fonte:

main of RFID RC522
/*
 * AVR-RFIDRC522.c
 * Created by Norlinux
 * Created: 16-09-2017
 *http://www.microelectronic.pt
 *https://www.facebook.com/MundoDosMicrocontroladores/
 *http://maquina.96.lt
 *Released under GPLv3.
 *Please refer to LICENSE file for licensing information.
 *which can be found at http://www.gnu.org/licenses/gpl.txt
 */
#include <avr/io.h>
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#include <util/delay.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
#include "spi.h"
#include "mfrc522.h"

#define NR_OF_CARDS  2
#define CARDS_SIZES  10

int main()
{
	uint8_t byte;
	uint8_t str[MAX_LEN];
	char string[MAX_LEN]={};
	char src[MAX_LEN];
	char buf[MAX_LEN];
	uint8_t user_nr=0;
	char name[NR_OF_CARDS][CARDS_SIZES] = {"Norlinux","Shimon"};
	char uID_CARDS[NR_OF_CARDS][CARDS_SIZES] = {"B0EAFD79DE","A16B703B81"};
	char check=0,ok=0;
	memset(string,0,sizeof(string));
	_delay_ms(50);
	LCDInit(LS_NONE);
	LCDWriteStringXY(2,0,"Ler RFID");

	spi_init();
	_delay_ms(1000);
	LCDClear();
	
	//init reader
	mfrc522_init();
	
	//check version of the reader
	byte = mfrc522_read(VersionReg);
	if(byte == 0x92)
	{
		LCDWriteStringXY(1,0,"MIFARE RC522v2");
		LCDWriteStringXY(3,1,"Detectado");
	}else if(byte == 0x91 || byte==0x90)
	{
		LCDWriteStringXY(1,0,"MIFARE RC522v1");
		LCDWriteStringXY(3,1,"Detectado");
	}else
	{
		LCDWriteStringXY(0,0,"Leitor Desconhecido");
	}
	
	byte = mfrc522_read(ComIEnReg);
	mfrc522_write(ComIEnReg,byte|0x20);
	byte = mfrc522_read(DivIEnReg);
	mfrc522_write(DivIEnReg,byte|0x80);
	
	_delay_ms(1500);
	LCDClear();
	
	while(1){
		byte = mfrc522_request(PICC_REQALL,str);
		if(byte == CARD_FOUND)
		{
			byte = mfrc522_get_card_serial(str);
			if(byte == CARD_FOUND)
			{
				for(byte=0;byte<8;byte++) 
				{	
					LCDHexDumpXY(byte*2,0,str[byte],string);
					if (byte==0)
					strcpy(src,string);
					else
					strcat(src, string);
					memset(string,0,sizeof(string));
				}
			}
			else
			{
				LCDWriteStringXY(0,1,"     Erro     ");
			}
			_delay_ms(2500);
			for (int i=0; i<NR_OF_CARDS; i++)
			{
				//sprintf(buf,"%d", i);
				//LCDWriteStringXY(8,1,buf);
				//_delay_ms(2500);
				for (int j=0; j<10; j++) 
				{
					if(src[j] == uID_CARDS[i][j]) 
					{
					//sprintf(buf,"%c", uID_CARDS[i][j]);
					//LCDWriteStringXY(0,1,buf);
					//_delay_ms(1000);
						check++;
						user_nr=i; 
						if(check==9)
						{
							check=0;
							ok=1;
							sprintf(buf,"user= %s  ", name[user_nr]);
							LCDWriteStringXY(0,1,buf);
							memset(src,0,sizeof(src));
							memset(string,0,sizeof(string));
						}

					}	
				}
			}
					if (ok)
					{
					LCDWriteStringXY(0,0," Insert New Card ");
					memset(src,0,sizeof(src));
					memset(string,0,sizeof(string));
					ok=0;
					}
					else
					{
					LCDClear();
					LCDWriteStringXY(0,0,"  Access Denied  ");
					memset(src,0,sizeof(src));
					memset(string,0,sizeof(string));
					ok=0;
					}			
		} // Card Found

		_delay_ms(1000);
	}
}

5 comentários

Passar directamente para o formulário dos comentários,

    • André Marques on 24 Outubro, 2017 at 10:40
    • Responder

    Bom dia,

    Gostaria de saber se era possivel disponibilizarem as bibliotecas spi.h e mfrc522.h.

    Com os melhores cumprimentos,
    André Marques

    1. Enviado para o e-mail pessoal,
      Obrigado pela participação

  1. Hi,
    can i please have your libreries for spi.h and mfrc522.h? i have my own, but it do not work. i can’t read the serial nummer of my cards.

    thank you

    Merlin Verlin

  2. You are welcome,

    Source Code Sent.

  3. Hello! I just want to contact you about the newest RFID UHF SOFTWARE for different businesses. We have software in different national languages. English, Chinese, Russian, Korean, Portuguese, Arabic and others.
    like on this VIDEO : https://www.youtube.com/user/ValeriyTomin/playlists
    Only contactless technology, long distance.
    – for mobile inventory
    – for retail
    – for jewelry
    – smart shelves
    – for hotels
    – anti-theft
    – for libraries
    – for access control
    – for parking
    – for production / factory
    – for laundry
    – for rental business
    – for conveyors and sorting
    – for personnel tracking and time tracking
    Details here: https://software.fresh222.com/
    If you are interested, please write to this address: info@fresh222.us

Deixe uma resposta

Your email address will not be published.

www.000webhost.com