Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * uart.h
- *
- * Created: 12/10/2019 2:50:11 PM
- * Author: dspuser
- */
- #ifndef UART_H_
- #define UART_H_
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #define F_CPU 14745600UL
- #define BAUD 9600
- #define UBRR ((8/(16*BAUD))-1)
- void UART_Init();
- void UART_sendByte(char ch);
- void UART_sendStr(char *ch);
- #endif /* UART_H_ */
- /*
- * CFile1.c
- *
- * Created: 12/10/2019 2:23:48 PM
- * Author: dspuser
- */
- #include "uart.h"
- void UART_Init()
- {
- UCSRC = 0<<URSEL;
- UBRRL = UBRR;
- UBRRH = (UBRR>>8);
- UCSRA = (0<<U2X) | (0<<MPCM);
- UCSRB = (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2);
- UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
- }
- void UART_sendByte(char ch)
- {
- while(!(UCSRA & (1<<UDRE)))
- {
- UDR = ch;
- }
- }
- void UART_sendStr(char *ch)
- {
- char i=0;
- while(ch[i]!=0)
- {
- UART_sendByte(ch[i]);
- i++;
- }
- }
- /*
- * GccApplication3.c
- *
- * Created: 12/10/2019 2:23:31 PM
- * Author : dspuser
- */
- #include "uart.h"
- int main(void)
- {
- char c = "c";
- UART_Init();
- /* Replace with your application code */
- while (1)
- {
- UART_sendStr(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement