Esculapio Flores

BIGMAC,I tried to make this Wiegand routine and I failed.

Discussion created by Esculapio Flores on Sep 5, 2006
Latest reply on Apr 8, 2009 by Michael Roman
Hi Bigmac!,
In my eagerness to make the things well I tried to make this code to read a Wiegand device but I had no luck.
Here I attached for you the timing of this protocol so that you can see if it agrees with my code or not.
unsigned int Read20BitData(void) {                unsigned char count;        unsigned int bits;        count = 0;             //size of each word        bits = 0;        for(count = 0;count < 20;count++)                 {                 bits = bits << 2;  //<< 1;                 //make room for next bit by shifting the result                for (;PTA_PTA2 == 1;)    __RESET_WATCHDOG(); // feeds the dog //wait for clock edge                for (;PTA_PTA2 == 0;)    __RESET_WATCHDOG(); // feeds the dog wait for clock edge                                if ((PTA_PTA3) == 1)                                 bits|= 1;       //either set                         else bits &= ~0xfffffffe;  //or clear LSB in bits                };         return bits;   };        /*************************************************        *              main routine*************************************************/void main(void) {                        DDRA_DDRA2 = 0                DDRA_DDRA3 = 0; //set one pin as an output                        //make PTB2 an output  for(;;) {         result = Read20BitData();    //read 20 bit word        }   };


  First,I have no idea if the data are stored right well into the var.¿How can data be viewed by a simulator?...the var is called "result".
Second,The data from device are delivered in ASCII format  and my LCD routines converts the BCD data to ASCII so I imagine that I just need some ASCII to BCD or ASCII to Binary trick to rebuild the data and 
display the right values on LCD.¿how can I do this?.
My functions is like this:
void printf_LCD_4bits(unsigned char fila, unsigned char columna, char *texto,char value){ unsigned char adrs;      adrs = columna - 1;   if(fila == 2)    adrs = adrs | 0x40; Ctrl4bits(adrs | 0x80); while(*texto)     Datos4bits(*texto++); // Datos4bits(':');  //Datos4bits( ((value%1000)/100)+0x30);  //Datos4bits( ((value%100)/10)+0x30); ----->this converts BCD to ASCII.I need the opposite  //Datos4bits( (value%10)+0x30);Datos4bits( (value%10)+0x30);}

Thank you BIG.
Have a nice week.

Message Edited by Alban on 2006-09-06 01:55 PM