cli()
before these routines and restore interruptswith sei()
later as the code is not guaranteed to behave if interrupts stealtoo much CPU time.uartcfg.h
.Adjust these for your project, and in your code, include uart.h
.uart_init()
somewhere in your hardware initialisation, and you shouldbe set to send short strings to the UART for debugging purposes.2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 | #include <avr/io.h> #include 'uart.h' #define UART_SET_BIT(port,bit) (port |= (1 << bit)) #define UART_CLEAR_BIT(port,bit) (port &= ~(1 << bit)) #define UART_BIT_WAIT() _delay_us(1000000.0 / (float) UART_BPS) #define UART_SEND_HIGH() {UART_CLEAR_BIT(UART_TX_PORT, UART_TX_PIN); UART_BIT_WAIT();} #define UART_SEND_LOW() {UART_SET_BIT(UART_TX_PORT, UART_TX_PIN); UART_BIT_WAIT();} uint8_t uart_setup(void){ UART_SET_BIT(UART_TX_PORT,UART_TX_PIN); } voiduart_putc(charc){ // start bit while(i){ UART_SEND_LOW(); UART_SEND_HIGH(); c=c>>1; } UART_SEND_LOW(); while(*s){ s++; } |