Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 21 → Rev 22

/branches/MK3Mag V0.14 Code Redesign Killagreg/uart.c
136,8 → 136,6
/****************************************************************/
void USART0_Init (void)
{
uint8_t sreg = SREG;
 
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * BAUD_RATE) - 1);
 
// disable all interrupts before configuration
150,13 → 148,14
 
// set direction of RXD0 and TXD0 pins
 
// set RXD0 (PD0) as an input pin
PORTD |= (1 << PORTD0);
// set RXD0 (PD0) as an input pin tristate
DDRD &= ~(1 << DDD0);
PORTD &= ~(1 << PORTD0);
// set TXD0 (PD1) as an output pin
PORTD |= (1 << PORTD1);
DDRD |= (1 << DDD1);
PORTD &= ~(1 << PORTD1);
 
 
// USART0 Baud Rate Register
// set clock divider
UBRR0H = (uint8_t)(ubrr >> 8);
166,8 → 165,7
 
// enable double speed operation
UCSR0A |= (1 << U2X0);
// enable receiver and transmitter
UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
 
// set asynchronous mode
UCSR0C &= ~(1 << UMSEL01);
UCSR0C &= ~(1 << UMSEL00);
181,10 → 179,13
UCSR0C |= (1 << UCSZ01);
UCSR0C |= (1 << UCSZ00);
 
// enable receiver and transmitter
UCSR0B |= (1 << RXEN0);
UCSR0B |= (1 << TXEN0);
 
// flush receive buffer
while ( UCSR0A & (1<<RXC0) ) UDR0;
 
// enable interrupts at the end
// enable RX-Interrupt
UCSR0B |= (1 << RXCIE0);
// enable TX-Interrupt
193,19 → 194,21
rxd_buffer_locked = FALSE;
txd_complete = TRUE;
 
Debug_Timer = SetDelay(200);
 
 
// restore global interrupt flags
SREG = sreg;
 
VersionInfo.Major = VERSION_MAJOR;
VersionInfo.Minor = VERSION_MINOR;
VersionInfo.PCCompatible = VERSION_COMPATIBLE;
 
// Version beim Start ausgeben (nicht schön, aber geht... )
uart_putchar ('\n');uart_putchar ('C');uart_putchar ('P');uart_putchar (':');
uart_putchar ('V');uart_putchar (0x30 + VERSION_MAJOR);uart_putchar ('.');uart_putchar (0x30 + VERSION_MINOR/10); uart_putchar (0x30 + VERSION_MINOR%10);
 
// Version beim Start ausgeben (nicht schön, aber geht... )
uart_putchar ('\n');
uart_putchar ('C');
uart_putchar ('P');
uart_putchar (':');
uart_putchar ('V');
uart_putchar (0x30 + VERSION_MAJOR);
uart_putchar ('.');uart_putchar (0x30 + VERSION_MINOR/10);
uart_putchar (0x30 + VERSION_MINOR%10);
uart_putchar ('\n');
}
 
212,19 → 215,21
// ---------------------------------------------------------------------------------
void USART0_EnableTXD(void)
{
//if(!(UCSR0B & (1 << TXEN0))) return;
DDRD |= (1<<DDD1); // set TXD pin as output
DDRD |= (1<<DDD1); // set TXD pin as output
PORTD &= ~(1 << PORTD1);
UCSR0B |= (1 << TXEN0); // enable TX in USART
UCSR0B |= (1 << TXCIE0); // disable TX-Interrupt
}
 
// ---------------------------------------------------------------------------------
void USART0_DisableTXD(void)
{
//if((UCSR0B & (1 << TXEN0))) return;
while(!txd_complete){ };
 
UCSR0B &= ~(1 << TXCIE0); // disable TX-Interrupt
UCSR0B &= ~(1 << TXEN0); // disable TXD in USART
DDRD &= ~(1<<DDD1); // set TXD pin as input
PORTD &= ~(1 << PORTD1);
}
 
/****************************************************************/