5058 views|9 replies

1w

Posts

16

Resources
The OP
 

STC microcontroller initialization question, everyone has a look [Copy link]

Recently I saw an STC initialization program as follows:
  1. void Timer0Init(void) //2.5 milliseconds @ 12.000MHz { AUXR &= 0x7F; //Timer clock 12T mode TMOD &= 0xF0; //Set timer mode TMOD |= 0x01; //Set timer mode TL0 = 0x3C; //Set timing initial value TH0 = 0xF6; //Set timing initial value TF0 = 0; //Clear TF0 flag TR0 = 1; //Timer 0 starts timing}
复制代码
My question is, in the first and second lines, AUXR and TMOD are both zero after reset, so won’t the bitwise AND become 0? Then how can it be initialized successfully? ? ? ?
This post is from 51mcu

Latest reply

  void InitPort(void) { P0M1=0x00; P0M0=0xff; P24=1; P2M1=0x10; P2M0=0x88; P41=1; P4M1=0x02; P4M0=0x04; }   Details Published on 2018-3-30 16:43
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 

30

Posts

0

Resources
2
 
Pay attention to the third line TMOD |= 0x01; //Set the timer mode
This post is from 51mcu

Comments

This is understandable, but what's going on with the first line? ? ? ?  Details Published on 2018-3-14 16:06
 
 
 

1w

Posts

16

Resources
3
 
Posted by a beginner learner on 2018-3-14 15:12 Pay attention to the third line TMOD |= 0x01; //Set timer mode
This is understandable, but what about the first line? ? ? ?
This post is from 51mcu

Comments

TMOD&=0xf0; is to set the TMOD register to zero first, in case TMOD is not 0x00; Assuming TMOD=0xff; TMOD|=0x01; TMOD becomes 0xff. Here is a C language program: #include int main() { int a,b=2; a=0xf0; // b&=a; b|=0x01; print  Details Published on 2018-3-14 18:41
 
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

4177

Posts

9

Resources
4
 
https://wenku.baidu.com/view/f3ca759a770bf78a6429544a.html Take a look at this in the Wenku library. I haven't worked with 51 for a long time. Look at the following table. After the AUXR register is reset, it is not necessarily 0. After the TMOD register is reset, it is 0, but the result of the bitwise AND is 0. It seems that the T0 timer is used.
This post is from 51mcu
 
 
 

424

Posts

8

Resources
5
 
ddllxxrr posted on 2018-3-14 16:06 This is understandable, but what's the matter with the first line? ? ? ?
TMOD&=0xf0; is to set the TMOD register to zero first, in case TMOD is not 0x00; Assuming TMOD=0xff; TMOD|=0x01; TMOD becomes 0xff. Here is a C language program: #include
int main() { int a,b=2; a=0xf0; // b&=a; b|=0x01; printf("%d",b); return 0; }
       
This post is from 51mcu
 
 
 

5

Posts

0

Resources
6
 
Learn a little bit, I don't know much about timers
This post is from 51mcu
 
 
 

525

Posts

235

Resources
7
 
The 4th floor is correct. Read the data sheet more!
This post is from 51mcu
 
Personal signature爱电子,爱生活
 
 

6069

Posts

4

Resources
8
 
This post was last edited by damiaa on 2018-3-19 14:22 AUXR &= 0x7F; //Timer clock 12T mode is to just write 0 to the highest bit (timer 0). TMOD &= 0xF0; //Set timer mode is to just write 0 to the lowest 4 bits (timer 0). The register here is not the memory. I don't know if this is the correct understanding
This post is from 51mcu
 
 
 

31

Posts

0

Resources
9
 
  MCUs are now everywhere, with a wide variety of types that developers are overwhelmed and are developing rapidly. From the 1980s, from the 4-bit and 8-bit microcontrollers at that time to the current various high-speed microcontrollers... Various manufacturers have also had ups and downs in speed, memory, and functions, and they are uneven~~ At the same time, a large number of manufacturers with representative microcontrollers have emerged: Atmel, TI, ST, MicroChip, ARM... The domestic Hongjing STC microcontroller is also remarkable... The following is a comparison of the advantages and disadvantages and functional manifestations of 51, MSP430, TMS, STM32, PIC, AVR, and STC microcontrollers... The 51 microcontroller is the most widely used 8-bit microcontroller and of course the easiest microcontroller for beginners to learn. It was first introduced by Intel. Due to its typical structure and complete centralized management of bus-specific registers, numerous logic bit operation functions and rich control-oriented instruction system, it can be called a "classic" of a generation, which laid the foundation for the development of other microcontrollers in the future. The main reasons why the 51 single-chip microcomputer has become a classic and easy-to-use single-chip microcomputer are as follows: Features: 1. From the internal hardware to the software, there is a complete bit-by-bit operating system, called a bit processor, and the processing object is not a word or a byte but a bit. It can not only process a certain bit of some special function registers in the chip, such as transfer, set, clear, test, etc., but also perform bit logic operations. Its functions are very complete and easy to use. [This article is reproduced from the Internet, the copyright belongs to the original author, if there is any infringement, please contact and delete] 2. At the same time, a dual-function address range is specially opened in the RAM area of the chip, which is extremely flexible to use. This function undoubtedly provides great convenience for users. 3. Multiplication and division instructions, which also brings convenience to programming. Many eight-bit single-chip microcomputers do not have multiplication functions. When performing multiplication, you have to compile a subroutine call, which is very inconvenient. Disadvantages: (Although it is a classic, the disadvantages are still obvious) 1. AD, EEPROM and other functions need to be expanded, which increases the burden on hardware and software 2. Although the I/O pin is easy to use, it has no output capability when the level is high, which is also the biggest weakness of the 51 series microcontrollers 3. The running speed is too slow, especially the dual data pointer. If it can be improved, it will bring great convenience to programming 4. The protection ability of 51 is very poor, and it is easy to burn the chip Application range: Currently, it is widely used in teaching occasions and occasions with low performance requirements. The most used devices: 8051, 80C51 MSP430 microcontrollers The MSP430 series microcontrollers are a 16-bit ultra-low power mixed signal processor that Texas Instruments began to market in 1996. The biggest highlight left to people is low power consumption and fast speed, flexible assembly language, many addressing modes, few instructions, and easy to use. Mainly because it integrates many analog circuits, digital circuits and microprocessors on one chip to provide a "single-chip" solution for actual application needs. Its rapid development and expanding application scope are mainly due to the following characteristics… Characteristics: 1. Powerful processing capability, using a reduced instruction set (RISC) structure, with rich addressing modes (7 source operand addressing, 4 destination operand addressing), concise 27 core instructions and a large number of analog instructions; a large number of registers and on-chip data memory can participate in a variety of operations; there are also efficient table lookup processing instructions; high processing speed, with an instruction cycle of 125 ns under 8MHz crystal drive. These characteristics ensure that high-efficiency source programs can be compiled 2. In terms of computing speed, it can achieve an instruction cycle of 125ns under the drive of 8MHz crystal. 16-bit data width, 125ns instruction cycle and multifunctional hardware multiplier (capable of multiplication and addition) can realize some algorithms of digital signal processing (such as FFT, etc.) 3. In terms of ultra-low power consumption, the reason why MSP430 microcontroller has ultra-low power consumption is that it has its own unique features in reducing the power supply voltage of the chip and flexible and controllable operating clock. The power supply voltage adopts 1.8~3.6V voltage. Therefore, when it runs under the clock condition of 1MHz, the current of the chip will be around 200~400uA, and the minimum power consumption in the clock shutdown mode is only 0.1uA Disadvantages: 1. I personally feel that it is not easy to get started, not suitable for beginners, and there is relatively little information. I can only go to the official website to find it. 2. It occupies a large instruction space, because it is a 16-bit microcontroller, the program is in words, and some instructions actually occupy 6 bytes. Although the program is concise on the surface, it occupies a large space compared with PIC microcontrollers. Application range: It is widely used in low-power and ultra-low-power industrial occasions. The most used devices: MSP430F series, MSP430G2 series, MSP430L09 series TMS microcontrollers. Here we also mention the TMS series microcontrollers, although they are not mainstream. The 8-bit CMOS microcontroller launched by TI has multiple storage modes and multiple peripheral interface modes, which are suitable for complex real-time control occasions. Although it is not as good as STM32 and not as ostentatious as MSP430, the TMS370C series microcontrollers provide cost-effective real-time system control by integrating advanced peripheral function modules and memory configurations of various chips. At the same time, it is realized by high-performance silicon gate CMOS EPROM and EEPROM technology. Low operating power CMOS technology, wide operating temperature range, noise suppression, coupled with high performance and rich on-chip peripheral functions, make the TMS370C series microcontrollers have certain applications in automotive electronics, industrial motor control, computers, communications and consumer products. STM32 MCU is a series of MCU launched by ST. All the friends in the industry know that this is a series of MCU with super cost-effectiveness, which is the best and has powerful functions. It is based on the ARM Cortex-M core designed for embedded applications requiring high performance, low cost and low power consumption. It also has first-class peripherals: 1μs dual 12-bit ADC, 4Mbit/s UART, 18Mbit/s SPI, etc. It also has excellent performance in power consumption and integration. Of course, it is slightly inferior to the power consumption of MSP430, but this does not affect the engineers' enthusiasm for it. It is well-known in the industry for its simple structure and easy-to-use tools combined with its powerful functions... Its powerful functions are mainly manifested in: Features: 1. Core: ARM32-bit Cortex-M3CPU, maximum operating frequency 72MHz, 1.25DMIPS/MHz, single-cycle multiplication and hardware division 2. Memory: 32-512KB Flash memory is integrated on the chip. 6-64KB SRAM memory 3. Clock, reset and power management: 2.0-3.6V power supply and I/O interface drive voltage. POR, PDR and programmable voltage detector (PVD). 4-16MHz crystal. Embedded 8MHz RC oscillator circuit adjusted before delivery. Internal 40 kHz RC oscillator circuit. PLL for CPU clock. 32kHz crystal oscillator with calibration for RTC 4. Debug mode: Serial debug (SWD) and JTAG interface. Up to 112 fast I/O ports, up to 11 timers, up to 13 communication interfaces Most used devices: STM32F103 series, STM32 L1 series, STM32W series. PIC microcontroller PIC microcontroller series is a product of Microship in the United States. It is divided into three levels, namely basic level, intermediate level and advanced level. It is one of the microcontrollers with the fastest market share growth. The CPU adopts RISC structure, with 33, 35 and 58 instructions respectively, which belongs to the reduced instruction set. At the same time, it adopts Harvard dual bus structure, which has a fast running speed. It can make the access of program memory and data memory processed in parallel. This instruction pipeline structure completes two parts of work in one cycle, one is to execute instructions, and the other is to fetch the next instruction from the program memory. In this way, each instruction only needs one cycle, which is one of the reasons for high efficiency operation. In addition, the reason why PIC microcontroller has become a very popular microcontroller for a while is nothing more than the following features: Features: 1.It has the characteristics of low operating voltage, low power consumption, and strong driving ability. The I/O port of the PIC series microcontroller is bidirectional, and its output circuit is a CMOS complementary push-pull output circuit. The I/O pin has added a direction register for setting the input or output state, thus solving the problem that the 51 series I/O pin is both input and output when it is high level. 2. When it is set to 1, it is in the input state, and no matter whether the pin is high level or low level, it is in a high impedance state to the outside; when it is set to 0, it is in the output state, no matter what level the pin is, it is in a low impedance state, with considerable driving ability, low level suction current up to 25mA, high level output current up to 20mA. Compared with the 51 series, this is a great advantage 3. It can directly drive the digital tube display and the external circuit is simple. Its A/D is 10 bits, which can meet the accuracy requirements. It has online debugging and programming (ISP) function. Disadvantages: Its special registers (SFR) are not concentrated in a fixed address range (80~FFH) like the 51 series, but are scattered in four address ranges. Only five special registers PCL, STATUS, FSR, PCLATH, INTCON appear in four storage bodies at the same time, but in the programming process, it is inevitable to deal with special registers, and the corresponding storage body must be repeatedly selected, that is, the 6th bit (RP1) and the 5th bit (RP0) of the status register STATUS are set or cleared. Data transmission and logical operations are basically carried out through the working register W (equivalent to the accumulator A of the 51 series), and the 51 series can also be directly transmitted between registers. Therefore, the bottleneck phenomenon of PIC microcontrollers is more serious than that of the 51 series. Friends who are programming should have a deep understanding of this. The most used devices: PIC16F873, PIC16F877 AVR microcontrollers AVR microcontrollers are relatively new microcontrollers launched by Atmel, and their significant features are high performance, high speed, and low power consumption. It cancels the machine cycle, takes the clock cycle as the instruction cycle, and implements pipeline operation. AVR microcontroller instructions are in words, and most instructions are single-cycle instructions. A single cycle can execute the current instruction function and complete the reading of the next instruction at the same time. Usually the clock frequency is 4~8MHz, so the shortest instruction execution time is 250~125ns. AVR microcontrollers have become the most popular microcontrollers recently. The main features are: Features: 1. The AVR series does not have a structure similar to the accumulator A. It mainly uses the R16~R31 registers to implement the function of A. In AVR, there is no data pointer DPTR like the 51 series, but three 16-bit registers X (composed of R26, R27), Y (composed of R28, R29), and Z (composed of R30, R31) complete the function of data pointer (equivalent to three groups of DPTR), and can also perform post-increment or pre-decrement operations, while in the 51 series, all logical operations must be performed in A; while AVR can be performed between any two registers, eliminating the need to toss back and forth in A, which is better than the 51 series. 2. AVR's dedicated registers are concentrated in the 00-3F address range, and there is no need to select the storage body first like PIC, which is more convenient to use than PIC. The address range of AVR's on-chip RAM is 0-00DF (AT90S2313) and 0060-025F (AT90S8515, AT90S8535). They occupy the address of the data space. These on-chip RAMs are only used to store data and usually do not have the function of general registers. When the program is complex, the general registers R0~R31 are not enough; while the 51 series has up to 128 general registers (4 times that of AVR), so you won't feel this way when programming. 3. The I/O pins of AVR are similar to PIC. It also has a direction register for controlling input or output. In the output state, the high-level output current is about 10mA, and the low-level sink current is 20mA. Although this is not as good as PIC, it is still better than the 51 series... Disadvantages: 1. There is no bit operation, and the relevant register bits are controlled and judged in the form of bytes. 2. There are great differences in the writing methods between C language and 51's C language, which makes friends who start learning 51 microcontrollers very uncomfortable. 3. There are 32 general registers (R0~R31), and the first 16 registers (R0~R15) cannot directly deal with immediate numbers, so the versatility is reduced. In the 51 series, all its general registers (address 00~7FH) can directly deal with immediate numbers, which is obviously better than the former. The most commonly used devices: ATUC64L3U, ATxmega64A1U, AT90S8515 STC MCU When it comes to STC MCU, some people will say that STC can also be considered mainstream, and it is estimated that it will be criticized~~ We are talking about it based on the fact that it is a relatively good MCU in China. STC MCU is a single clock/machine cycle MCU produced by Hongjing. To put it bluntly, STC MCU is a combination of 51 and AVR. Some people say that AVR is a replacement MCU for 51, but there are great differences in bit control and C language writing of AVR MCU. The STC single-chip microcomputer combines the advantages of 51 and AVR. Although its functions are not as powerful as AVR, the functions found in AVR are basically available on STC. At the same time, the STC single-chip microcomputer is a 51 core, which provides great convenience for engineers based on 51 single-chip microcomputers and saves the time of learning AVR while retaining the various functions of AVR… The STC single-chip microcomputer is a new generation of 8051 single-chip microcomputer with high speed, low power consumption and super anti-interference. The instruction code is fully compatible with the traditional 8051, but the speed is 8 to 12 times faster, and it has an internal integrated MAX810 dedicated reset circuit. 4-channel PWM 8-channel high-speed 10-bit A, D conversion, for motor supplier control, strong interference occasions, become a new series of single-chip microcomputers after 51 single-chip microcomputer... Features: 1. Download the burning program with the serial port is convenient and easy to use, easy to use, with a large number of learning materials and videos, the most famous one is the video of Teacher Du, many friends who are interested in single-chip microcomputers are introduced through this video, and it has a wide voltage: 5.5 ~ 3.8V, 2.4 ~ 3.8V, low power consumption design: idle mode, power-down mode (can be awakened by external interrupt) 2. STC single-chip microcomputer has in-application programming, debugging is more convenient; with 10-bit AD, internal EEPROM, can work at 1T/machine cycle, the speed is 8~12 times that of traditional 51 single-chip microcomputer, the price is also cheaper 3. 4 Channel capture/compare unit, STC12C2052AD series has 2 channels, which can also be used to realize 4 more timers or 4 external interrupts, 2 hardware 16-bit timers, compatible with ordinary 8051 timers. 4-way PCA can also realize 4 more timers, with hardware watchdog, high-speed SPI communication port, full-duplex asynchronous serial port, compatible with ordinary 8051 serial port, and also has advanced instruction set structure, compatible with ordinary 8051 instruction set PS: Although the STC microcontroller is not as powerful as AVR and STM32, and the price is not as cheap as 51 and ST32, these are not important. What is important is that this is a relatively outstanding domestic microcontroller. I hope that domestic microcontrollers can go all the way... The most used device: STC12C2052AD Freescale microcontrollers are mainly for S08, S12 and other microcontrollers, of course Freescale microcontrollers are far from this. Freescale series of microcontrollers adopt Harvard structure and pipeline instruction structure, and they have shown the characteristics of low cost and high performance in many fields. Its architecture saves a lot of time for product development. In addition, Freescale provides a variety of integrated modules and bus interfaces, which can play a more flexible role in different systems! The unique features of Freescale microcontrollers are as follows: 1. Full range: From low-end to high-end, from 8-bit to 32-bit, the full range is available. The 8-bit/32-bit pin-compatible QE128 launched by it can be directly transplanted from 8-bit to 32-bit, making up for the missing link in the 8/32-bit compatible architecture of the microcontroller industry. 2. Multiple system clock modules: three modules and seven working modes. Multiple clock source input options, different MCUs have different clock generation mechanisms, which can be RC oscillators, external clocks or crystal oscillators, or internal clocks. Most CPUs have the above three modules at the same time! It can run in the seven working modes of FEI, FEE, FBI, FBILP, FBE, FBELP, and STOP. 3.Various communication module interfaces: Freescale microcontrollers integrate various communication interface modules internally: including serial communication interface module SCI, multi-master I2C bus module, serial peripheral interface module SPI, MSCAN08 controller module, universal serial bus module (USB/PS2) 4. More optional modules: LCD driver module, temperature sensor, ultra-high frequency transmission module, synchronous processor module, MCU with synchronous processor also has screen display module OSD, and a few MCUs have ring detection module RING and dual-tone multi-frequency/tone generator DMG module 5. High reliability, strong anti-interference, multiple pin counts and packaging options 6. Low power consumption, maybe the power consumption of Freescale series microcontrollers is not as low as that of MSP430, but it has two fully static "wait" and "stop" modes, which can reduce your power consumption overall! Several recently launched ultra-low power consumption models are comparable to MSP430! The most used device: MC9S12G series Paimingxincheng Tel: 400-693-8369 If you really want to rank these microcontrollers, then if you want to follow the crowd, the 51 microcontroller is the first choice; if you pursue ultra-high cost performance, STM32 will be your ideal choice; if you desire ultra-low power consumption, MSP430 will definitely not let you down; if you want to support domestic products, STC will excite you.
This post is from 51mcu
 
Personal signaturehttps://www.iczoom.com
 
 

31

Posts

0

Resources
10
 
  void InitPort(void) { P0M1=0x00; P0M0=0xff; P24=1; P2M1=0x10; P2M0=0x88; P41=1; P4M1=0x02; P4M0=0x04; }
This post is from 51mcu
 
Personal signaturehttps://www.iczoom.com
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list