??? 02/14/07 13:40 Modified: 02/14/07 14:04 Read: times |
#132895 - done that; same thing + the code Responding to: ???'s previous message |
i've changed 48 to '0'...
i don't get it... sometimes it reads the data correctly sometimes it doesn't. i don't find a rule here...maybe i'm missing something when the data readen is wrong, each time it's wrong it's the same...it's not something random! #include <reg51.h> #include <stdio.h> //extern void init(void); unsigned char port1; //sbit p3_b7 = port3 ^ 7; unsigned char nrb=0; unsigned char byte_meu[40]; unsigned char i=0; void alarm (void) interrupt 2 //enters when clock signal comes from card reader { if (i>30) EA=0;//after 30 characters we stop the interrupt port1=(~P1)&0x01; //reading data pin from P1, bit 1 byte_meu[i]=byte_meu[i]<<1; byte_meu[i]=byte_meu[i]+port1; //writing in a byte nrb++; if (nrb==5){ //go to the next location after 5 bits i++; nrb=0; //reset bit counter } } init_all() //serial init { SM1=1; REN=1; TMOD=0x20; TH1=0xFD; //=253 TR1=1; EA=1; EX1=1; IT1=1; P1=255; P3=255; } void main (void) { char c; unsigned char j; init_all(); printf ("Hello World!!\n"); while1: c= _getkey (); //wait for key printf(" i:%d \n",i); for(j=0;j<40;j++) { putchar ( byte_meu[j]+'0'); //send the data when key is pressed byte_meu[j]=0x0; //clear the data after we send it } nrb=0; //clears number of bits and i=0; //number of caracters read EA=1; //enables interrupt goto while1; } |