Electronic engineers pass on their experience: classic experience in using AVR microcontrollers

Publisher:SparkCrafterLatest update time:2012-11-14 Keywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Using better devices only creates a good foundation and possibility for designing and implementing a good system. If you still use and follow the traditional hardware and software design ideas and methods, you can't use AVR well, and you can't even really understand the characteristics and strengths of AVR.
AVR has the characteristics of quick start and easy development, but to fully appreciate and give full play to the advantages of AVR, it also requires the application engineer's own hardware and software design and development capabilities to continue to learn and practice.

Compared with traditional types of single-chip microcomputers, AVR has greatly improved and improved in many aspects such as structural system, functional components, performance and reliability, in addition to being able to realize some of the original basic functions.


The better the function of the device, the more people with higher skills and abilities are needed to use and drive it. Just like a good F1 racing car, only a driver with superb skills can fully appreciate the characteristics of the car and maximize its performance.

"Outsiders watch the excitement, insiders watch the doorway", for engineers with a certain foundation in embedded and single-chip system design and development, it is a good idea to try AVR first.
Development environment and tools: PC + download line + actual system board Development software on PC: AVR Studio (Free) assembly + assembly debugging + high-level language debugging + software simulation ICC, CVAVR, BASCOM-AVR high-level language program development + program download. One of them is purchased as a genuine full-function as the main development environment, and the other uses the DEMO version as an auxiliary and reference. AVR ISP download line: STK200 and STK200+ and STK300 ISP programmer. Through the printer port of the PC, the system running code (HEX, BIN) and data are written into the Flash and EEPROM of the AVR chip using ISP technology to program the configuration fuse bit and encryption bit of the AVR. Supports most AVR chips, as well as ATMEL's 51-compatible chips 89S8252, 89S52, etc. The download line support program is included in ICC, CVAVR, BASCOM-AVR, and BASCOM-8051. Free dedicated download programs: SLISP, PonyProg2000, etc. Recommendations for not using emulators as much as possible: When developing and debugging system programs, many people rely entirely on emulators, and once they leave the emulator, they feel at a loss. In fact, since the AVR's Flash memory can be easily erased and written online multiple times using ISP technology, it is recommended to try not to use (rely on) emulators to develop and debug programs. In the actual development process, program debugging can start from the following aspects: Current high-level language compilers (such as C compilers) can generate highly efficient machine codes, so it is recommended that you try to use high-level languages ​​to write system programs. Use the AVR Studio software simulation environment provided by Atmel, as well as other software simulation environments (BASCOM-AVR). Use high-level languages ​​to write system programs as much as possible. Utilize the LED, LCD or asynchronous serial port on the target board. See the introduction of "How to develop AVR without an emulator" in the attachment. Improve the rationality of hardware design: Try to reasonably and fully use the resources in the AVR chip, such as EEPROM, A/D, and internal RC oscillator source. Try to use peripheral devices connected by serial communication, large-capacity memory, LCD controller, printer, and use 7279 instead of 8279 (LED digital tube + keyboard). Except for the need to expand RAM (such as voice and image), it is generally not recommended to use parallel expansion (573 + decoding circuit) to reduce the probability of hardware, wiring and PCB board errors, and also improve the reliability of the system. Parallel expansion to serial expansion is a development trend. Now there are a large number of new peripheral devices using high-speed serial interfaces, such as A/D, D/A, RTC, memory, etc. Try to use and reserve the ISP program download interface on the target board, or use IAP technology. Advantages: The compatibility of ISP interface and I/O is better than JETAG. Disadvantages: Cannot debug online Pay attention to and master the use of AVR configuration fuses: . System crystal selection. Use of BOD . Startup delay. PC6 pin of Mega8, conversion between RESET and general I/O. Conversion between JETAG interface and general I/O . Conversion of startup vector, setting of BOOT-LOAT area size Considerations for improving hardware reliability: . Try to use on-chip crystal, low-frequency system clock, and small output amplitude of oscillation circuit. . Choose appropriate startup delay parameters . Use BOD and on-chip watchdog . Use sleep mode reasonably . Do not use I/O port to set output low level . Use internal EEPROM and register MCUCSR to judge reset flag and perform different processing Improve software design ability and level: Try to reasonably use high-level language to design and write system programs. Many people think that using assembly language to write programs is more concise, and using high-level language development will waste a lot of program space. In fact, this is a misunderstanding. For an experienced assembly master who is very familiar with a certain microcontroller, he can write more concise code than high-level language. For developers who are not very familiar with assembly language, or who suddenly change to a new microcontroller, can you guarantee that you can write a more concise code than high-level language? The advantages of high-level language cannot be compared with assembly language: . Convenient program transplantation . Robustness of program . Support for mathematical operations . Clear structured programming and maintainability of program. . Collaborative software development with short development cycle. Today's high-level language compilers (such as C compilers) can generate machine code with high code efficiency. Therefore, it is recommended that you use high-level language to write programs that can be implemented in high-level language as much as possible. In situations where speed and timing requirements are particularly strict, mixed programming methods can be used to solve the problem. A more in-depth and comprehensive grasp of the regulations of various serial communication protocols: Embedded systems currently use a large number of serial interface peripheral chips and various communication interfaces, such as RS232, two-wire (I2C), three-wire (SPI), single bus, USB, CAN, TCP/IP, etc. Developers and programmers should understand low-level protocols, be familiar with how hardware implements low-level protocols, how to define reliable upper-level application protocols, and the interface design between low-level protocol drivers and upper-level application protocols (implementation of middle-level software). Hardware engineers should improve their software writing ability, adopt standard programming methods, perfect software overall framework design, good data structure and program structure system. (Programmers majoring in computer software are not familiar with hardware, most of them write software under the support of operating systems, and do not understand the driver layer and interface of low-level interfaces and protocols, and often cannot write good single-chip system programs.) The writing of communication interfaces should try to use interrupts + buffers, layered + structured design, and try not to use round-robin methods (reducing the efficiency of AVR). See the URAT (RS232) driver + middle-layer software example.


























































Use good system design mode:
Try not to use the traditional foreground and background (interrupt) system design mode, as tasks affect and interfere with each other and cannot be operated on a scheduled basis. For example, design an 8-bit LED digital tube display driven by dynamic scanning + a 4*4 matrix keyboard with dynamic scanning.
Use TimeTip + state machine design + CASE structure to implement multi-task parallel operation system design method. Or time-triggered system design. (See: "Time-triggered Embedded System Design Mode" China Electric Power Press 2004.6)
Port small embedded operating systems, such as UCOS-II. There are some free simple operating systems based on AVR on the Internet. Improve C language programming skills and software application level: Be familiar with and make good use of higher-level applications such as data structures, pointer applications, and memory management in C. Be familiar with and understand the characteristics of the high-level language development platform you are using. These platforms are for a certain type of processor and contain many special incompatible statements and extended structures, statements, functions, etc. Although they are easy to use, they should be used reasonably due to their opacity and time uncertainty. For example, getchar() and putchar() in C. AVR has multiple development platforms, each with its own characteristics and shortcomings. The ability to use these platforms in combination and complement each other can improve development efficiency. For example, through the ICC and CVAVR program generator CodeWizard, you can learn and understand the hardware settings of AVR, simplify calculations, and quickly generate basic program modules, such as "a URAT (RS232) low-level driver + middle-level software example".



Keywords:AVR Reference address:Electronic engineers pass on their experience: classic experience in using AVR microcontrollers

Previous article:Introduction to PIC 16C84 Microcontroller (Part 2)
Next article:DAC Power Consumption Data Calculation Power Consumption Figures Summary

Recommended ReadingLatest update time:2024-11-16 16:42

PIC microcontroller learning independent buttons
Hardware circuit: independent button connected to RA5 Effect: Make the LED at port RD0 light up when the independent button is 0. Note: The default state of PORTA is not a digital IO port, we need to configure it as a digital IO port. This involves the ADCON1 register. //Basic application of buttons Independent
[Microcontroller]
Introduction to the principle and structure of 8051 series microcontrollers
A microcontroller is a control chip, a microcomputer, and with the addition of crystal oscillator, memory, address latch, logic gate, seven-segment decoder (display), buttons (similar to a keyboard), expansion chip, interface, etc., it is a microcontroller system, the following is a basic introduction to the principle
[Microcontroller]
Introduction to the principle and structure of 8051 series microcontrollers
Design of automatic metering feeding system based on single chip microcomputer 8031
  1 Introduction   In order to increase the proportion of domestic equipment, save foreign exchange, facilitate maintenance and ensure production, this paper, at the request of the manufacturer, has developed an embedded microcomputer automatic metering and feeding system based on 8031 ​​on the basis of a thorough
[Microcontroller]
Design of automatic metering feeding system based on single chip microcomputer 8031
Hands-on teaching of 51 single chip microcomputer | 1602 LCD
For components like this that contain chips, the most important thing is to learn how to understand the pin functions of the chip, rather than to memorize the statements of the chip. The same components from different manufacturers have slight differences, so when purchasing such things, ask the manufacturer for a chi
[Microcontroller]
Hands-on teaching of 51 single chip microcomputer | 1602 LCD
51 single chip microcomputer course design - LED dot matrix billboard program design
The final assignment for last semester was LED dot matrix billboards. The requirements were as follows: (1) LED dot matrix billboards capable of displaying different characters; (2) Press buttons to switch between different display effects (such as flashing, still, panning, etc.); (3) Press the button to switch differ
[Microcontroller]
51 single chip microcomputer course design - LED dot matrix billboard program design
51 MCU UART communication sends and receives numbers, letters and Chinese characters, and controls the LED on and off
1. Receive what you send /* Project creation MCU selection, Atmel 89C55 MCU: STC12C5A60S2 Crystal oscillator: 12M Function: Serial port application Baud rate: 4800 8 None 1 None */ #include REG51.h // You can use the general header file //Serial port interrupt initialization program void UART_init(void){
[Microcontroller]
51 MCU UART communication sends and receives numbers, letters and Chinese characters, and controls the LED on and off
Design of infrared communication interface in single chip microcomputer system
In many application systems based on single-chip microcomputers, the system needs to realize remote control function, and infrared communication is a method that is widely used. The remote control protocols on the market are generally simple, not very confidential, and have weak anti-interference capabilities. Here, we
[Microcontroller]
Low-power system design based on Atmega48 microcontroller
With the development of microelectronics and computer technology, especially the widespread application of microcomputers in various fields, indicators such as power consumption, cost, volume, and reliability have become important issues that designers are concerned about. Especially in battery-powered devices, how to
[Microcontroller]
Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号