Many beginners are confused by the shift algorithm, which is in the form of (1<
UCSRC = (1< UCSR0B = (1< This way of writing is a blessing for experts, because these codes explain which bits of the register are operated on, and the meaning of its operation can be seen; but it is a curse for novices, because novices cannot understand such programs. Let's go back to the beginning and explain what the shift algorithm is: For example: A = (1<<2), 1 written in binary is 0000 0001, and this 1 shifted left 2 bits is 0000 0100, so the resulting number A is 0000 0100, which is 0x04. For example: B = (2<<4), 2 is written as 0000 0010 in binary, and this number shifted left 4 bits is 0010 0000, so the resulting number B is 0010 0000, which is 0x20. Both of the above shift algorithms are correct. The first way of writing it represents a number with the third digit being 1 and the rest being 0s, and the numbering starts from 0. For example, (1<<0) represents 0000 0001, and (1<<7) represents 1000 0000. However, the second way of writing it does not have this meaning. Shifting is also used for multiplication and division. Shifting left by one bit multiplies by 2, and shifting right by one bit divides by 2. The number obtained by shifting 2 left by four bits in the second way of writing it above is 2×2×2×2×2=32, which is 0x20 above. Let’s look at the above sentence again: UCSRC = (1< UCSRC is an eight-bit register related to serial port communication. Each bit of it has a special definition. We can see the following by checking the data sheet. The header file iom16v.h and similar files included in the program will have a definition like #define URSEL 7. 1<
Previous article:ICC AVR line number display settings
Next article:ICC AVR font size adjustment
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Will the GaN RF market be big?
- [RVB2601 Creative Application Development] 1 Unboxing and Environment Setup
- Introduction to RF and Wireless Technology
- Help
- ODX-based diagnostic application software INTEWORK-OBT
- Share the MSP430F5529 clock UCS programming considerations
- RK3288 Information
- FFT based on C2000 series DSP
- Occupy the posting position, ESP32---WS2812 16*16 dot matrix drawing points, lines and surfaces
- ASM1117 SOT-323 heat sink problem?