Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Try u2x mode first
  2. uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
  3. *_ucsra = 1 << U2X0;
  4.  
  5. // hardcoded exception for 57600 for compatibility with the bootloader
  6. // shipped with the Duemilanove and previous boards and the firmware
  7. // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
  8. // be > 4095, so switch back to non-u2x mode if the baud rate is too
  9. // low.
  10. if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
  11. {
  12. *_ucsra = 0;
  13. baud_setting = (F_CPU / 8 / baud - 1) / 2;
  14. }
  15.  
  16. // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
  17. *_ubrrh = baud_setting >> 8;
  18. *_ubrrl = baud_setting;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement