The various data registers and control registers inside a 32-bit microcontroller are all 32 bits. Similarly, the data and control registers inside an 8-bit microcontroller are all 8 bits.
For example:
The definition of "interrupt control register" IE of AT89C51 microcontroller is shown in the figure below:
bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 |
EA | reserve | ET2 | ES | ET1 | EX1 | ET0 | EX0 |
The definition of LPC1114's "AHB bus clock control register" SYSAHBCLKCTRL is shown in the figure below:
bit31 | bit30 | bit29 | bit28 | bit27 | bit26 | bit25 | bit24 |
reserve | reserve | reserve | reserve | reserve | reserve | reserve | reserve |
bit23 | bit22 | bit21 | bit20 | bit19 | bit18 | bit17 | bit16 |
reserve | reserve | reserve | reserve | reserve | SSP1 | reserve | IOCON |
bit15 | bit14 | bit13 | bit12 | bit11 | bit10 | bit9 | bit8 |
WDT | reserve | ADC | UART | SSP0 | CT32B1 | CT32B0 | CT16B1 |
bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 |
CT16B0 | GPIO | I2C | FLASH2 | FLASH1 | RAM | ROM | SYS |
The above two control registers, one is 8-bit and the other is 32-bit. The similarity between them is that each bit determines a task. For example, writing 1 to bit4 of the IE register of the AT89C51 microcontroller can turn on the serial port interrupt, and writing 0 can turn off the serial port interrupt. Writing 1 to bit6 of the AHBCLKCTRL register of the LPC1114 microcontroller means turning on the GPIO working clock, and writing 0 means turning off the GPIO working clock.
The IE register mentioned above can be used to enable the general interrupt with IE=0x80, or directly write EA=1 to enable the general interrupt. The way to enable with EA=1 is "bit operation". Compared with directly writing the register value, "bit operation" will change the value of the entire register, while "bit operation" will not change other values in the register.
The registers of the LPC1114 microcontroller do not support "bit operations". In order to operate a certain bit without affecting the values of other bits, we need to use the logical "or" and "and" operations of the C language.
For example:
Write 1 to bit6 of the SYSAHBCLKCTRL register:
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
Write 0 to bit6 of the SYSAHBCLKCTRL register:
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<6);
In the header file lpc11xx.h, each register is defined by the structure of each module, so when we want to write a value to a register, we need to use the symbol "->" to assign a value to a member variable of the structure. In the above formula, the SYSAHBCLKCTTL register is located in the structure LPC_SYSCON, so when assigning a value to the register, we need to write it like this.
1<<6 means 1 is shifted to the left by 6, that is:
The 32-bit number 1 is represented in binary as 000000000000000000000000000000001
The 32-bit number 1 shifted left 6 times becomes 000000000000000000000000001000000
The left-shifted data is "OR"ed with the value in SYSAHBCLKCTRL. The logic of "OR" is 0, "OR" any number is any number, and 1, "OR" any number is 1, so the result is only bit6 set to 1.
Similarly, we can analyze the statement that writes 0 to bit6. These are all basic knowledge of C language. Please believe that experts do not have special skills, but have mastered a solid foundation.
Special note: The two statements for writing registers above may seem complicated at first glance, but they are actually very simple! When we want to write a value to a certain bit of a register in the future, for example, to write 1 to bit n of the BB register of the AA module, we can apply the above formula, that is:
AA->BB |=(1< Similarly, to write 0 to bit n, that is: AA->BB&=~(1< Dear! Congratulations, you have learned most of it.
Previous article:18b20 measuring temperature - lpc1114
Next article:Pin overview of ARM Cortex M0 LPC1114
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- MSP430F5438 clock system
- Repair of FOTILE embedded electric steamer, the water level sensor failed and the circuit was broken because of a small resistor
- EEWORLD University Hall----Live Replay: AVNET uses MPLAB? Ecosystem and Curiosity Nano Development Board to create an innovative development workflow
- BleuNRG-1 one master and multiple slaves master module search interval setting
- How to use iic to make LCD screen display
- Design of MSP430 and MMC/SD card interface
- An Engineer's Guide to Temperature Sensing
- N ways to program the development board
- Analysis of Rectification Circuit and Filter Circuit
- Learn more about logic analyzers