Changeset cd3a9ac in avrstuff
- Timestamp:
- Jul 29, 2014, 10:37:15 PM (10 years ago)
- Branches:
- main
- Children:
- 6d8c366
- Parents:
- efe25a8
- Location:
- libs/usart
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libs/usart/usart.c
refe25a8 rcd3a9ac 4 4 #include <inttypes.h> 5 5 6 #ifndef BAUD 7 #error You must define BAUD to use libuart. 8 #endif 6 9 7 10 //This function is used to initialize the USART 8 //at a given UBRR value 9 void USARTInit(uint16_t ubrr_value) 11 void USARTInit() 10 12 { 13 //Set Baud rate 14 #include <util/setbaud.h> 15 UBRRH = UBRRH_VALUE; 16 UBRRL = UBRRL_VALUE; 17 #if USE_2X 18 UCSRA |= (1 << U2X); 19 #else 20 UCSRA &= ~(1 << U2X); 21 #endif 11 22 12 //Set Baud rate 13 UBRRL = ubrr_value; 14 UBRRH = (ubrr_value>>8); 23 /*Set Frame Format 24 >> Asynchronous mode 25 >> No Parity 26 >> 1 StopBit 27 >> char size 8 28 */ 29 #ifdef __AVR_ATtiny2313__ 30 UCSRC = (1 << UCSZ1) | (1 << UCSZ0); 31 #else 32 UCSRC = (1 << URSEL) | (3 << UCSZ0); 33 #endif 15 34 16 /*Set Frame Format 17 18 19 >> Asynchronous mode 20 >> No Parity 21 >> 1 StopBit 22 >> char size 8 23 24 */ 25 26 UCSRC=(1<<URSEL)|(3<<UCSZ0); 27 28 //Enable The receiver and transmitter 29 UCSRB=(1<<RXEN)|(1<<TXEN); 35 //Enable The receiver and transmitter 36 UCSRB = (1 << RXEN) | (1 << TXEN); 30 37 } 31 38 -
libs/usart/usart.h
refe25a8 rcd3a9ac 1 1 /* USART i/o library 2 * Copyright 2010 , Adrien Destugues <pulkomandy@pulkomandy.ath.cx>2 * Copyright 2010-2014, Adrien Destugues <pulkomandy@pulkomandy.tk> 3 3 * Distributed under the terms of the MIT Licence */ 4 4 5 5 #include <stdint.h> 6 6 7 void USARTInit( uint16_t ubrr_value);7 void USARTInit(); 8 8 void USARTWriteChar(char data); 9 9 void USARTWriteHex(unsigned char i);
Note:
See TracChangeset
for help on using the changeset viewer.