source: projects/gamm10-interface/src/toolchain.h @ 60

Last change on this file since 60 was 60, checked in by sven, 13 years ago

First import of code files from the bull-anelex-project. They were started in April 2010 and there are several development steps in the anelex-interface made in late 2010.

File size: 2.0 KB
Line 
1/*
2 * um in main.c einfach mehr Uebersicht zu haben, hier eine Quick & Dirty-
3 * Sammlung von typisch anfallendem Zeug: libc-Initialisierung, langweilige
4 * Standard-Routinen, usw.
5 *
6 */
7
8#define  __AVR_ATmega644__   1
9//#define  OSCSPEED            20*1000*1000
10// statt OSCSPEED hab ich jetzt auch F_CPU genutzt in UartInit()
11// F_CPU wird durch die make file (den Aufruf von AVR Studio) bereits definiert
12
13#include <string.h>
14#include <stdio.h>
15#include <stdlib.h> // abs, itoa
16#include <stdint.h> // int8_t, uint16_t
17typedef unsigned char byte_t;
18
19#include <util/delay.h>
20
21#include "avr/io.h"
22#include "avr/interrupt.h"
23
24// STDIO aufsetzen
25
26static int uart_transmit(char c, FILE *stream) {
27        if (c == '\n')
28                uart_transmit('\r', stream);
29        loop_until_bit_is_set(UCSR0A, UDRE0);
30        UDR0 = c;
31        return 0;
32}
33
34static FILE _meine_stdout_ = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE);
35
36// das muss im main() aufgerufen werden:
37#define setup_stdio()  ( stdout = &_meine_stdout_ )
38
39
40// LED-Spielzeug
41// sic! mit ja/nein und so
42#define stop_led()              ( PORTB &= ~(1 << PORTB0) )
43#define start_led()             ( PORTB |= (1 << PORTB0) )
44#define is_led()        ( PINB & (1 << PORTB0) )
45#define toggle_led()    ( is_led() ? stop_led() : start_led() )
46
47
48void UartInit(uint32_t Baud)
49{
50        int BaudRate = F_CPU / (16 * Baud) - 1;
51
52        UBRR0H = (unsigned char) BaudRate>>8;
53        UBRR0L = (unsigned char) BaudRate;
54        //set BaudRate
55
56        UCSR0B = UCSR0B | (0b00011000);
57        // RXEN & TXEN enable (Bits 4, 3 = 1)
58
59        UCSR0C = (UCSR0C | (0b10000110));
60        // USART Register Select (Bit 7 = 1)
61        // 8 data bits per frame (Bit 2, 1 = 1)
62
63        UCSR0C = UCSR0C & 0b11110111;
64        // 1 Stop bit (Bit 3 = 0)     
65}
66
67
68void print_bits(byte_t byte) {
69        char str[10];
70        /*
71        byte_t bit; byte_t pos = 0;
72        for(bit = 7; bit >= 0; bit--) {
73                str[pos++] = ( (1 << bit) & byte ) ? '1' : '0';
74        }
75        str[8] = ' ';
76        str[9] = '\0';
77        puts(str);
78        */
79        puts(itoa(byte, str, 2));
80}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License