fork(1) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <math.h>
  4.  
  5. typedef unsigned char uint8;
  6.  
  7. int main(void) {
  8.  
  9. #define F_CPU 1000000UL
  10. #define BAUD_RATE 9600
  11. #define FACTOR_8_16 8
  12.  
  13. unsigned char UBRRH;
  14. unsigned char UBRRL;
  15. /*calculate UBBR value */
  16. uint16_t UBBR_value = F_CPU / (FACTOR_8_16 * BAUD_RATE) - 1;
  17. //Put the upper part of the UBBR value here (bits 8 to 11)
  18. UBRRH = (uint8)(UBBR_value >> 8);
  19. //Put the remaining part of the UBBR value here
  20. UBRRL = (uint8)UBBR_value;
  21.  
  22. printf("Without float: UBRRL = %d, UBRRH = %d\n", UBRRL, UBRRH);
  23.  
  24. /*calculate UBBR value */
  25. UBBR_value = lrint((F_CPU / (FACTOR_8_16 * (float)BAUD_RATE)) - 1);
  26. //Put the upper part of the UBBR value here (bits 8 to 11)
  27. UBRRH = (uint8)(UBBR_value >> 8);
  28. //Put the remaining part of the UBBR value here
  29. UBRRL = (uint8)UBBR_value;
  30.  
  31. printf("With float: UBRRL = %d, UBRRH = %d\n", UBRRL, UBRRH);
  32. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Without float: UBRRL = 12, UBRRH = 0
With float: UBRRL = 12, UBRRH = 0