Why do we need to calculate the modulus and remainder of 256 when the microcontroller interrupts and installs the initial value?

Publisher:清新天空Latest update time:2015-08-25 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When the timer works in 16-bit counting mode, there are two parameters TH and TL.
Both parameters are 8-bit (0-255) and cannot directly accept 16-bit (0-65535) data.
In order to assign the high 8 bits to TH, the method of dividing by 256 is used, which is equivalent to >> 8 (2 to the 8th power = 256), which is equivalent to moving the high 8 bits to the low 8 bits. The
remainder is calculated to assign the low 8 bits to TL. When it cannot be divided by 256, the remainder range is only within 0-255. So it can be directly assigned to TL.

Therefore,
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
is equivalent to
TH0=(65536-50000)>>8;
TL0=(65536-50000)&0x00ff;.
During calculation, the microcontroller is more efficient in logical operations than in arithmetic operations.
Keywords:MCU Reference address:Why do we need to calculate the modulus and remainder of 256 when the microcontroller interrupts and installs the initial value?

Previous article:22.1184 crystal oscillator microcontroller
Next article:Setting the slave address of the I2C device

Recommended ReadingLatest update time:2024-11-23 10:24

Solar LED Street Light Solution Using STM32 MCU
  As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand , and advocating green environmental protection technologies for energy conservation and
[Microcontroller]
Solar LED Street Light Solution Using STM32 MCU
Design of software and hardware platform for ARM9 microcontroller
Embedded application system design includes two parts: hardware platform and software platform. The former is a hardware system with embedded microcontroller/microprocessor as the core; the latter is a software system built around embedded operating system. The two are inseparable in design, and it is necessary to b
[Microcontroller]
Design of software and hardware platform for ARM9 microcontroller
PIC microcontroller CCS C language (application of #INT_DEFAULT)
#INT_DEFAULT Syntax: #int_default Purpose: If the PIC triggers an interrupt and no interrupt flag is set, the following function will be called. If there is an interrupt flag, but it is never triggered, the #int_default function will also be called. Example: #int_default default_isr(){ printf(“Unexplained inte
[Microcontroller]
51 MCU Program In-depth writing of bare metal code helps to understand the characteristics of the hardware
The microcontroller does not have an operating system. The codes written in Keil are all bare-metal codes. In-depth writing of bare-metal codes helps to understand the characteristics of the hardware. If the hardware characteristics are not fixed, the other processes are all caused by the code. I suddenly thought of
[Microcontroller]
51 MCU Program In-depth writing of bare metal code helps to understand the characteristics of the hardware
Memory Problems of 51 MCU
The 51 single-chip microcomputer addresses the memory space not by bus but by instructions. 1:51 consists of the following memory modules ROM Flash RAM has------lower 128 bits of internal RAM (00-7F)           -------higher 128 bits of internal RAM (80-FF)---           -------Special Function Register (SFR) (80-FF)  
[Microcontroller]
Design of reset circuit system for MSP430 series microcontroller
0 Introduction TI's MSP430 series of mixed signal processors are one of the products in the current mainstream MCU market. They are widely used in the field of electronic applications and are favored by more and more electronic designers due to their powerful processing capabilities, high peripheral device inte
[Microcontroller]
Design of reset circuit system for MSP430 series microcontroller
AVR MCU serial port multi-machine communication program
In the process of multi-machine communication, the RS232 interfaces of all devices are connected to the communication line, and only one device can be the host, and the others are slaves. The communication is initiated by the host. The data frame generally uses 1 start bit and 9 data bits, of which the 9th bit (RXB8)
[Microcontroller]
Design of voltage regulation system for electrostatic precipitator based on single chip microcomputer control
1. Introduction Electrostatic precipitators have the characteristics of high dust removal efficiency and relatively low operation and maintenance costs. They play a very important role in reducing harmful dust emissions into the atmosphere and are currently a widely used environmental protection equipment. Electrost
[Microcontroller]
Design of voltage regulation system for electrostatic precipitator based on single chip microcomputer control
Latest Microcontroller 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号