1 #include "pic32_c.h" 2 #include "debug.h" 3 4 /* Value output functions. */ 5 6 void bits(uint32_t reg) 7 { 8 vbits(REG(reg)); 9 } 10 11 void vbits(uint32_t val) 12 { 13 uint32_t mask; 14 15 for (mask = (1 << 31); mask; mask >>= 1) 16 if (val & mask) 17 uart_write('1'); 18 else 19 uart_write('0'); 20 21 uart_write('\r'); 22 uart_write('\n'); 23 } 24 25 void vhex(uint32_t val) 26 { 27 uint32_t mask; 28 uint8_t digit, shift; 29 30 for (mask = (0b1111 << 28), shift = 28; mask; mask >>= 4, shift -= 4) 31 { 32 digit = (val & mask) >> shift; 33 if (digit > 9) 34 uart_write('A' + digit - 10); 35 else 36 uart_write('0' + digit); 37 } 38 39 uart_write('\r'); 40 uart_write('\n'); 41 } 42 43 /* General output functions. */ 44 45 void uart_write(char c) 46 { 47 while (REG(UART_REG(1, UxSTA)) & (1 << 9)); /* UTXBF (buffer full) */ 48 49 REG(UART_REG(1, UxTXREG)) = c; 50 } 51 52 void uart_write_string(const char *s) 53 { 54 while (*s) 55 uart_write(*s++); 56 }