Revision 1084
Added functions for printing hexadecimal numbers to USB, see serial.h
serial.c | ||
---|---|---|
276 | 276 |
|
277 | 277 |
return 0; |
278 | 278 |
} |
279 |
|
|
280 |
/** |
|
281 |
* Determines a hexadecimal digit in ASCII code. |
|
282 |
* |
|
283 |
* @param value the value of the digit (0<=value<=15) |
|
284 |
* |
|
285 |
* @return the hexadecimal digit in ASCII code, or '?' |
|
286 |
* if the input is invalid. |
|
287 |
**/ |
|
288 |
uint8_t hex_digit (uint8_t value) |
|
289 |
{ |
|
290 |
if (value>15) return '?'; |
|
291 |
// Postcondition: 0<=x<=15 |
|
292 |
|
|
293 |
return "0123456789ABCDEF"[value]; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* Prints a fixed width hexadecimal representation of an unsigned |
|
298 |
* 16 bit integer in ASCII code to USB. |
|
299 |
* usb_init must be called before this function can be used. |
|
300 |
* |
|
301 |
* @param value the value to print |
|
302 |
* |
|
303 |
* @see usb_init, usb_puti, usb_puts, usb_puth8, hex_digit |
|
304 |
**/ |
|
305 |
void usb_puth16 (uint16_t value) |
|
306 |
{ |
|
307 |
usb_putc (hex_digit((value >>12)&0xF)); |
|
308 |
usb_putc (hex_digit((value >>8 )&0xF)); |
|
309 |
usb_putc (hex_digit((value >>4 )&0xF)); |
|
310 |
usb_putc (hex_digit( value &0xF)); |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Prints a fixed width hexadecimal representation of an unsigned |
|
315 |
* 8 bit integer in ASCII code to USB. |
|
316 |
* usb_init must be called before this function can be used. |
|
317 |
* |
|
318 |
* @param value the value to print |
|
319 |
* |
|
320 |
* @see usb_init, usb_puti, usb_puts, usb_puth16, hex_digit |
|
321 |
**/ |
|
322 |
void usb_puth8(uint8_t value) |
|
323 |
{ |
|
324 |
usb_putc (hex_digit ((value)>>4 &0xF)); |
|
325 |
usb_putc (hex_digit ( value &0xF)); |
|
326 |
} |
|
327 |
|
Also available in: Unified diff