Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void)
- {
- DDRA =0xFF;
- char data, olddata;
- int count = 0;
- //USARTInit(6); //9600 baud w/o 1<<u2x
- USARTInit(0); //115.2k baud
- PORTA = 0x00;
- bool lights = false;
- while(1)
- {
- //Read data
- data=USARTReadChar();
- if (data != olddata)
- {
- count++;
- PORTA = count;
- //PORTA = 0x00;
- //PORTA = data;
- olddata = data;
- USARTWriteChar(data);
- }
- //USARTWriteChar(data);
- }
- }//end of main
- void USARTInit(uint16_t ubrr_value)
- {
- //Set Baud rate
- UBRRL = ubrr_value;
- UBRRH = (ubrr_value>>8);
- /*Set Frame Format
- >> Asynchronous mode
- >> No Parity
- >> 1 StopBit
- >> char size 8
- */
- UCSRA = (1<<U2X);//double usart transmission speed
- UCSRC=(1<<URSEL)|(3<<UCSZ0);
- //Enable The receiver and transmitter
- UCSRB=(1<<RXEN)|(1<<TXEN);
- }
- //This function is used to read the available data
- //from USART. This function will wait until data is
- //available.
- char USARTReadChar(void)
- {
- //Wait until a data is available
- while(!(UCSRA & (1<<RXC)))
- {
- //Do nothing
- }
- //Now USART has got data from host
- //and is available is buffer
- return UDR;
- }
- //This function writes the given "data" to
- //the USART which then transmit it via TX line
- void USARTWriteChar(char data)
- {
- //Wait until the transmitter is ready
- while(!(UCSRA & (1<<UDRE)))
- {
- //Do nothing
- }
- //Now write the data to USART buffer
- UDR=data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement