Differences

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

Link to this comparison view

Both sides previous revision Previous revision
microcontrollertechnik:tips_for_prgramming [2026/03/08 20:41] – [Simulide] mexleadminmicrocontrollertechnik:tips_for_prgramming [2026/03/08 20:46] (current) – removed mexleadmin
Line 1: Line 1:
-====== Tips for Programming ====== 
- 
-  * If the task involves hardware-software co-design, the creation of the software or the software system development can already begin in parallel with the schematic design or directly afterwards. 
-  * First, think about 
-      * **what** the software has to do (higher-level tasks), 
-      * and in **which sequence** it should do so 
-  * Then you can consider 
-      * how these individual tasks can be assigned to **C functions**, 
-      * how the C functions depend on one another, 
-      * which interfaces the C functions require between each other (data type, value range, name) 
-  * **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 here. These often already provide algorithms or code snippets. 
- 
-===== Software System Design ===== 
-If you do not yet know exactly how the software or the hardware to be used will be applied, the following tips should help: 
-    * Do not search for the component only in German. The number of results increases many times over if you search in English. [[https://www.linguee.de/|Linguee]] is recommended for translation. 
-    * Also use image search if you do not know the exact term. 
-    * If terms are unclear, the following search terms can also help: // ''Arduino'' + <English translation of the "thing" being searched for> + optionally ''Project''//. Alternatively, ''AVR'' or ''Atmel'' can be used instead of Arduino. For C code, you can additionally search for ''"c code"''. Code is often found on GitHub, so adding ''site:github.com'' in Google may also be helpful. 
- 
-===== Requirements for Evaluation ===== 
- 
-The [[vorgaben_fuer_die_softwareentwicklung|Requirements for Programming]] contain notes on what the submitted code should look like. 
- 
-===== Common Errors and Debugging ===== 
- 
-  * Tips on debugging and common mistakes can be found in the [[microcontrollertechnik:tipps_fuer_die_fehlersuche|Tips for Troubleshooting]]. 
-  * Try to test your program after every small change whenever possible. If you change three things and only test afterwards, you will not know which change caused the issue! 
-  *{{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}} 
- 
-===== General ===== 
-  * 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 hardware. From 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]]. 
-  * The hardware does not need to be fully completed in order to start programming. If you want to use a microcontroller from the ATmega family, you can already develop and test software with the MiniMEXLE, MEXLE2020, or Simulide. 
-  * Tips for the {{ :doc8453.pdf |programming of ATMEL chips}} 
-  * If you need large tables, you 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 5 to 10. 
-  * There is no [[http://www.if-schleife.de|if loop]]! 
-  * If you search the web for solutions, note that Arduinos generally use C%%++%% (e.g. file.cpp). In most cases this is not directly compatible. On the other hand, the concepts can still be adopted. 
-  * for(x = 0 ; x < 400 ; x%%++%%) : If x is defined as an 8-bit integer, this loop will run forever... 
-  * Variable types must be taken into account in calculations, otherwise c=a/b with int a=5 and int b=2 becomes 2. An explicit type cast helps here: c=(float)a/b 
- 
-===== Serial Interfaces ===== 
-  * Programming an AVR chip via USB (if the chip supports this) is done using the tool [[https://www.microchip.com/developmenttools/ProductDetails/FLIP|FLIP]] 
-  * If you want to control an external component via a microcontroller, the following must be considered: Check whether the external component triggers on the positive edge or on the negative edge. As a rule, this cannot be changed on the external component itself. This can be changed in software on the microcontroller side. 
-  * If another I2C interface is required, you can find [[https://en.wikipedia.org/wiki/I%C2%B2C|templates for this online]]. 
- 
-===== Programming the ST7565 in the ERC 128 64 - 1 Display ===== 
-  * 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 sections. These 8x8 pixels are also called pages. In software, 132x65 pixels can be addressed, but output is only on 128x64 pixels. 
-  * In the {{ grundlagen_der_digitaltechnik:st7565.pdf |ST7565}}, each 8-bit vertical block is stored in one byte. 
-  * The commands that can be used via SPI are described in the datasheet. 
-  * Via SPI, the display can only be written to. Reading is not possible. 
-  * Read the manufacturer's sample code and look for tutorials for the ST7565. 
-  * Pay attention to the mounting orientation when controlling the display. 
- 
-===== Using 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 action. The JTAG interface must first be disabled using the following code: \\ <code> 
-MCUCR |=(1<<JTD); 
-MCUCR |=(1<<JTD); 
-</code> Important: The control register must be written __twice__. 
-  * For time-critical output of consecutive bits (e.g. for controlling [[elektronik_labor:hardware_fuer_schaltungserstellung|intelligent LEDs]]), interrupts must definitely be used. It 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. 
-  * If you use an external oscillator or crystal, two 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 clock. That means this port assignment is the last thing the chip does... After that, it can only be revived via the debugger interface. 
-