Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #include <stdio.h>
- #include <avr/io.h>
- #include "debuguart.h"
- inline void fulldelay(void)
- {
- volatile int i;
- for (i = 0; i < 44; i ++);
- }
- inline void debuguart_high(void)
- {
- PORTC |= 1<<PC0;
- }
- inline void debuguart_low(void)
- {
- PORTC &= ~(1<<PC0);
- }
- void debuguart_init(void)
- {
- DDRC = (1 << DDC0);
- debuguart_high();
- /* This is for printf */
- static FILE mystdout =
- FDEV_SETUP_STREAM(debuguart_putchar, NULL, _FDEV_SETUP_WRITE);
- stdout = &mystdout;
- }
- void debuguart_sendbyte(uint8_t c)
- {
- /* start bit */
- debuguart_low();
- fulldelay();
- if (c & 1) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 2) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 4) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 8) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 16) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 32) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 64) debuguart_high(); else debuguart_low();
- fulldelay();
- if (c & 128) debuguart_high(); else debuguart_low();
- fulldelay();
- /* parity thingie */
- debuguart_high();
- fulldelay();
- }
- int debuguart_putchar(char c, FILE *stream)
- {
- if (c == '\n') {
- debuguart_sendbyte('\r');
- }
- debuguart_sendbyte(c);
- return 0;
- }
- /* vim: set sw=4 et: */
Add Comment
Please, Sign In to add comment