kramann.info
© Guido Kramann

Login: Passwort:










Mikrocontroller
1 Einfuehrung
..1.1 Entwicklungsgeschichtliches
..1.2 Maschinensprache
..1.3 Assemblerbeispiel
..1.4 Sprachwahl
..1.5 Praxis
....1.5.1 Digital_IO
....1.5.2 Byteoperationen
....1.5.3 AVR_Studio
....1.5.4 Testboard
....1.5.5 Aufgaben
....1.5.6 Do_it_yourself
......1.5.6.1 Ampel
......1.5.6.2 Programmierer
..1.6 Literatur
..1.7 Programmierer
....1.7.1 Bauverlauf
....1.7.2 KurzreferenzLow
....1.7.2 Kurzreferenz_16PU
..1.8 Uebung1
..1.9 BoardAtHome
....1.9.1 Software
....1.9.2 Hardware
....1.9.3 Knoppix
....1.9.4 Aufbau
....1.9.5 LED
2 Oszillator
..2.1 Assembler
..2.2 Interner_RC
..2.3 Quarz
..2.4 Taktgenerator
3 DigitalIO
..3.1 Elektrische_Eigenschaften
..3.2 Pullup_Widerstaende
..3.3 Bitmasken_Eingang
..3.4 Bitmasken_Ausgang
..3.5 Tic_Tac_Toe
....3.5.1 DuoLEDs
....3.5.2 Schaltplan
....3.5.3 Spielfeld
....3.5.4 Anwahl
....3.5.5 Kontrolle
..3.6 Laboruebung2
..3.7 Laboruebung2_alt
4 PWM
..4.1 Prinzip
..4.2 Nutzen
..4.3 Generierung
..4.4 Programmierung
..4.5 Servos
..4.7 Laboruebung3
..4.8 LoesungUE3
..4.9 Uebung6
5 LichtKlangKugeln
..5.1 LED
..5.2 RGB
..5.3 Sensoren
..5.4 lautsprecher
..5.5 tonerzeugung
6 UART
..6.1 Bussysteme
..6.2 UART
..6.3 RS232
..6.4 Hardware
..6.5 Senden
..6.6 Hyperterminal
..6.7 Empfangen
..6.8 Broadcast
..6.9 Uebung4
7 Infrarot
..7.1 schalten
..7.2 seriell
..7.3 Uebung
8 OOP
..8.1 Probleme
..8.2 Konzept
..8.3 Statisch
..8.4 Datentypen
..8.5 RS232
....8.5.1 Prozedural
....8.5.2 Analyse
....8.5.3 Umsetzung
....8.5.4 Vererbung
....8.5.5 Statisch
....8.5.6 Performance
..8.6 Fahrzeug
9 ADW
..9.1 ADW
..9.2 Zaehler
10 Peripherie
..10.1 RS232Menue
..10.2 ASCIIDisplay
..10.3 Tastenmatrix
..10.4 Schrittmotor
..10.5 Zaehler
..10.6 Uebung7
11 SPI
..11.1 Testanordnung
..11.2 Register
..11.3 Test1
..11.4 Test2_Interrupt
..11.5 Test3_2Slaves
..11.6 Laboruebung
12 EEPROM
13 I2C
..13.1 MasterSendByte
..13.2 MasterSend2Bytes
..13.3 MasterReceiveByte
..13.4 MasterReceive2Bytes
14 Anwendungen
..14.1 Mechatroniklabor
....14.1.1 Biegelinie
....14.1.2 Ausbruchsicherung
....14.1.3 Einachser
....14.1.4 AV
....14.1.5 Vierradlenkung
....14.1.6 Kommunikation
..14.2 Sinuserzeugung
....14.2.1 Variante1
....14.2.2 Variante2
....14.2.3 Variante3
....14.2.4 Variante4
..14.3 Laboruebung8
..14.4 Loesung_Ue8
..14.5 SPI_Nachtrag
20 Xubuntu

14.2.2 Variante 2 - Warum berechnen, was man sich merken kann?

variante2.zip - Download des Projektes
#include <avr/io.h>

volatile unsigned char data[720] = { 
125,  126,  127,  128,  129,  130,  132,  133,  134,  135,  136,  137,  138,  139,  140,  141,  142,  143,  
145,  146,  147,  148,  149,  150,  151,  152,  153,  154,  155,  156,  157,  158,  159,  161,  162,  163,  
164,  165,  166,  167,  168,  169,  170,  171,  172,  173,  174,  175,  176,  177,  178,  179,  180,  181,  
182,  183,  184,  185,  186,  187,  188,  188,  189,  190,  191,  192,  193,  194,  195,  196,  197,  198,  
198,  199,  200,  201,  202,  203,  204,  205,  205,  206,  207,  208,  209,  209,  210,  211,  212,  213,  
213,  214,  215,  216,  216,  217,  218,  219,  219,  220,  221,  221,  222,  223,  224,  224,  225,  225,  
226,  227,  227,  228,  229,  229,  230,  230,  231,  232,  232,  233,  233,  234,  234,  235,  235,  236,  
236,  237,  237,  238,  238,  239,  239,  240,  240,  240,  241,  241,  242,  242,  242,  243,  243,  244,  
244,  244,  245,  245,  245,  245,  246,  246,  246,  247,  247,  247,  247,  247,  248,  248,  248,  248,  
248,  249,  249,  249,  249,  249,  249,  249,  250,  250,  250,  250,  250,  250,  250,  250,  250,  250,  
250,  250,  250,  250,  250,  250,  250,  250,  250,  250,  250,  249,  249,  249,  249,  249,  249,  249,  
248,  248,  248,  248,  248,  247,  247,  247,  247,  247,  246,  246,  246,  245,  245,  245,  245,  244,  
244,  244,  243,  243,  242,  242,  242,  241,  241,  240,  240,  240,  239,  239,  238,  238,  237,  237,  
236,  236,  235,  235,  234,  234,  233,  233,  232,  232,  231,  230,  230,  229,  229,  228,  227,  227,  
226,  225,  225,  224,  224,  223,  222,  221,  221,  220,  219,  219,  218,  217,  216,  216,  215,  214,  
213,  213,  212,  211,  210,  209,  209,  208,  207,  206,  205,  205,  204,  203,  202,  201,  200,  199,  
198,  198,  197,  196,  195,  194,  193,  192,  191,  190,  189,  188,  188,  187,  186,  185,  184,  183,  
182,  181,  180,  179,  178,  177,  176,  175,  174,  173,  172,  171,  170,  169,  168,  167,  166,  165,  
164,  163,  162,  161,  159,  158,  157,  156,  155,  154,  153,  152,  151,  150,  149,  148,  147,  146,  
145,  143,  142,  141,  140,  139,  138,  137,  136,  135,  134,  133,  132,  130,  129,  128,  127,  126,  
125,  124,  123,  122,  121,  120,  118,  117,  116,  115,  114,  113,  112,  111,  110,  109,  108,  107,  
105,  104,  103,  102,  101,  100,   99,   98,   97,   96,   95,   94,   93,   92,   91,   89,   88,   87,   
86,   85,   84,   83,   82,   81,   80,   79,   78,   77,   76,   75,   74,   73,   72,   71,   70,   69,   
68,   67,   66,   65,   64,   63,   62,   62,   61,   60,   59,   58,   57,   56,   55,   54,   53,   52,   
52,   51,   50,   49,   48,   47,   46,   45,   45,   44,   43,   42,   41,   41,   40,   39,   38,   37,   
37,   36,   35,   34,   34,   33,   32,   31,   31,   30,   29,   29,   28,   27,   26,   26,   25,   25,   
24,   23,   23,   22,   21,   21,   20,   20,   19,   18,   18,   17,   17,   16,   16,   15,   15,   14,   
14,   13,   13,   12,   12,   11,   11,   10,   10,   10,    9,    9,    8,    8,    8,    7,    7,    6,    
6,    6,    5,    5,    5,    5,    4,    4,    4,    3,    3,    3,    3,    3,    2,    2,    2,    2,    
2,    1,    1,    1,    1,    1,    1,    1,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    
0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    1,    1,    1,    1,    1,    1,    1,    
2,    2,    2,    2,    2,    3,    3,    3,    3,    3,    4,    4,    4,    5,    5,    5,    5,    6,    
6,    6,    7,    7,    8,    8,    8,    9,    9,   10,   10,   10,   11,   11,   12,   12,   13,   13,   
14,   14,   15,   15,   16,   16,   17,   17,   18,   18,   19,   20,   20,   21,   21,   22,   23,   23,   
24,   25,   25,   26,   26,   27,   28,   29,   29,   30,   31,   31,   32,   33,   34,   34,   35,   36,   
37,   37,   38,   39,   40,   41,   41,   42,   43,   44,   45,   45,   46,   47,   48,   49,   50,   51,   
52,   52,   53,   54,   55,   56,   57,   58,   59,   60,   61,   62,   62,   63,   64,   65,   66,   67,   
68,   69,   70,   71,   72,   73,   74,   75,   76,   77,   78,   79,   80,   81,   82,   83,   84,   85,   
86,   87,   88,   89,   91,   92,   93,   94,   95,   96,   97,   98,   99,  100,  101,  102,  103,  104,  
105,  107,  108,  109,  110,  111,  112,  113,  114,  115,  116,  117,  118,  120,  121,  122,  123,  124
};

int main(void)
{
   int i;
//Für das Warten Timer2 verwenden:
//Teiler CS22 CS21 CS20
//001 1
//010 8
//011 32
//100 64
//101 128
//110 256
//111 1024

    TCCR2 = (1<<FOC2) | (0<<WGM20) | (0<<COM21) | (0<<COM20) | (0<<WGM21) | (1<<CS22) | (0<<CS21) | (0<<CS20);

//Für das Senden des PWM-Signals Timer1 verwenden;
//Teiler CS12 CS11 CS10
//001 1
//010 8
//011 64
//100 256
//101 1024


    TCCR1A = (1<<COM1A1) | (0<<COM1A0) | (1<<COM1B1) | (0<<COM1B0) | (0<<FOC1A) | (0<<FOC1B) | (0<<WGM11) | (0<<WGM10);
    TCCR1B = (0<<ICNC1) | (0<<ICES1) | (1<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (1<<CS10); //Teilung 1

    DDRD |= (1<<PB5) | (1<<PB4); //auf Ausgang setzen.            
    //PWM-Frequenz durch Setzen von TOP festlegen:
    ICR1 = 250;
//fpwm = 9216000/(2*TOP*1)=18432Hz

    TCNT2=0;
    i=0;
    while(true)
    {
        OCR1A = data[i]; //1Hz Schwingung
        i++;
        i%=720;
        while(TCNT2<200); //Samplingrate mit der die PWM-Breite verstellt wird: 9216000/(64*200)=720Hz
        TCNT2=0;
    }
	return 0;
}

 

Code 14.2.2-1: Programmcode