Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /*
  2. * uart.h
  3. *
  4. * Created: 12/10/2019 2:50:11 PM
  5. * Author: dspuser
  6. */
  7.  
  8.  
  9.  
  10. #ifndef UART_H_
  11. #define UART_H_
  12.  
  13. #include <avr/io.h>
  14. #include <avr/interrupt.h>
  15. #include <util/delay.h>
  16. #define F_CPU 14745600UL
  17. #define BAUD 9600
  18. #define UBRR ((8/(16*BAUD))-1)
  19.  
  20. void UART_Init();
  21. void UART_sendByte(char ch);
  22. void UART_sendStr(char *ch);
  23.  
  24.  
  25.  
  26. #endif /* UART_H_ */
  27.  
  28. /*
  29. * CFile1.c
  30. *
  31. * Created: 12/10/2019 2:23:48 PM
  32. * Author: dspuser
  33. */
  34.  
  35. #include "uart.h"
  36.  
  37. void UART_Init()
  38. {
  39. UCSRC = 0<<URSEL;
  40. UBRRL = UBRR;
  41. UBRRH = (UBRR>>8);
  42. UCSRA = (0<<U2X) | (0<<MPCM);
  43. UCSRB = (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2);
  44. UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
  45. }
  46.  
  47. void UART_sendByte(char ch)
  48. {
  49. while(!(UCSRA & (1<<UDRE)))
  50. {
  51. UDR = ch;
  52. }
  53. }
  54.  
  55. void UART_sendStr(char *ch)
  56. {
  57. char i=0;
  58. while(ch[i]!=0)
  59. {
  60. UART_sendByte(ch[i]);
  61. i++;
  62. }
  63. }
  64.  
  65. /*
  66. * GccApplication3.c
  67. *
  68. * Created: 12/10/2019 2:23:31 PM
  69. * Author : dspuser
  70. */
  71.  
  72. #include "uart.h"
  73.  
  74.  
  75. int main(void)
  76. {
  77. char c = "c";
  78. UART_Init();
  79. /* Replace with your application code */
  80. while (1)
  81. {
  82. UART_sendStr(c);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement