Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #define XTAL 8000000L
- #define BAUDRATE 9600L
- #define BAUDDIVIDER (XTAL/(16*BAUDRATE)-1)
- void init(void);
- void sendString(char *str);
- void sendByte(char byte);
- char *string = "I am USART test message";
- int main(void) {
- init();
- sei();
- sendString(string);
- return 0;
- }
- void init(void) {
- DDRB = 0xff;
- PORTB = 0xff;
- UBRRH = BAUDDIVIDER >> 8;
- UBRRL = BAUDDIVIDER & 0xFF;
- UCSRA = 0;
- UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE) | (1 << TXCIE) | (0 << UDRIE);
- UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
- }
- void sendString(char *str) {
- while(*str != '\0') {
- sendByte(*str);
- str++;
- }
- }
- void sendByte(char byte) {
- while(!(UCSRA & (1 << UDRE)));
- UDR = byte;
- }
Advertisement
Add Comment
Please, Sign In to add comment