Created
May 28, 2015 10:58
-
-
Save metrafonic/ae3bee3bf786acbc304e to your computer and use it in GitHub Desktop.
TX UART
This file contains hidden or 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
| #include <avr/io.h> | |
| #include"ButtonPress.h" | |
| int main(void) | |
| { | |
| DDRB |= 1 << PINB1; | |
| DDRB &= ~(1 << PINB0); | |
| PORTB |= 1 << PINB0; | |
| int UBBRValue = 25; | |
| //Put the upper part of the baud number here (bits 8 to 11) | |
| UBRRH = (unsigned char) (UBBRValue >> 8); | |
| //Put the remaining part of the baud number here | |
| UBRRL = (unsigned char) UBBRValue; | |
| //Enable the receiver and transmitter | |
| UCSRB = (1 << RXEN) | (1 << TXEN); | |
| //Set 2 stop bits and data bit length is 8-bit | |
| UCSRC = (1 << USBS) | (3 << UCSZ0); | |
| while (1){ | |
| if (ButtonPressed(0, PINB, 0, 100)){ | |
| PORTB ^= 1 << PINB1; | |
| //Wait until the Transmitter is ready | |
| while (! (UCSRA & (1 << UDRE)) ); | |
| //Get that data outa here! | |
| UDR = 0b11111111; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment