Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * demoApp.c
- *
- * Created: 18.10.2017. 02.02.01
- * Author : Aleksandar
- */
- #define F_CPU 16000000UL
- #define BAUD 38400
- #define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)
- #include <avr/io.h>
- #include <util/delay.h>
- #include <string.h>
- #define setBit(sfr, bit) (sfr |= (1<<bit))
- #define clearBit(sfr, bit) (sfr &= ~(1<<bit))
- #define toggleBit(sfr, bit) (sfr ^= (1<<bit))
- void initUART(){
- UBRR0H = BAUDRATE<<8;
- UBRR0L = BAUDRATE;
- UCSR0B|= (1<<TXEN0)|(1<<RXEN0);
- UCSR0C|= (1<<UMSEL01)|(1<<UCSZ00)|(1<<UCSZ01);
- void transmit(uint8_t data){
- while(!(UCSR0A & (1<<UDRE0)));
- UDR0 = data;
- }
- void sendASCII(char string[]){
- for(int i = 0; i < strlen(string); i++){
- transmit(string[i]);
- }
- }
- int main(void)
- {
- char demoString[100] = "Hello world";
- initUART();
- /* Replace with your application code */
- while (1)
- {
- sendASCII(demoString);
- _delay_ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement