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 } };
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);}
Message Edited by Alban on 2006-09-06 01:55 PM
Message Edited by bigmac on 2006-09-06 05:45 AM