Created
June 15, 2011 06:21
-
-
Save jasoncigar/1026585 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef USART_H_ | |
#define USART_H_ | |
void USARTInit(void); | |
void USARTInitRecieverInterrupt(void); | |
int USARTSendByte(char data, FILE *stream); | |
int USARTReceiveByte(FILE *stream); | |
int USARTReceiveByteWithoutEcho(FILE *stream); | |
void USARTInit(void) | |
{ | |
UCSRA=0x00; | |
UCSRB=0x18; | |
UCSRC=0x86; | |
UBRRH=0x00; | |
UBRRL=0x67; | |
} | |
void USARTInitRecieverInterrupt(void) | |
{ | |
UCSRA=0x00; | |
UCSRB=0x98; | |
UCSRC=0x86; | |
UBRRH=0x00; | |
UBRRL=0x67; | |
} | |
int USARTSendByte(char data, FILE *stream) | |
{ | |
if(data == '\n') | |
{ | |
USARTSendByte('\r', 0); | |
} | |
while(!(UCSRA&(1<<UDRE))){}; | |
UDR = data; | |
return 0; | |
} | |
int USARTReceiveByte(FILE *stream) | |
{ | |
char data; | |
while(!(UCSRA&(1<<RXC))){}; | |
data=UDR; | |
USARTSendByte(data,stream); | |
return data; | |
} | |
int USARTReceiveByteWithoutEcho(FILE *stream) | |
{ | |
uint8_t data; | |
while(!(UCSRA&(1<<RXC))){}; | |
data=UDR; | |
return data; | |
} | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment