GabrielVinicios
Joined: 27 May 2011 Posts: 2
|
Problems between RFID and PIC |
Posted: Fri May 27, 2011 3:13 pm |
|
|
I bought a RFID-12 and i´ve looking for a solution to communicate it with uC PIC16F628A. I found two ways to follow:
- Using RS232 protocol;
- Using the example in the file ex_rfid.c, that exists in the folder examples.
I´ve tried to communicate it with RS232 and it doesn´t work. Look at my code:
Code: |
#include "C:\Users\Thiago\Desktop\eletronica\PIC1\rfid.h"
#use rs232(baud=2400,parity=N,xmit=PIN_a2,rcv=PIN_a1,bits=8,stream=ID12)
#define LCD_DATA_PORT getenv("SFR:PORTB")
#define LCD_ENABLE_PIN PIN_b0
#define LCD_RS_PIN PIN_b2
#define LCD_RW_PIN PIN_b1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#define LCD_TYPE 2
#include <lcd.c>
void main()
{
char valor[12];
int aux;
char c;
lcd_init();
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
disable_interrupts(INT_RDA);
disable_interrupts(GLOBAL);
output_high(pin_a7);
lcd_putc("teste...");
while(TRUE) {
for (aux=0;aux<12;aux++){
valor[aux]=getc();
printf (lcd_putc,"%d",valor[aux]);
}
delay_ms(2000);
lcd_putc("\f");
}
} |
The LCD Display showed just it: -1 -1 -1 -1 -1 -1 -1
I tried also several bauds, like 9600, 2400, etc.
I found out another code in this forum, and it doesn´t work too. See:
Code: | #define RFID_START_BYTE 0x0A
#define RFID_END_BYTE 0x0D
void get_rfid_string()
{
int8 s[12];
unsigned int8 max=20;
unsigned int8 len;
char c;
// Wait for start byte
do
{
c = fgetc(ID12);
} while (c != RFID_START_BYTE);
// Receive data until END byte is received or buffer full
// correct for terminating zero
len=0;
s=0;
while ((c != RFID_END_BYTE) && (len < max))
{
c = fgetc(ID12);
s[len++] = c;
};
// fprintf(CPU, "%s\n", s);
printf(lcd_putc,"\f%s\n",s);
}
//3. Main program
VOID main()
{
printf(lcd_putc,"\f");
DO {
get_rfid_string();
} WHILE(TRUE);
} |
But in this case, nothing appears on the LCD.
What am I doing wrong?
I tried it with several tags...
Thank you so far. |
|