loggin
Joined: 23 Sep 2010 Posts: 10
|
RFID, U2270 and Manchester decode... |
Posted: Mon Jul 04, 2011 11:52 am |
|
|
Hello to all!
I've got a problem with manchester decoding. I receive almost a code but something goes wrong. I receive not the right bytes. I need help about this code or if You can offer me other one. Here is the code:
Code: |
#bit INTEDG0 = 0xFF1.6
#bit B0 = 0xF81.0 //Interrupt PIN B0
int Bit_Counter = 0;
int Decode_Value;
BYTE buff[64] = {0};
int a;
enum decode_enum
{
IDLE = 0,
SYNCH_START,
DECODE,
DECODE_1,
ERROR
};
int Decode_State = IDLE;
#int_EXT
void EXT_isr(void)
{
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
switch(Decode_State)
{
case IDLE:
set_timer0(0);
Decode_State = SYNCH_START;
INTEDG0 = 1;
break;
case SYNCH_START:
if(get_timer0() > 300*5*2)
{
Decode_State = IDLE;
}
else if(get_timer0() > 210*5*2 && get_timer0() < 300*5*2)
{
Bit_Counter++;
Decode_Value |= 0x00 | INTEDG0 ;
// buff[0] = B0;
Decode_State = DECODE;
}
else
{
Decode_State = ERROR;
}
set_timer0(0);
break;
case DECODE:
if(get_timer0() > 90*5*2 && get_timer0() < 180*5*2)
{
Decode_State = DECODE_1;
}
else if(get_timer0() > 210*5*2 && get_timer0() < 300*5*2)
{
Bit_Counter++;
Decode_Value = Decode_Value | (B0 << Bit_Counter);
buff[Bit_Counter] = B0;
if(Bit_Counter == 64)
{
Bit_Counter = 0;
disable_interrupts(INT_EXT);
for(a=0;a<64;a++)
{
putc(buff[a]);
}
enable_interrupts(INT_EXT);
}
}
else
{
Decode_State = ERROR;
}
set_timer0(0);
break;
case DECODE_1:
if(get_timer0() > 90*5*2 && get_timer0() < 180*5*2)
{
Bit_Counter++;
Decode_Value = Decode_Value | (B0<< Bit_Counter);// putc(Decode_Value);
if(Bit_Counter == 7)
{
Bit_Counter = 0;
disable_interrupts(INT_EXT);
for(a=0;a<64;a++)
{
putc(buff[a]);
}
enable_interrupts(INT_EXT);
}
Decode_State = DECODE;
}
else
{
Decode_State = ERROR;
}
set_timer0(0);
break;
case ERROR:
Decode_State = IDLE;
Decode_Value = 0;
Bit_Counter = 0;
break;
}
INTEDG0 = !INTEDG0;
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER0);
}
#INT_TIMER0
void TIMER0_isr(void)
{
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
Decode_State = IDLE;
Decode_Value = 0;
Bit_Counter = 0;
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER0);
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); //13.1 ms overflow
enable_interrupts(INT_EXT); //Enable EXTernal INTerrupt (B0), High to Low edge
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
set_tris_a(0x00);
set_tris_b(0x01);
while(true)
{
}
}
|
Using 18F4550, 20Mhz Q
Is this the right approach and algorithm? In this code I just want to receive for example 8 bytes (or 11!) from RFID card. Timer0 cycle 0.2us. Baudrate out of U2270 1,95kb/s.
Thank You in advance!
Best Regards! |
|