Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/19/07 08:40
Modified:
  02/19/07 08:48

Read: times


 
#133228 - incorrect readings when changing cards
Responding to: ???'s previous message
Russel,
that was an old version, i'm masking the bits now.
now it works...sometimes it reads the data incorect.
Also when i change cards the reading is incorrect! the first reading with the second card is incorrect!

OUTPUT:
where i nr of bytes read
s have start
S have stop
nrb number of bits
char nr is number of calls of interrupt function
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@=O
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@=O
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@=O
----i change card here-----
i:0 s:0 S:0 EA:1 nrb:0 nr:250 0
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@LO
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@LO
---- first card again ----
i:0 s:0 S:0 EA:1 nrb:4 nr:254 0
i:4 s:1 S:1 EA:1 nrb:0 nr:45 J1@=O
I don't understand why nr of calls of ISR is around 250 and no start sentinel is found!

<p>#include <reg51.h>

#include <stdio.h></p>
<p>//extern void init(void);

unsigned char port1;

//sbit p3_b7 = port3 ^ 7;

unsigned char nrb=0;

unsigned char my_byte[15];

unsigned char have_start;

unsigned char have_stop;

unsigned char i;

unsigned char nr;</p>
<p> </p>
<p>void alarm (void) interrupt 2

{

if (have_stop==0){

nr++;

//bit bb ;

//port3=(~P3)&0x80;

port1=(~P1)&0x01;

my_byte[i]=my_byte[i]<<1;

my_byte[i]=my_byte[i]+port1; ////writing bit in byte

nrb++;//increment number of bits

if (nrb==5){

            if (have_start==0)//we don't have a START yet

            {                      if ((my_byte[i]&0x1f)==0x1A)  //have we found a start?

                                    {

                                     if (i<14)

                                      { i++;     }           //found start so increment i

                                     have_start=1;

                                    }

                                    else      //we don't have a start yet and this is not a start!

                                                {

                                                //if (i<14)

//                                              {i++;}   //trebuie sters asta                                          

                                                 my_byte[i]=0x0;    //we clear my byte

                                                 }

                        }                     

                        else ///we read a start in the past

                        {

                        if ((my_byte[i]&0x1f)==0x1F) //byte read not end sentinel

                        {

                        have_stop=1;

                        //EA=0;

                        }

                        else{

                         if (i<14)   {

                          i++;        }

                          }

                        }                     

            nrb=0;  //set number of bits to 0

}</p>
<p>/*

port3=port3&0x80;

port3=port3>>7;

port3=~port3;*/

//i=10;

}

}

init_all()

{

SM1=1;

REN=1;

TMOD=0x20;

TH1=0xFD; //=253

TR1=1;

EA=1;

EX1=1;

IT1=1;

}</p>
<p> </p>
<p>void main (void)  {       

char c;

char j;

init_all();

have_start=0;

have_stop=0;

i=0;   

nr=0;

  printf ("Hello World!\n");         /* the 'printf' function call */</p>
<p> </p>
<p>while1:

                        c = _getkey ();

                        printf(" i:%d s:%d S:%d EA:%d nrb:%d nr:%d ",i,have_start,have_stop,EA,nrb,nr);

                        for(j=0;j<=i;j++)                           

                                    {

                                    putchar ( my_byte[j]+48); 

            my_byte[j]=0x0;

             }

   printf("\n");

            have_start=0;

            have_stop=0;

            nrb=0;

            i=0;

            //EA=1;//start again the global intterup service

            nrb=0;

            for(j=0;j<=15;j++)                           

                        {

                        my_byte[j]=0x0;

             }

            printf(" i:%d s:%d S:%d EA:%d nrb:%d nr:%d\n ",i,have_start,have_stop,EA,nrb,nr);

   nr=0;

   nrb=0;

goto while1;</p>
<p>}          </p>


List of 24 messages in thread
TopicAuthorDate
Reading a ISO7811 card with AT89c2051            01/01/70 00:00      
   You need to clear my_byte[]!            01/01/70 00:00      
      i\'m already doing that            01/01/70 00:00      
         Clearer?            01/01/70 00:00      
            done that; same thing + the code            01/01/70 00:00      
               Difference between right and wrong..            01/01/70 00:00      
                  rigth and wrong            01/01/70 00:00      
                     Are those the actual results?            01/01/70 00:00      
                        here are the actual values            01/01/70 00:00      
                           Did you do as Russell suggested?            01/01/70 00:00      
                              I clear my_byte            01/01/70 00:00      
                                 I am Confused...            01/01/70 00:00      
                                    byte_meu is my_byte            01/01/70 00:00      
                           Look for the start sentinel            01/01/70 00:00      
                              Start and end sentinel !            01/01/70 00:00      
                                 Masking            01/01/70 00:00      
                                    incorrect readings when changing cards            01/01/70 00:00      
                                       Dont count bits until you have the sentinel!            01/01/70 00:00      
                                          Not necessarily garbage either....            01/01/70 00:00      
                                          THANKS !!!!! It works!!            01/01/70 00:00      
   Credit Card Reader Using a PIC12C509            01/01/70 00:00      
      How does your code work?            01/01/70 00:00      
         a bug ! and another problem            01/01/70 00:00      
      Credit Card Hex PIC12F629            01/01/70 00:00      

Back to Subject List