Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
microcontrollertechnik:tipps_fuers_programmieren [2026/03/08 20:39] mexleadminmicrocontrollertechnik:tipps_fuers_programmieren [2026/03/08 20:39] (current) – old revision restored (2026/03/08 20:36) mexleadmin
Line 1: Line 1:
-====== Tips for Programming ======+====== Tipps fürs Programmieren ======
  
-  * If the task involves hardware-software co-designthe creation of the software or the software system development can already begin in parallel with the schematic design or directly afterwards+  * Sofern es sich um eine Aufgabe mit Hardware-Software-Co-Design handeltkann mit der Erstellung der Software bzw. der Softwaresystem-Entwicklung bereits parallel zur Schaltplan-Erstellung bzw. direkt danach begonnen werden
-  * Firstthink about +  * Machen Sie sich dazu zunächst Gedanken
-      * **what** the software has to do (higher-level tasks), +      * **was**  die Software tun muss (übergeordnete Tätigkeiten), 
-      * and in **which sequence** it should do so +      * und in **welcher Abfolge**  sie das tun soll 
-  * Then you can consider +  * Dann können Sie sich überlegen, 
-      * how these individual tasks can be assigned to **C functions**, +      * wie diese einzelnen Tätigkeiten **C-Funktionen**  zugeordnet werden können
-      * how the functions depend on one another+      * wie die C-Funktionen voneinander abhängen
-      * which interfaces the functions require between each other (data typevalue rangename+      * welche Schnittstellen die C-Funktionen untereinander benötigen, (DatentypWertebereichName
-  * **Only then should you think about what the code looks like**. A look at the datasheets and application notes of the µControllers and chips can help hereThese often already provide algorithms or code snippets.+  * **Erst dann sollten Sie überlegen wie der Code aussieht**. Hier hilft ein Blick in die Datenblätter und Application Notes der µController und ChipsDort sind nicht selten Algorithmen oder Codeschnipsel vorgegeben.
  
 ===== Software System Design ===== ===== Software System Design =====
-If you do not yet know exactly how the software or the hardware to be used will be appliedthe following tips should help+Falls Sie noch nicht wissenwie die Software oder die zu verwende Hardware genau genutzt wird, sollten folgende Tipps helfen:  
-    * Do not search for the component only in GermanThe number of results increases many times over if you search in English. [[https://www.linguee.de/|Linguee]] is recommended for translation+    * Suchen Sie die Komponente nicht (nur) auf deutschDie Ergebnisse vermehren sich um ein Vielfaches, wenn in Englisch gesucht wirdZur Übersetzung empfiehlt sich [[https://www.linguee.de/|Linguee]]. 
-    * Also use image search if you do not know the exact term+    * Nutzen Sie auch die Bildersuche, wenn Sie den genauen Begriff nicht kennen
-    * If terms are unclearthe following search terms can also help: // ''Arduino'' + <English translation of the "thingbeing searched for> + optionally ''Project''//Alternatively, ''AVR'' or ''Atmel'' can be used instead of ArduinoFor code, you can additionally search for ''"c code"''. Code is often found on GitHubso adding ''site:github.com'' in Google may also be helpful.+    * Bei unklaren Begriffenbieten sich auch folgende Suchworte an: // ''Arduino'' + <englische Übersetzung von dem "Dingwas gesucht wird> + ggf. ''Project''//Alternativ bietet sich statt Arduino auch ''AVR'' oder ''Atmel'' anFür C-Code kann ein ''"c code"'' zusätzlich gesucht werden. Code liegt häufig auf Githubentsprechend kann sich in Google ein Hinzufügen von ''site:github.com'' empfehlen.
  
-===== Requirements for Evaluation =====+===== Vorgaben für Bewertung =====
  
-The [[vorgaben_fuer_die_softwareentwicklung|Requirements for Programming]] contain notes on what the submitted code should look like.+Die [[vorgaben_fuer_die_softwareentwicklung|Vorgaben für die Programmierung]] enthalten Hinweise, wie der abgegebene Code aussehen soll.
  
-===== Common Errors and Debugging =====+===== Häufige Fehler und Debugging =====
  
-  * Tips on debugging and common mistakes can be found in the [[microcontrollertechnik:tipps_fuer_die_fehlersuche|Tips for Troubleshooting]]. +  * Tipps zum Debugging und zu häufigen Fehlern finden sich bei den [[microcontrollertechnik:tipps_fuer_die_fehlersuche|Tipps für die Fehlersuche]]. 
-  * Try to test your program after every small change whenever possibleIf you change three things and only test afterwardsyou will not know which change caused the issue+  * Versuchen Sie möglichst nach jeder kleinen Änderung Ihr Programm zu testenWenn Sie drei Punkte ändern und dann erst testendann wissen Sie nicht, an welcher Änderung es liegt   
-  *{{microcontrollertechnik:presentation-twenty-five_most-common_mistakes.pdf|The 25 Most Common Programming Mistakes}} or as a {{microcontrollertechnik:10.1.1.113.6245.pdf|paper}} and further {{ microcontrollertechnik:koopman11_escsv_handouts.pdf |41 common mistakes}}+  *{{microcontrollertechnik:presentation-twenty-five_most-common_mistakes.pdf|Die 25 häufigsten Fehler beim Programmieren}} oder als {{microcontrollertechnik:10.1.1.113.6245.pdf|Paper}} und weitere {{ microcontrollertechnik:koopman11_escsv_handouts.pdf |41 häufige Fehler}}
  
-===== General ===== +===== Allgemeines ===== 
-  * A good introduction to embedded software development can be found in the book [[https://link.springer.com/content/pdf/10.1007%2F978-3-658-18386-8.pdf|Sensor Networks in Theory and Practice Successfully Realizing Embedded Systems Projects]] by colleagues Meroth and Sora. It explains how to get started in the field of software development embedded in hardwareFrom within the university network or via VPN, you can view it directly on Springer Link. Another good introduction can be found at [[https://www.mikrocontroller.net/articles/AVR-GCC-Tutorial|Mikrocontroller.net]]. +  * Eine schöne Einführung in die Embedded Softwareentwicklung ist im Buch [[https://link.springer.com/content/pdf/10.1007%2F978-3-658-18386-8.pdf|Sensornetzwerke in Theorie und Praxis - Embedded Systems-Projekte erfolgreich realisieren]] von Kollegen Meroth und Sora zu findenDort wird der Einstieg in das Feld die (in Hardware) eingebettete Softwareentwicklung erklärtAus dem Hochschulnetz bzw. mit VPN können Sie dieses direkt bei Springer Link betrachtenEine andere schöne Einführung findet sich auf [[https://www.mikrocontroller.net/articles/AVR-GCC-Tutorial|Mikrocontroller.net]]. 
-  * The hardware does not need to be fully completed in order to start programmingIf you want to use a microcontroller from the ATmega familyyou can already develop and test software with the MiniMEXLE, MEXLE2020, or Simulide. +  * Zum Programmieren muss die Hardware noch nicht vollständig seinWenn Sie einen Mikrocontroller der ATmega Familie nutzen wollenso können Sie z.B. mit dem MiniMEXLE, MEXLE2020 oder Simulide bereits Software entwickeln und testen
-  * Tips for the {{ :doc8453.pdf |programming of ATMEL chips}} +  * Tipps für die {{ :doc8453.pdf |Programmierung von ATMEL Chips}} 
-  * If you need large tablesyou should store the data in program memory (EEPROM) and not in data memory (SRAM). As a rule, the program memory is larger by a factor of to 10. +  * Falls Sie lange Tabellen benötigensollten Sie die Daten im Programmspeicher (EEPROM) und nicht im Datenspeicher (SRAM) ablegenIn der Regel ist der Programmspeicher um den Faktor 5..10 größer 
-  * There is no [[http://www.if-schleife.de|if loop]]! +  * Es gibt keine [[http://www.if-schleife.de|If-Schleife]]! 
-  * If you search the web for solutionsnote that Arduinos generally use C%%++%% (e.g. file.cpp). In most cases this is not directly compatibleOn the other hand, the concepts can still be adopted+  * Falls Sie im Netz nach Lösungen suchenso beachten Sie, dass bei Arduinos in der Regel C%%++%% (z.B. file.cpp) genutzt wirdDies ist in den seltensten Fällen direkt kompatibelAndererseits lassen sich aber die Konzepte übernehmen
-  * for(x = 0 ; x < 400 ; x%%++%%) : If is defined as an 8-bit integer, this loop will run forever... +  * for(x = 0 ; x < 400 ; x%%++%%) : Wenn als 8 bit integer definiert istwird diese Schleife endlos lange laufen...  
-  * Variable types must be taken into account in calculationsotherwise c=a/b with int a=5 and int b=2 becomes 2. An explicit type cast helps here: c=(float)a/b+  * Die Variablentypen sind bei Rechnungen zu beachtensonst wird aus c=a/b mit int a=5 und int b=2 eine 2. Hier hilft ein expliziter Typecast: c=(float)a/b
  
-===== Serial Interfaces ===== +===== serielle Schnittstellen ===== 
-  * Programming an AVR chip via USB (if the chip supports thisis done using the tool [[https://www.microchip.com/developmenttools/ProductDetails/FLIP|FLIP]] +  * Die Programmierung eines AVR-Chips über USB (sofern dies der Chip ermöglicht), geschieht über das Tool [[https://www.microchip.com/developmenttools/ProductDetails/FLIP|FLIP]] 
-  * If you want to control an external component via a microcontrollerthe following must be consideredCheck whether the external component triggers on the positive edge or on the negative edgeAs a rule, this cannot be changed on the external component itselfThis can be changed in software on the microcontroller side+  * Falls Sie einen externen Baustein über einen Mikrocontroller ansteuern wollenist folgendes zu beachtenÜberprüfen Sie, ob der externe Baustein auf die positive Flanke triggert oder auf die negative. In der Regel lässt sich dies beim externen Baustein nicht ändernDies kann auf der Seite des Mikrocontrollers per Software geändert werden.  
-  * If another I2C interface is requiredyou can find [[https://en.wikipedia.org/wiki/I%C2%B2C|templates for this online]].+  * Falls eine weitere I2C Schnittstelle benötigt wirdso finden sich [[https://en.wikipedia.org/wiki/I%C2%B2C|Vorlagen dazu im Netz]].
  
-===== Programming the ST7565 in the ERC 128 64 - 1 Display ===== +===== Programmierung des ST7565 im Display ERC 128 64 - 1 ===== 
-  * The {{ laborausstattung:erc12864-1.pdf |ERC 128 64 - 1}} display with 128 pixels in the x-direction and 64 in the y-direction is divided into 8x8 sectionsThese 8x8 pixels are also called pages. In software, 132x65 pixels can be addressed, but output is only on 128x64 pixels+  * Das Display {{ laborausstattung:erc12864-1.pdf |ERC 128 64 - 1}} mit 128 Pixel in x-Richtung und 64 in y-Richtung ist in 8x8 Teile unterteiltDie 8x8 Pixel werden auch Page genannt. In Sotware sind 132x65 Pixel ansprechbar - die Ausgabe ist aber nur auf 128x64 Pixel
-  * In the {{ grundlagen_der_digitaltechnik:st7565.pdf |ST7565}}, each 8-bit vertical block is stored in one byte+  * Je 8bit vertikal sind im {{ grundlagen_der_digitaltechnik:st7565.pdf |ST7565}} in einem Byte gespeichert
-  * The commands that can be used via SPI are described in the datasheet+  * Die Kommandos, welche über SPI genutzt werden können, sind im Datasheet beschrieben.  
-  * Via SPI, the display can only be written toReading is not possible+  * Über SPI kann nur auf das Display geschrieben werdenEin Lesen ist nicht möglich.  
-  * Read the manufacturer's sample code and look for tutorials for the ST7565. +  * Lesen Sie den Beispiel-Code des Herstellers und suchen Sie ob es Tutorials für den ST7565 gibt
-  * Pay attention to the mounting orientation when controlling the display.+  * Beachten Sie die Einbaurichtung bei der Ansteuerung des Displays.
  
-===== Using Ports ===== +===== Verwenden von Ports ===== 
-  * The following must be observed if you want or need to use JTAG ports differently e.g. PF4..7 on the ATMEGA16U4 - (JTAG ports ports to which the programming hardware is connected): The JTAG ports cannot be used directly without further actionThe JTAG interface must first be disabled using the following code: \\ <code>+  * Folgendes ist zu beachten, falls Sie JTAG-Ports - z.B. PF4..7 bei ATMEGA16U4 - anderweitig verwenden wollen/müssen (JTAG Ports Ports an denen die ProgrammierHW angeschlossen wird): Die JTAG-Ports können nicht ohne weiteres direkt genutzt werdenDie JTAG Schnittstelle muss zunächst über folgenden Code deaktiviert werden. \\ <code>
 MCUCR |=(1<<JTD); MCUCR |=(1<<JTD);
 MCUCR |=(1<<JTD); MCUCR |=(1<<JTD);
-</code> ImportantThe control register must be written __twice__+</code>  WichtigEs das Control Register muss __zweimal__ geschrieben werden
-  * For time-critical output of consecutive bits (e.gfor controlling [[elektronik_labor:hardware_fuer_schaltungserstellung|intelligent LEDs]]), interrupts must definitely be usedIt is also worthwhile to additionally rely on __USART__. With USART, the data to be sent is first written into the UDRn register and then transferred into the shift register+  * Für eine zeitkritische Ausgabe von aufeinanderfolgenden Bits (z.Bfür die Ansteuerung von [[elektronik_labor:hardware_fuer_schaltungserstellung|intelligenten LEDs]]) müssen unbedingt Interrupts genutzt werdenEs lohnt sich zusätzlich auf __USART__ zurückzugreifenBei USART werden die zu versendenden Daten zunächst ins UDRn Register gegeben und dann in das Shiftregister übertragen.  
-  * If you use an external oscillator or crystaltwo ports are used for this (ports XTAL = "Crystal"). If you accidentally define these ports as outputs via DDR, the chip will no longer have a clockThat means this port assignment is the last thing the chip does... After that, it can only be revived via the debugger interface.+  * Falls Sie einen externen Oszillator oder Quarz benutzenwerden zwei Ports dafür verwendet (Ports XTAL = "Crystal"). Wenn Sie diese Ports per DDR versehentlich zu einem Ausgang definierenhat der Chip keinen Takt mehrDas heißt diese Portzuweisung ist das letzte was der Chip macht... Es ist danach nur noch per Debuggerschnittstelle möglich diesen wieder zu beleben.
  
 ====== Simulide ====== ====== Simulide ======
-===== Stepper Motor Driver =====+===== Schrittmotortreiber =====
  
-Various stepper motor drivers (such as the [[https://www.ti.com/lit/ds/symlink/drv8825.pdf|DRV8825]]) make it possible to drive a stepper motor by specifying the direction and pulsing the STEP pinSuch drivers are not available in Simulide. +Verschiedene Schrittmotortreiber bzw. Steppermotor Driver (wie z.B. [[https://www.ti.com/lit/ds/symlink/drv8825.pdf|DRV8825]]) ermöglichen durch die Angabe der Richtung und ein Takten des STEP Pins das Antreiben eines SchrittmotorsSolche Treiber sind in Simulide nicht verfügbar
-However, the following simulation at least allows this to be replicated:+Folgende Simulation ermöglicht aber zumindest die Nachbildung 
 {{microcontrollertechnik:stepper.rar}} {{microcontrollertechnik:stepper.rar}}
 +
 +
 +
 +
 +