Advertisement
ReVerse

Untitled

Feb 13th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /*
  2.  * main.c
  3.  *
  4.  *  Created on: 12 lut 2016
  5.  *      Author: Pawel
  6.  */
  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9.  
  10. void USART_Transmit(char data);
  11. void USART_Init(uint16_t baud);
  12.  
  13. #define FOSC 8000000
  14. #define BAUD 9600
  15. #define MYUBBR FOSC/16/BAUD-1
  16.  
  17. int main(void)
  18. {
  19.     USART_Init(MYUBBR);
  20.     while(1)
  21.     {
  22.         USART_Transmit('B');
  23.         _delay_ms(1000);
  24.     }
  25. }
  26.  
  27.  
  28. void USART_Transmit(char data)
  29. {
  30.     while(!(UCSRA & (1<<UDRE)));
  31.     UDR = data;
  32. }
  33.  
  34. void USART_Init(uint16_t baud){
  35.     UBRRH = (uint8_t)(baud>>8);
  36.     UBRRL = (uint8_t)baud;
  37.     UCSRB = (1<<RXEN) | (1<<TXEN);
  38.     UCSRC = (1<<URSEL) | (3<<UCSZ0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement