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