CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RFID. need help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jinggy



Joined: 20 May 2008
Posts: 9
Location: malaysia

View user's profile Send private message MSN Messenger

RFID. need help
PostPosted: Wed Jun 11, 2008 8:43 pm     Reply with quote

hello all.

i'm using a RFID reader module from parallax
[url]
http://www.parallax.com/dl/docs/prod/audiovis/RFID-Reader-v1.1.pdf [/url] to read 12-byte tags and display on a LCD screen.

but instead of getting ID such as 0F02A670DF or 0F02A66F79, i get some weird symbols like {6/ @ ^ &). anybody knows why?

here's my codes:

Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV2,VREGEN
#use delay(clock=48000000)

#include <lcd.c>

#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define TX PIN_C6

#use rs232(baud = 2400, rcv = PIN_C7)

void main( void )
{
  int i=0;
  byte buf[12];

lcd_init();
output_low(PIN_C6);
delay_ms(2000);

   for (i=0;i<12;i++) {
       buf[i] = getc();
   }
   for (i=0;i<12;i++) {
       lcd_putc(buf[i]);
    }
while(1);
}


thanks in advance!
Ttelmah
Guest







PostPosted: Thu Jun 12, 2008 2:26 am     Reply with quote

Obvious thing, check your clock rate.
From what you show, you have a 20MHz crystal?.
PLL5, is then correct. Otherwise this needs to change.
Then CPUDIV2, will give you a master clock at _24MHz_, not the 48MHz that you have selected in the clock statement. I'd suspect this is the problem.

The dividers here are really designed to 'confuse'. Available dividers are /1, /2, /3, and /4. When fed from the crystal source, they work as named. However from the USB clock, they are each effectively doubled in the division given!... I prefer to think that the USB clock actually comes from after the /2 divider in the USB chain, rather than before this. Not what the diagram shows, but it is what happens!. If you look carefully at table 2-3 (oscillator configuration), for your crystal, they show CPUDIV1:CPUDIV0, having to be selected as '00', for 48MHz. This is the selection that gives /1, when using the external crystal (look at figure 2-1), so the fuses need to be set to CPUDIV1...

Select this. I think you will find it starts to work.
However, add the C6 transmit pin to your UART definition (otherwise you will be using a software UART). You don't have to use the pin, but the definition needs to be there to tell the compiler to use the hardware UART. Also add the 'ERRORS' define to this.
Then use the same method shown in the example code, don't wait for two seconds, but wait for the start character, or you may be 'out of sync' with the incoming data. So:
Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

#include <lcd.c>

#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define TX PIN_C6

#use rs232(baud = 2400, rcv = PIN_C7,xmit=PIN_C6,ERRORS)

void main( void )
{
  int i=0;
  byte buf[12];

  lcd_init();
  output_low(PIN_C6);
  while (getc() != 0x0A) ; //wait for the tag

  //Now only have 11 characters to read
  for (i=0;i<11;i++) {
     buf[i] = getc();
  }
  for (i=0;i<11;i++) {
     lcd_putc(buf[i]);
  }
  while(1);
}


Best Wishes
jinggy



Joined: 20 May 2008
Posts: 9
Location: malaysia

View user's profile Send private message MSN Messenger

PostPosted: Thu Jun 12, 2008 3:23 am     Reply with quote

thanks a lot Ttelmah!!!

it works! finallyyy Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group