source: projects/anelex-interface/src (Ignorante Variante, die einfach Daten reinschiebt ohne Rueckmeldung)/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.1 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 ** ANALEX-INTERFACE, kopiert von Gamma10-Interface am
7 ** 28. August 2010, 17:30 im Museum
8 *
9 */
10
11#define  __AVR_ATmega644__   1
12//#define  OSCSPEED            20*1000*1000
13// statt OSCSPEED hab ich jetzt auch F_CPU genutzt in UartInit()
14// F_CPU wird durch die make file (den Aufruf von AVR Studio) bereits definiert
15
16#include <string.h>
17#include <stdio.h>
18#include <stdlib.h> // abs, itoa
19#include <stdint.h> // int8_t, uint16_t
20typedef unsigned char byte_t;
21
22#include <util/delay.h>
23
24#include "avr/io.h"
25#include "avr/interrupt.h"
26
27// STDIO aufsetzen
28
29static int uart_transmit(char c, FILE *stream) {
30        if (c == '\n')
31                uart_transmit('\r', stream);
32        loop_until_bit_is_set(UCSR0A, UDRE0);
33        UDR0 = c;
34        return 0;
35}
36
37static FILE _meine_stdout_ = FDEV_SETUP_STREAM(uart_transmit, NULL, _FDEV_SETUP_WRITE);
38
39// das muss im main() aufgerufen werden:
40#define setup_stdio()  ( stdout = &_meine_stdout_ )
41
42
43// LED-Spielzeug
44// sic! mit ja/nein und so
45#define stop_led()              ( PORTB &= ~(1 << PORTB0) )
46#define start_led()             ( PORTB |= (1 << PORTB0) )
47#define is_led()        ( PINB & (1 << PORTB0) )
48#define toggle_led()    ( is_led() ? stop_led() : start_led() )
49
50
51void UartInit(uint32_t Baud)
52{
53        int BaudRate = F_CPU / (16 * Baud) - 1;
54
55        UBRR0H = (unsigned char) BaudRate>>8;
56        UBRR0L = (unsigned char) BaudRate;
57        //set BaudRate
58
59        UCSR0B = UCSR0B | (0b00011000);
60        // RXEN & TXEN enable (Bits 4, 3 = 1)
61
62        UCSR0C = (UCSR0C | (0b10000110));
63        // USART Register Select (Bit 7 = 1)
64        // 8 data bits per frame (Bit 2, 1 = 1)
65
66        UCSR0C = UCSR0C & 0b11110111;
67        // 1 Stop bit (Bit 3 = 0)     
68}
69
70
71void print_bits(byte_t byte) {
72        char str[10];
73        /*
74        byte_t bit; byte_t pos = 0;
75        for(bit = 7; bit >= 0; bit--) {
76                str[pos++] = ( (1 << bit) & byte ) ? '1' : '0';
77        }
78        str[8] = ' ';
79        str[9] = '\0';
80        puts(str);
81        */
82        puts(itoa(byte, str, 2));
83}
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