Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. /*
  2.  * demoApp.c
  3.  *
  4.  * Created: 18.10.2017. 02.02.01
  5.  * Author : Aleksandar
  6.  */
  7.  
  8. #define F_CPU 16000000UL
  9. #define BAUD 38400
  10. #define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)
  11.  
  12. #include <avr/io.h>
  13. #include <util/delay.h>
  14. #include <string.h>
  15.  
  16. #define setBit(sfr, bit) (sfr |= (1<<bit))
  17. #define clearBit(sfr, bit) (sfr &= ~(1<<bit))
  18. #define toggleBit(sfr, bit) (sfr ^= (1<<bit))
  19.  
  20. void initUART(){
  21.     UBRR0H = BAUDRATE<<8;
  22.     UBRR0L = BAUDRATE;
  23.     UCSR0B|= (1<<TXEN0)|(1<<RXEN0);                
  24.     UCSR0C|= (1<<UMSEL01)|(1<<UCSZ00)|(1<<UCSZ01);  
  25.  
  26. void transmit(uint8_t data){
  27.     while(!(UCSR0A & (1<<UDRE0)));
  28.     UDR0 = data;   
  29. }
  30.  
  31. void sendASCII(char string[]){
  32.     for(int i = 0; i < strlen(string); i++){
  33.         transmit(string[i]);
  34.     }
  35. }
  36.  
  37. int main(void)
  38. {
  39.     char demoString[100] = "Hello world";
  40.     initUART();
  41.     /* Replace with your application code */
  42.     while (1)
  43.     {
  44.        
  45.         sendASCII(demoString);
  46.         _delay_ms(1000);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement