//debug code int main(void){ char ch; char string[20]; // global to assist in debugging uint32_t n; PLL_Init(Bus50MHz); // 50 MHz UART_Init(); // initialize UART OutCRLF(); for(ch='A'; ch<='Z'; ch=ch+1){// print the uppercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar(' '); for(ch='a'; ch<='z'; ch=ch+1){// print the lowercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar('-'); UART_OutChar('-'); UART_OutChar('>'); while(1){ UART_OutString("InString: "); UART_InString(string,19); UART_OutString(" OutString="); UART_OutString(string); OutCRLF(); UART_OutString("InUDec: "); n=UART_InUDec(); UART_OutString(" OutUDec="); UART_OutUDec(n); OutCRLF(); UART_OutString("InUHex: "); n=UART_InUHex(); UART_OutString(" OutUHex="); UART_OutUHex(n); OutCRLF(); } }
//--------------------------UART_OutUHex---------------------------- // Output a 32-bit number in unsigned hexadecimal format // Input: 32-bit number to be transferred // Output: none // Variable format 1 to 8 digits with no space before or after void UART_OutUHex(uint32_t number){ // This function uses recursion to convert the number of // unspecified length as an ASCII string if(number >= 0x10){ UART_OutUHex(number/0x10); UART_OutUHex(number%0x10); } else{ if(number < 0xA){ UART_OutChar(number+'0'); } else{ UART_OutChar((number-0x0A)+'A'); } } }
static int _SH_HexDump(void) { char c[4]; int i, ret = 0; if(!_SH_cmd.args[0][0]) { fprintf(stderr, "Usage: %s <filename>\n", _SH_cmd.command); return 1; } if(eFile_ROpen(_SH_cmd.args[0])) { fprintf(stderr, "Error opening file for reading\n"); eFile_RClose(); return 1; } while(1) { for(i = 0; i < 4; i++) { unsigned long l; eFile_ReadNext(&c[0]); eFile_ReadNext(&c[1]); eFile_ReadNext(&c[2]); ret = eFile_ReadNext(&c[3]); l = ((c[3] << 24) | (c[2] << 16) | (c[1] << 8) | c[0]); UART_OutUHex(l); printf("\n"); if(ret || l == 0) { eFile_RClose(); printf("\n"); return 0; } } } }