Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 16000000UL // 1MHz
- #include <avr/io.h>
- #include <stdio.h>
- #include <util/delay.h>
- void init_uart(void);
- static int uart_putc(char data, FILE *stream);
- static FILE mystdout = FDEV_SETUP_STREAM(uart_putc, NULL, _FDEV_SETUP_WRITE);
- int main(void)
- {
- stdout=&mystdout;
- DDRB |= (1<<PB1);
- init_uart();
- while(1)
- {
- if (!(PINB & (1<<PB0)))
- {
- printf("AABBCC\r\n");
- PORTB |= (1<<PB1);
- _delay_ms(500);
- PORTB &= ~(1<<PB1);
- while (!(PINB & (1<<PB0))){}
- }
- }
- }
- void init_uart(void){
- UBRR1 = 103;
- UCSR1B = (1<<RXEN1)|(1<<TXEN1);
- }
- static int uart_putc(char data, FILE *stream){
- if (data == '\n') uart_putc('\r', stream);
- while (!(UCSR1A & (1<<UDRE1))){};
- UDR1 = data;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement