Hello, I found a code for RTC using UART.
I understand almost all code, but I confused about BCD and ASCII conversion. I use google as much as I could, but I think my problem is specific.'cause I can't find a code like this (I'm reading books about C). Can anyone help me a little, or give me a brief explanation or something.
I know everyone has their own logic, and thats why I don't undestand this code, but I also know that experts can understand it.
char getbcd(void) { unsigned char c, buff[3], i=0; while(1) { c = getchar(); if(('0'<=c)&&(c<='9')&&(i<2)) { // Si c es dÃgito 0..9 y si i>0 buff[i++] = c; // Guardar en buffer putchar(c); // Eco } else if((c=='\b')&&(i)) { // Si c es BACKSPACE y si i>0 i--; // putchar(c); // Eco } else if((c=='\r')&&(i)) // Si c es ENTER y si i>0 break; // Salir del bucle } c = buff[0]-'0'; if (i>1) { // (i==2) c <<= 4; c |= (buff[1]-'0'); } return c; }
All about RTC is clear to me.
I repeat, I don't write this code :S. If my post is in the wrong place, forgive me. I don't want to use copy and paste, Im learning how to write my own codes.
THANKS IN ADVANCE and sorry i dont' speak good english