|
|
View previous topic :: View next topic |
Author |
Message |
atomy_kwang
Joined: 28 Jun 2008 Posts: 24
|
USART Problem , help me please |
Posted: Sun Dec 14, 2008 1:18 am |
|
|
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
#bit PIND0 = 0x08.0
#define use_portb_lcd
#include <lcd.c>
BYTE RxdataBuff[21];
BYTE sel_card[4]={0xBA,0x02,0x01,0xB9};//Select mifare card command
//Return 10 bytes
BYTE byte_length;
void lcd_clr_line(unsigned char j)
{
lcd_gotoxy(1,j);
lcd_putc(" ");
}
void main()
{
BYTE i ;
char Cardf_Str[] = "Selected Card" ; // Card selected string for 0x00 status
char Notag_Str[] = "No tag"; // No tag string for 0x01 status
char Colli_Str[] = "Collision occur"; //Collision occur string for 0x0A status
char Chksm_Str[] = "Checksum error"; // Checksum error string for 0xF0 status
PIND0=1;
lcd_init();
lcd_gotoxy(1,1); // Set LCD position , x = position , y = line
while(TRUE)
{
lcd_gotoxy(1,1);
for(i=0;i<6;i++)
lcd_putc(Notag_Str[i]); // Print "No tag" on LCD
while(PIND0==1);
lcd_gotoxy(1,1);
lcd_putc("Detect card");
for(i=0;i<4;i++)
{
putc(sel_card[i]);
delay_ms(100);
}
delay_ms(80);
if(getc()==0xBD)
{
byte_length = getc();
for(i=0;i<byte_length;i++)
{
RxdataBuff[i] = getc();
}
lcd_gotoxy(1,1);
switch(RxdataBuff[1])
{
case 0x00: for(i=0;i<12;i++)
lcd_putc(Cardf_Str[i]); // Print "card selected" on LCD
lcd_gotoxy(1,2);
lcd_putc("SN: ");
for(i=2;i<6;i++)
{
printf(lcd_putc,"%X",RxdataBuff);
}
break;
case 0x01: for(i=0;i<6;i++)
lcd_putc(Notag_Str);
lcd_clr_line(2);
break;
case 0x0A: for(i=0;i<14;i++)
lcd_putc(Colli_Str); // Print "Collision occur" on LCD
lcd_clr_line(2);
break;
case 0xF0: for(i=0;i<13;i++)
lcd_putc(Chksm_Str); // Print "Checksum error" on LCD
lcd_clr_line(2);
break;
}
}
else
{
lcd_gotoxy(1,1);
lcd_putc("Cardreader error");
}
}
}
my code did not work
The probrem is sending the data
for(i=0;i<4;i++)
{
putc(sel_card[i]);
delay_ms(100);
}
and wait for response from module rfid
then I will bring data from it to compare in the switch case
I have an example from PSOC
http://narong.ee.engr.tu.ac.th/microlab/doc/rfid/
but I try to use PIC on it
Help me
Thank you every one |
|
|
Ttelmah Guest
|
|
Posted: Sun Dec 14, 2008 4:20 am |
|
|
First, learn to use the 'code' buttons to post code.
Second, some very obvious things wrong. You define 'PIND0', to talk directly to the PIN I/O register, but never set the TRIS for this. You don't use the CCS functions, which will do this automatically. You are both reading and writing to this pin...
You then have a 'clear line' function, which doesn't. It only clears a single character.
Then after you send the 'sel_card' data, it is 180mSec, before you start reading the serial. Does the unit pause for this long?. If not, data _will_ have been lost, and the UART almost certainly locked up (you have not got 'errors' in the UART definition, which would clear the lock up, but still leave the data lost...).
Many more I'm sure...
Best Wishes |
|
|
atomy_kwang
Joined: 28 Jun 2008 Posts: 24
|
|
Posted: Sun Dec 14, 2008 11:15 am |
|
|
Could you help me for a code , Ttelmah ?
Thank you |
|
|
azHer
Joined: 01 May 2008 Posts: 7
|
Re: USART Problem , help me please |
Posted: Tue Mar 31, 2009 12:42 am |
|
|
Hai Atomy! Do you have success to interface your 16f877 to Rfid module?
I also want to try that module. Is it ok to start with command to Control Red Led?
Just to get some idea. |
|
|
|
|
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
|