Changeset cd3a9ac in avrstuff


Ignore:
Timestamp:
Jul 29, 2014, 10:37:15 PM (10 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
6d8c366
Parents:
efe25a8
Message:

Make libusart aware of attiny2313.

git-svn-id: svn://pulkomandy.tk/avrstuff@109 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

Location:
libs/usart
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libs/usart/usart.c

    refe25a8 rcd3a9ac  
    44#include <inttypes.h>
    55
     6#ifndef BAUD
     7        #error You must define BAUD to use libuart.
     8#endif
    69
    710//This function is used to initialize the USART
    8 //at a given UBRR value
    9 void USARTInit(uint16_t ubrr_value)
     11void USARTInit()
    1012{
     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
    1122
    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
    1534
    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);
    3037}
    3138
  • libs/usart/usart.h

    refe25a8 rcd3a9ac  
    11/* USART i/o library
    2  * Copyright 2010, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
     2 * Copyright 2010-2014, Adrien Destugues <pulkomandy@pulkomandy.tk>
    33 * Distributed under the terms of the MIT Licence */
    44
    55#include <stdint.h>
    66
    7 void USARTInit(uint16_t ubrr_value);
     7void USARTInit();
    88void USARTWriteChar(char data);
    99void USARTWriteHex(unsigned char i);
Note: See TracChangeset for help on using the changeset viewer.