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 support@ccsinfo.com

RFID, U2270 and Manchester decode...

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



Joined: 23 Sep 2010
Posts: 10

View user's profile Send private message

RFID, U2270 and Manchester decode...
PostPosted: Mon Jul 04, 2011 11:52 am     Reply with quote

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!
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