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