Guest
|
rfid kit problems |
Posted: Thu Nov 02, 2006 12:50 pm |
|
|
Hi all,
I have problems to get the rfid example for the em4150 to work properly. The example should only check for the rfid chip and blink green if detected and red otherwise. The code below acts strange and little changes will have different effects on the behaviour. Right now the led blinks only red, but with different frequency dependend if a chip is near the antenna or not. err prints 1/0 so I think it recognizes the chip. But the led is red only?!
Maybe I am blind and doing something silly, but I can't see it.
I have the latest PCML (Linux version) of the compiler.
If it is not the silly me, could someone compile it with a recent windows version of the pcm compiler and send me the hex? Maybe it is a compiler issue or a driver problem.
my email is: caro33 at gmx dot net
Thanks a lot
Jens
Code: |
#include <16f876a.h>
//#device *=16
#fuses HS, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#use delay(clock=20000000)
#define RS485_ID 0x11
#define RS485_USE_EXT_INT FALSE
#define ADAPTER_RS485_ID 0x7F
#define GREEN_LED PIN_C3
#define YELLOW_LED PIN_C4
#define RED_LED PIN_C5
#include <rs485.c>
#include <em4095.c>
#include <em4150.c>
#include <stdlib.h>
int8 msg[32];
int32 rfid;
typedef enum {OFF, GREEN, RED} LEDcolor;
void twoColorLED(LEDcolor color)
{
switch(color) {
case OFF:
output_low(PIN_A3);
output_low(PIN_A5);
break;
case GREEN:
output_high(PIN_A3);
output_low(PIN_A5);
break;
case RED:
output_low(PIN_A3);
output_high(PIN_A5);
break;
}
}
void RS485send(char *s)
{
int8 size;
for(size=0; s[size]!='\0'; ++size);
rs485_wait_for_bus(FALSE);
while(!rs485_send_message(ADAPTER_RS485_ID, size, s)) {
delay_ms(RS485_ID);
}
}
void main(void)
{
int8 err;
rs485_init();
rf_init();
output_low(GREEN_LED);
sprintf(msg, "\r\n*** RFID-Reader V0.1 ***");
RS485send(msg);
for(;;) {
err = read_4150((int32 *)&rfid, 32);
sprintf(msg, "\r\n***Err: %d", err);
RS485send(msg);
switch(err) {
case ERR_OK:
twoColorLED(GREEN);
//sprintf(msg, "\r\n***Id: %lu (%d)", rfid, err);
//RS485send(msg);
break;
case ERR_LIW:
case ERR_NAK:
case ERR_PARITY:
default:
twoColorLED(RED);
}
delay_ms(250);
twoColorLED(OFF);
delay_ms(250);
}
}
|
|
|