Phone

    00852-6915 1330

microcontroller Related Articles

Stay Ahead with Expert Electronics Insights,
Industry Trends, and Innovative Tips

IC Chips

Different Types of Microcontrollers and Their Applications

Microcontrollers, also known as embedded controllers, are integrated circuit (IC) chips that contain all the components of a small computer on a single chip. A microcontroller incorporates key elements like a central processing unit (CPU), memory, input/output peripherals, and timers. Microcontrollers are embedded into larger systems and devices to provide automated and precise control. They have become ubiquitous in modern electronic devices due to their small size, low power consumption, and low cost. How Microcontrollers Work Although microcontrollers operate at high speeds, they execute instructions sequentially, unlike a typical computer. When powered on, the control logic register activates the quartz oscillator, charging the parasite capacitors briefly during initial setup. Once the oscillator frequency stabilizes at maximum voltage, the bit-writing process through special function registers commences based on the oscillator's clock cycle. All the electronics start functioning in nanoseconds according to this sequence. A microcontroller's main function is to operate as an independent unit utilizing its on-chip processor and memory. It can leverage its built-in peripherals similarly to an 8051 microcontroller. Classification by Bus Width The bus width refers to the number of parallel data lines in a microcontroller. Wider buses allow more data to be transferred simultaneously, increasing throughput. Microcontrollers are classified into 8-bit, 16-bit, and 32-bit architectures based on their bus width: 8-Bit Microcontrollers: These possess an 8-bit wide data bus, permitting 8 bits of data to be processed in one clock cycle. However, arithmetic operations on larger data sizes prove challenging. Popular examples include the Intel 8051, Motorola 68HC11, and Microchip PIC microcontrollers. Example Part:Part Number: ATmega328PManufacturer: Microchip TechnologyDescription: The ATmega328P is a popular 8-bit microcontroller used in Arduino boards. It features 32KB of flash memory, 2KB of SRAM, and 1KB of EEPROM. 16-Bit Microcontrollers: With their 16-bit bus, these can transfer 16 bits of data per cycle. Their 16-bit arithmetic logic unit (ALU) improves performance over 8-bit designs. The Motorola 68HC12 and Microchip PIC24 are common 16-bit microcontrollers.Example Part:Part Number: PIC24FJ128GA010Manufacturer: Microchip TechnologyDescription: The PIC24FJ128GA010 is a widely used 16-bit microcontroller with 128KB of flash memory, 8KB of RAM, and various peripherals. It is known for its low power consumption and high performance. 32-Bit Microcontrollers: Featuring a 32-bit bus width, these offer the highest throughput and precision. Complex applications like audio/video processing benefit from their fast processing capabilities. The Microchip PIC32 and Atmel AVR32 are 32-bit microcontroller product families.Example Part:Part Number: STM32F407VGManufacturer: STMicroelectronicsDescription: The STM32F407VG is a popular 32-bit microcontroller based on the ARM Cortex-M4 core. It offers 1MB of flash memory, 192KB of SRAM, and a wide range of peripherals, making it suitable for demanding applications. Classification by Memory Microcontrollers contain memory in two broad configurations:Embedded Memory Microcontrollers: In these microcontrollers, all required memory blocks like RAM, ROM, and flash are integrated on the single chip. The memory capacity is fixed and cannot be expanded externally in most cases. External Memory Microcontrollers: These have some memory blocks located off-chip, requiring external memory modules to function fully. While external memory increases capacity, it also increases the size and cost of the total system. Classification by Architecture The architecture defines how a microcontroller accesses its memory and executes instructions:Harvard Architecture: Program and data memory are separated in this design. Instructions and data can be accessed simultaneously via different buses, allowing for faster execution. The program memory stores code while data memory handles variables. Von Neumann Architecture: This uses a unified memory for both instructions and data. While simpler, it can experience bottlenecks from conflicting demands on the single memory bus. Most personal computers use the Von Neumann model. Modified Harvard Architecture: This attempts to get the best of both worlds by using a separate program and data memory but having a shared bus. This avoids conflicts while retaining fast access. Many modern microcontrollers leverage modified Harvard architectures. Classification by Instruction Set The instruction set architecture (ISA) consists of the basic commands and functions that a microcontroller CPU understands:CISC (Complex Instruction Set Computer): CISC microcontrollers have a large, complex set of instructions that enable programs to be coded efficiently in fewer lines. But the complexity slows operation. RISC (Reduced Instruction Set Computer): RISC ISAs use simpler instructions that execute rapidly, although programs require more lines of code. High-performance microcontrollers often employ RISC cores. Applications of Microcontrollers The versatility of microcontrollers enables them to be embedded into a diverse range of devices and machines:Automotive Systems: Microcontrollers monitor and control electrical systems in vehicles, including engine control modules, power windows, and anti-lock brakes. Industrial Automation: Microcontrollers provide precision programmable control of manufacturing processes, robotics, and assembly lines. Consumer Electronics: Appliances, gaming systems, and smart home devices rely on microcontrollers for automated and interactive capabilities. Medical Devices: Miniaturized microcontrollers allow smart medical devices to diagnose conditions, deliver treatments, and monitor patient health. Communications: Microcontrollers enable complex signal processing in modems, routers, cell phones, and other network gear. Aerospace Systems: Rugged, radiation-hardened microcontrollers are built for flight control, guidance systems, and other avionics applications. Conclusion Microcontrollers pack the power of a small computer into a single, highly-integrated chip. They are categorized based on criteria like bus width, memory architecture, and instruction set. Microcontrollers provide intelligent and precise control capabilities that have revolutionized embedded system design across industrial, consumer, medical, and communications applications. As microcontroller technology continues advancing, more innovative and personalized edge devices will emerge. FAQs Q1: What is the difference between a microcontroller and a microprocessor?A: A microcontroller is a single chip that integrates components like CPU, memory, and I/O interfaces. A microprocessor is just a CPU chip that requires external memory and peripherals. Microcontrollers are self-contained, low cost, and can independently complete control tasks. Microprocessors offer more power but need complex circuit design.Q2: What are the pros and cons of 8-bit vs 32-bit microcontrollers?A: 8-bit microcontrollers have an 8-bit data bus width, lower performance, and simpler design while being low cost. 32-bit microcontrollers have higher processing power and faster execution but also higher cost. 8-bit MCUs are good for simple applications while 32-bit suits more demanding tasks.Q3: How do Harvard and Von Neumann architectures differ in microcontrollers?A: The Harvard architecture has separate program and data memory buses, allowing simultaneous access and faster execution. The Von Neumann architecture uses unified memory for programs and data, causing bus contention and slower speed. Harvard architecture offers stronger real-time control capabilities.
Kynix On 2023-09-25   333
IC Chips

How Embedded Controllers are Changing the World

  With the evolving times and fast-advancing technologies, smart devices, computerized systems and other industrial applications are heavily relying on miniature computing.  In today’s world, embedded systems are a critical part of the daily average person ranging from their application in homes, offices, industries and even personal gadgets.   These embedded systems have become a crucial part of real life partly due to their ease of use, minimal intervention and availability. The engineering behind these systems is to meet the requirements while being efficient, low powered and meeting essential demands. Some of the devices that we used daily with smart devices include microwaves, smart ovens, refrigerators, washing machines, and smart lighting, to mention but a few.   Artificial intelligence and machine learning in recent days have been in the limelight with many investors and a major key player in the world of technology contributing to its growth. The application of machine learning and artificial intelligence is virtually limitless. The heart of most devices using this technology are embedded systems. As the use of embedded systems continues to grow within every industry and sector, so does technology.   Embedded systems and embedded controllers are often used interchangeably and for the most part, can pass for each other. However, there is a slight difference in meaning. Embedded Systems vs Embedded Controllers An embedded system is a combination of hardware and software designed for a specific purpose, often with real-time constraints. It typically consists of a microcontroller, memory, input/output peripherals, and sometimes additional hardware such as sensors or actuators. Embedded systems are used in a wide range of applications, including consumer electronics, automotive, aerospace, and industrial automation.   An embedded controller is a type of microcontroller, often just referred to as a microcontroller, that is specifically designed for controlling a specific device or system. It is typically used in embedded systems that require precise control over the operation of mechanical or electrical components. Embedded controllers often have specialized features such as analogue-to-digital converters, timers, and communication interfaces that make them well-suited for controlling a specific system.   In general, an embedded controller is a specific type of microcontroller that is designed to perform a specific function within an embedded system. Meanwhile, an embedded system can consist of various components, including microcontrollers, and is designed to perform a specific task or set of tasks. Thus, an embedded system is the device and interface that we interact with daily while the microcontroller is the control unit that gives life to the technology.   Over the years, embedded controllers have evolved significantly with major improvements and advancements from the earliest microprocessors and iterations of a microcontroller to the advanced microcontrollers we use today. Why embedded controllers Embedded controllers are found in a wide variety of devices, products and systems from household appliances and medical devices to industrial machinery and automotive systems. Their application also can be vastly diverse from simple automation applications such as light control to entire industrial automation setups. With the rise of IoT and industrial application of IoT (IIoT), applications in the industrial sector have rapidly expanded.   Aside from their simplicity, inexpensiveness and a vast array of applications, embedded systems are chosen for their other advantages. Compared to traditional computers and microprocessors, embedded controllers are the key enablers of modern automation.   Here are a few key indicators of how embedded systems have evolved and changed the world of automation and modern miniaturized computing: Improved efficiency  Embedded controllers are helping to improve efficiency in a variety of applications, from smart homes to industrial automation. By automating routine tasks and optimizing processes, these controllers can help reduce waste, save energy, and streamline operations.   Enhanced functionality  Embedded controllers are enabling new and innovative features in a wide range of products, from cars and smartphones to medical devices and appliances. These controllers are making it possible to deliver new levels of performance, functionality, and convenience to consumers and businesses.   Increased automation Embedded controllers are helping to drive the automation of many industries, from manufacturing and logistics to agriculture and healthcare. By automating routine tasks, these controllers can help increase productivity, reduce costs, and improve quality control.   Greater precision and accuracy Embedded controllers are enabling greater precision and accuracy in many applications, from medical devices and scientific instruments to automotive systems and consumer electronics. By controlling and monitoring specific functions, these controllers can help ensure that products and systems operate reliably and accurately.   Advancements in technology Embedded controllers are driving advancements in technology, from the Internet of Things (IoT) to autonomous vehicles and smart cities. These controllers are enabling the development of new technologies and systems that are transforming the way we live, work, and interact with the world around us.   Integration of communication interfaces In the mid-2000s, microcontrollers began to integrate communication interfaces, such as Ethernet, Wi-Fi, and Bluetooth, which made it possible to connect devices to the internet and other devices. This paved the way for the development of the Internet of Things (IoT).   Advancements in power efficiency In recent years, microcontrollers have become more power-efficient, with the development of low-power processors, sleep modes, and power management systems. This has enabled the development of battery-powered devices that can operate for extended periods.   Advanced functionality and security Today's microcontrollers offer advanced functionality, such as real-time operating systems, graphics processing, and machine learning capabilities. They also incorporate advanced security features to protect against cyber threats.   Embedded controllers are shaping the world we live in, enabling new levels of efficiency, functionality, and automation across a wide range of industries and applications. As technology continues to advance, microcontrollers are likely to continue to evolve and play an increasingly important role in our lives.   Exploring Embedded Controllers in Real Life As earlier said, the application of embedded controllers has become immense and the potential of further exploration is still underway. With these advancements and vast applications, the impact of this technology is revolutionary and is shaping the future.   Embedded controllers are changing the world in several ways, thanks to their ability to improve efficiency, increase productivity, and enhance functionality in a wide range of applications. Here are a few examples:   Smart Home Automation and Home Appliances In terms of vast applications and the most widely explore uses of embedded controllers, home automation carries the day. This is perhaps due to the simplicity of using embedded controllers and embedded systems, enabling small applications, simple smart devices, DIY projects of automation and other reliable solutions to smart monitoring and even security systems. Embedded controllers are a key component of the smart home revolution, enabling homeowners to remotely monitor and control their appliances, heating and cooling systems, security systems, and more. This allows for greater energy efficiency, convenience, and comfort.   Health Management Systems Embedded controllers are playing an important role in healthcare, enabling the development of advanced medical devices that can monitor and administer medication with greater accuracy and precision. This improves patient outcomes and reduces the risk of errors.   Medical Devices Over the longest time, medical devices and other healthcare-related systems have tried to incorporate embedded systems. This allows for easier monitoring, management and even automation of simple processes. The systems can gather and collect data on a patient’s condition and monitor progress in treatment by monitoring heart rate, pulse rate and other vitals. The information can be relayed to caregivers or doctors via the cloud.   Medical devices, such as pacemakers and insulin pumps, rely on embedded controllers to monitor vital signs and even administer medication. These controllers are designed to operate reliably and accurately in a wide range of conditions Automobiles and Autonomous Vehicles With the advent of the booming exploration in autonomous and self-driving vehicles, such as self-driving cars, autonomous submarines and unmanned drones, the use of embedded controllers has played a key role. Providing navigation systems, IoT modules, battery management systems and other subsystems that relay all the needed data to the users. Embedded controllers are a critical component of autonomous vehicles, enabling them to monitor their surroundings, make decisions, and take action without human intervention. This has the potential to revolutionize transportation and make it safer and more efficient.   In modern automobiles, embedded systems are designed and fitted to provide a better customer experience whilst also providing enhanced safety on the road. The result of this has been realized with lower traffic fatalities over the years.Adaptive speed control, automobile breakdown warning, pedestrian detection, merging assistance, airbags, and other active safety systems are some prominent examples. These are a few of the characteristics that are expected to reduce the risk of accidents and increase demand for embedded systems throughout the world.   Industrial automation With Industry 4.0 on the cusp of fruition, embedded controllers are playing a vital role in its realization being the link between modern technology, IoT and industrial systems. Most industrial systems and setups are adopting machine learning and artificial intelligence to improve work efficiency, accuracy, repeatability, and safety and reduce the cost of labour. This is possible since machines using sophisticated algorithms can identify defects, reduce downtime and diagnose systems before failure.   Embedded controllers are used in industrial automation systems to control machinery and monitor production processes. These controllers can operate in harsh environments and are designed to withstand high temperatures, vibrations, and other stresses. In such applications robots are designed to perform tasks that are considered dangerous. Robots are equipped with embedded systems, employing the use of sensors actuators and feedback from other systems to perform the tasks safely.   Consumer electronics Devices like smartphones, tablets, and smart speakers use embedded controllers to manage their complex functions and interfaces. These controllers help to optimize battery life, reduce power consumption, and enhance user experiences.   Overall, the evolution of microcontrollers has enabled the development of a wide range of devices and systems, from simple household appliances to complex industrial machinery and the Internet of Things. As technology continues to advance, microcontrollers are likely to continue to evolve and play an increasingly important role in our lives.   FAQs What is an embedded controller? An embedded controller, also known as a microcontroller, is a small computer system that is designed to control and manage specific tasks within electronic devices.   Embedded controllers are changing the world in several ways, such as improving efficiency, enhancing functionality, increasing automation, and enabling new technologies and systems.   What are some examples of applications that use embedded controllers? Examples of applications that use embedded controllers include smart homes, medical devices, automotive systems, industrial automation, and the Internet of Things (IoT).   Embedded controllers are playing an important role in healthcare, enabling the development of advanced medical devices that can monitor and administer medication with greater accuracy and precision, leading to improved patient outcomes and reduced risk of errors.   Embedded controllers are a critical component of the IoT, enabling devices to communicate with each other and with the internet, and enabling the development of new technologies and systems that are transforming the way we live and work.   What are some future developments in embedded controllers? Future developments in embedded controllers are likely to include advancements in processing power and memory, integration of communication interfaces, improvements in power efficiency, and advanced functionality such as machine learning and artificial intelligence          
Karty On 2023-03-27   327
Transmitters

RS485 Serial Communication Protocol

IntroductionWhat is RS485?MaterialsMAX485 pinoutHalf duplex operationHere is how the program worksFull duplex operationHalf duplex operation codeFull duplex codeIntroductionIn digital computer communication between two computers can be made using either parallel or serial method. In parallel communication separate line is dedicated for a one-bit information to transfer. This communication is fast and easy, but it requires a lot of wires at least as many as the number of bits need to be sent in parallel. For example, to transfer a 64-bit data from one device to another, 64 data lines will be required which is impractical in embedded systems. The alternative method to transfer data is to use serial communication. In serial communication one bit at a time is transferred from one device to another one. While this method solves the wiring problem it has a lot of other problems such as bandwidth, data lagging, complex protocol, and electrical standards. There are lot of different methods to do serial communication while one method is good in one situation another one is better in another situation. In this article we will discuss RS485 communication protocol which is one of the many available serial communication methods.Materials1MAX485 module2STM32 F401CDU6What is RS485?An industry specification called RS-485 outlines the physical layer and electrical interface for point-to-point electrical device communication. RS485 is the industrial standard for communication that defines the electrical interface and physical layer for point-to-point communication. RS485 is a robust communication system it can support multiple devices on a single bus, works in a noisy environment as well and requires a maximum of 4 lines.RS485 was first developed in 1983 and has since been used in many industrial applications because of its robustness and simplicity. It has the ability to transmit data over long distances while at the same time it is cheap, thus engineers are using it in all sorts of applications such as automotive, manufacturing, and theater spaces. Nowadays almost all motor controllers, VFDs and manufacturing machines will have a port available for RS485.RS485 is actually a standard that defines the electrical characteristics of the transmitters and receivers for communication protocols. RS482 uses two lines usually called A and B which must be balanced and differential. It means that the two lines must have same impedance, nearly same length and must be differential. The key features of RS485 communication are given belowMultipoint operation10 Mbps data transfer rate at 40 feet lengthMaximum cable length is 4000 feetRS485 works both in half duplex as well full duplex mode. In half duplex mode one device can either transmit or receive data at a time. While in full duplex mode, a device can transmit and receive data at the same time. Having more than one device on a bus can cause problem when two or more devices transmit data at the same time. Therefore, software control is necessary to ensure only one device transmit data at a time.RS485 is the physical layer of communication in the OSI model. It means this layer can be used as a base for other protocols such as UART which in most application people use because UART is an asynchronous communication protocol that does not require any clock signal which make it very easy to use. In this article we will demonstrate how RS485 can be used between two STM32 microcontrollers to communicate and exchange data. We will be using MAX485 module which is an easily available RS485 module. MAX485 pinoutRO → Receiver outputRE → Receiver enableDE → Data enableDI → Data inputVCC → Input voltageGND → GroundA, B → RS485 differential linesHalf duplex operationIn half duplex operation either data can be received or transmitted at a time. Both operations cannot be done at the same time. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. Making them low puts the module in receiving mode while making them high puts the device in transmitter mode.In CubeMX the microcontroller of our choice is selected which in our case is STM32 F401CDU6. In connectivity UART1 should be enabled with 115200 bps baud rate. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSEGPIO A7 is set as outputHere is how the program worksThe setup has two microcontrollers. We will call one side as A and the other side as B. When a user presses the user key on A STM32 microcontroller it will send the information to the B microcontroller via RS485. The receiving B microcontroller will switch on the onboard LED and will responds with an OK message. The OK message will blink the led on A microcontroller twice. Similarly, when the user presses key on B microcontroller it will transmit a message to A microcontroller and turns on the onboard LED and will responds with an OK message. The OK message will blink LED on B microcontroller twice. Similarly pressing the button again will do the same except this time it will turn off the LED.Full duplex operationIn full duplex operation data can be received or transmitted at the same time. Both operations can be done at the same time. In this mode two MAX485 modules will be required at each end and overall, 4 MAX485 modules will be used. It means that the two MAX485 modules will be constantly in receiving mode while the other two will constantly in transmission mode. MAX485 has data flow control pins called DE and RE which puts the module in receiver mode or in transmit mode. We will put the data control pins of two module as high while put the data control pins of other two module low. The configuration is shown below.The program works the same way as it was working in the half duplex mode however, this time the transmitted and received by MCUs at the same time.Half duplex operation code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){   HAL_Init();   SystemClock_Config();     MX_GPIO_Init();  MX_USART1_UART_Init();  /* USER CODE BEGIN 2 */  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);   //Put RS485 module in receiving mode  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);   //Turn Off LED pin    while (1)  {      HAL_UART_Receive(&huart1, R_Data, 1, 10);  // If button is pressed on the other MCU  if(R_Data[0] == 83)  {  HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);                //Toggle LED pin  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);    //Put RS485 module in transmission mode  HAL_UART_Transmit(&huart1, T_Data, 1, 10);             //Send acknowledgment  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  //Put RS485 module in transmission mode  R_Data[0] = 0;  }  // If OK message is receive  if(R_Data[0] == 69)  {  if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13))  {  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  }  else  {  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  }  R_Data[0] = 0;  }  // Button is pressed  if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))  {  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);    //Put RS485 module in transmission mode  T_Data[0] = 83;  HAL_UART_Transmit(&huart1, T_Data, 1, 10);  T_Data[0] = 69;  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);    //Put RS485 module in Receiving mode  }  }  /* USER CODE END 3 */}Full duplex code#include "main.h" UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */int8_t R_Data[1] = {0};int8_t T_Data[1] = {69};/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_USART1_UART_Init(void); int main(void){   HAL_Init();   SystemClock_Config();     MX_GPIO_Init();  MX_USART1_UART_Init();  /* USER CODE BEGIN 2 */  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);   //Turn Off LED pin    while (1)  {      HAL_UART_Receive(&huart1, R_Data, 1, 10);  // If button is pressed on the other MCU  if(R_Data[0] == 83)  {  HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);                //Toggle LED pin  HAL_UART_Transmit(&huart1, T_Data, 1, 10);             //Send acknowledgment  R_Data[0] = 0;  }  // If OK message is receive  if(R_Data[0] == 69)  {  if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13))  {  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  }  else  {  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);  HAL_Delay(500);  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);  }  R_Data[0] = 0;  }  // Button is pressed  if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))  {  T_Data[0] = 83;  HAL_UART_Transmit(&huart1, T_Data, 1, 10);  T_Data[0] = 69;  }  }  /* USER CODE END 3 */}  
Victoria On 2022-10-26   821
IC Chips

4×4 matrix keypad in STM32

Keypads are input devices that are being widely used in many embedded system projects. It can be found in appliances, door locks, and industrial machines. Keypads are used to take input from the user in the form of numbers or characters which can further be used for processing such as password, menu selection and navigating among different options. One of the most common and low-cost keypads is the matrix keypad with 4×4 or 3×3 buttons. In this article we will discuss how a low cost 4×4 matrix keypad can be used in STM32. Before proceeding further, we will need to know few things.Materials14×4 matrix keypad2STM32 F401How a 4×4 keypad works? 4×4 keypadIn microcontrollers usually a pin is used to take input from the user. This input can be either 1 or 0. Multiple 1’s and 0’s can be combined to store more information. For this purpose, multiple input pins will be required. However, this becomes impractical when the input pins required exceed certain number such as 16 or 9 as the microcontrollers do not have this many pins available.The 4×4 matrix keypad solves this problem and reduced the required number of pins to 8 or 6. It  is made of a thin and flexible membrane. The 16 keys of the 4 x 4 keypad module are arranged in a matrix of rows and columns. A copper trace connects each of these switches to the others. The rows and column are not connected to each other in normal condition. When we push a key, a column and a row come into contact with each other. In matrix keypads the buttons are divided among rows and columns. Four buttons lie on each row and each column. Thus, columns are connected to external input pins of microcontroller while the rows are connected to output pins of microcontroller. The output pins are high all the time. When a button is pressed the corresponding column goes high and the microcontroller detects it. Finding which column has been activated is easy as each column is connected to a separate pin, however, finding a row is difficult. Once both row and column are identified then the corresponding button can be identified. A clever method to identify the pressed key is to switch off all output pins except one, and then check which input pins is high. Doing this for all the output pins will identify the row. Once the row number is found out, the button can easily be traced out.matrix keypad in STM32STM32 F401 implementationSTM32 F401In CubeMX the relative microcontroller of our choice is selected which in our case is STM32 F401CDU6. The GPIOs that need to be selected as output or external interrupt input are given in the figure above. In the NVIC tab the interrupt should be enabled. Other necessary settings are given below.RCC → Crystal/Ceramic ResonatorSYS → Debug → Serial WireClock Configuration → HCLK → 84 MHzClock Configuration → PLL Source Mux → HSE Once the CubeMX code is generated the following code should be added to the /* USER CODE BEGIN PV */ section./* USER CODE BEGIN PV */  GPIO_InitTypeDef GPIO_InitStructPrivate = {0};  uint32_t previousM = 0;  uint32_t currentM = 0;  uint8_t key = 0;  uint8_t InputData[5] = {0};  int i = 0;/* USER CODE END PV */This code section defines the necessary variables that will come handy later.In the main.c section in /* USER CODE BEGIN 2 */ the output configured pins should be set to 1.  /* USER CODE BEGIN 2 */  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);  /* USER CODE END 2 */  While the interrupt callback function void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) should be added to /* USER CODE BEGIN 4 */ section.void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){  currentM = HAL_GetTick();  if (currentM - previousM > 10) {    /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/    GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;    GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT;    GPIO_InitStructPrivate.Pull = GPIO_NOPULL;    GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW;    HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate);     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 68; //ASCII value of D    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 67; //ASCII value of C    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 66; //ASCII value of B    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 65; //ASCII value of A    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 35; //ASCII value of #    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 57; //ASCII value of 9      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 9;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 54; //ASCII value of 6      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 6;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 51; //ASCII value of 3      if (i == 4)            {             //Send Data            }            else            {             InputData[i] = 3;            }            if(i <= 4)            {             i = i + 1;             }            else            {             i = 0;            }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 48; //ASCII value of 0      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 0;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 56; //ASCII value of 8      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 8;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 53; //ASCII value of 5      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 5;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 50; //ASCII value of 2      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 2;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 42; //ASCII value of *     }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 55; //ASCII value of 7      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 7;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 52; //ASCII value of 4      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 4;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 49; //ASCII value of 1      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 1;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);    /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/    GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING;    GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN;    HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate);    previousM = currentM;   }} In the callback function the two linescurrentM = HAL_GetTick();  if (currentM - previousM > 10)takes care of the debouncing of the buttons. In keypad it is a common problem that a but hits once is recorded twice or thrice. So, take of that, a little delay is added at the beginning of callback function.The complete code is given below.#include "main.h" /* USER CODE BEGIN PV */  GPIO_InitTypeDef GPIO_InitStructPrivate = {0};  uint32_t previousM = 0;  uint32_t currentM = 0;  uint8_t key = 0;  uint8_t InputData[5] = {0};  int i = 0;/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);/* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*//* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /**  * @brief  The application entry point.  * @retval int  */int main(void){  /* USER CODE BEGIN 1 */   /* USER CODE END 1 */   /* MCU Configuration--------------------------------------------------------*/   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */  HAL_Init();   /* USER CODE BEGIN Init */   /* USER CODE END Init */   /* Configure the system clock */  SystemClock_Config();   /* USER CODE BEGIN SysInit */   /* USER CODE END SysInit */   /* Initialize all configured peripherals */  MX_GPIO_Init();  /* USER CODE BEGIN 2 */  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);  /* USER CODE END 2 */   /* Infinite loop */  /* USER CODE BEGIN WHILE */  while (1)  {    /* USER CODE END WHILE */     /* USER CODE BEGIN 3 */  }  /* USER CODE END 3 */}  /* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){  currentM = HAL_GetTick();  if (currentM - previousM > 10) {    /*Configure GPIO pins : PB6 PB7 PB8 PB9 to GPIO_INPUT*/    GPIO_InitStructPrivate.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;    GPIO_InitStructPrivate.Mode = GPIO_MODE_INPUT;    GPIO_InitStructPrivate.Pull = GPIO_NOPULL;    GPIO_InitStructPrivate.Speed = GPIO_SPEED_FREQ_LOW;    HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate);     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 68; //ASCII value of D    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 67; //ASCII value of C    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 66; //ASCII value of B    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 65; //ASCII value of A    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 35; //ASCII value of #    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 57; //ASCII value of 9      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 9;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 54; //ASCII value of 6      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 6;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 51; //ASCII value of 3      if (i == 4)            {             //Send Data            }            else            {             InputData[i] = 3;            }            if(i <= 4)            {             i = i + 1;             }            else            {             i = 0;            }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 48; //ASCII value of 0      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 0;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 56; //ASCII value of 8      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 8;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 53; //ASCII value of 5      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 5;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 50; //ASCII value of 2      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 2;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);    if(GPIO_Pin == GPIO_PIN_6 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6))    {      key = 42; //ASCII value of *     }    else if(GPIO_Pin == GPIO_PIN_7 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7))    {      key = 55; //ASCII value of 7      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 7;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_8 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8))    {      key = 52; //ASCII value of 4      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 4;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }    else if(GPIO_Pin == GPIO_PIN_9 && HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9))    {      key = 49; //ASCII value of 1      if (i == 4)      {       //Send Data      }      else      {       InputData[i] = 1;      }      if(i <= 4)      {       i = i + 1;       }      else      {       i = 0;      }    }     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1);    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);    /*Configure GPIO pins : PB6 PB7 PB8 PB9 back to EXTI*/    GPIO_InitStructPrivate.Mode = GPIO_MODE_IT_RISING;    GPIO_InitStructPrivate.Pull = GPIO_PULLDOWN;    HAL_GPIO_Init(GPIOB, &GPIO_InitStructPrivate);    previousM = currentM;   }}  
Allen On 2022-10-17   1082
Resistors

Popularization of Science - MCU

CatalogIntroductionⅠ What is a Microcontroller(MCU)?Ⅱ The History of the Microcontroller (MCU)Ⅲ The Classification and Application of MCUⅣ China MCU Technology and Well-known ManufacturersⅤ  The Basic Functions of MCUⅥ Learning Methods - Using MCUⅦ Six Main Dimensions of MCU Products for Future ImprovementⅧ Programming of MCUⅨ Summary of the MCU Programming EngineerⅩ How to Develop MCU Ⅺ 5 Tips to Solve the Questions About the MCU CrystalⅫ Summary of Chip OperationFAQIntroductionA microcontroller (MCU) is a small computer built on a single metal-oxide-semiconductor (MOS) integrated circuit (IC) chip. A microcontroller is made up of a CPU  (processor core), memory, and programmable input/output peripherals. On chip, a small amount of RAM, as well as ferroelectric RAM, NOR flash, or OTP ROM , is commonly included. Microcontrollers  , in contrast to microprocessors  used in personal computers  or other general-purpose applications, are designed for embedded applications and are made up of a number of discrete chips. This article will delve deeper into the MCU.Ⅰ What is a Microcontroller(MCU)? Microcontroller UnitThe microcontroller unit (MCU) appropriately reduces the frequency and specifications of the CPU  and integrates peripheral interfaces such as memory, counter, USB, A/D conversion, UART, PLC, and DMA. At the same time, even the LCD driver circuit is integrated on a single chip to form a chip-level computer, which can be controlled in different combinations for different applications, such as mobile phones, PC peripherals, remote controls, automotive electronics, industrial stepping motors, machines The control of the arm, etc., can be seen in the MCU.Figure 1 MCU componentsⅡ The History of the Microcontroller (MCU)Microcontroller Unit has a short history, but it has evolved quickly. Its generation and development are roughly synchronized with that of microprocessors  (CPUs). Since Intel Corporation of the United States first introduced 4-bit microprocessors  in 1971, its evolution can be roughly divided into five stages. The following is an overview of the development of Intel's MCU.1971-1976  The initial stage of MCU developmentIn November 1971, Intel introduced the Intel 4004, a 4-bit microprocessor with an integration level of 2000 transistors/chips and equipped with RAM, ROM, and shift registers, which served as the first MCS-4 microprocessor. The Intel 8008 8-bit microprocessor was introduced, followed by other 8-bit microprocessors  from various companies.1976-1980  Low-performance MCU stageThe MCS-48 series, introduced by Intel Corporation in 1976, has a monolithic structure that integrates an 8-bit CPU.  an 8-bit parallel I/O interface, an 8-bit timer/counter, RAM, and ROM on a semiconductor chip. Its addressing range is limited (no more than 4 KB), there is no serial I/O, the RAM and ROM capacity is limited, and the interrupt system is simple, but its functions can meet the needs of general industrial control and intelligent instruments and meters.1980~1983  High-performance MCU stageHigh-performance 8-bit microcontrollers introduced at this stage typically include serial ports, multi-level interrupt processing systems, and multiple 16-bit timers/counters. The capacity of the on-chip RAM and ROM  is increased, and the addressing range can reach 64 KB. A/D conversion interfaces are also available on individual chips. 1983~late 1980s  16-bit microcontroller stage.In 1983, Intel introduced a high-performance 16-bit microcontroller MCS-96  series. The chip integration level was as high as 120,000 transistors/chips due to the use of the most recent manufacturing process.1990sCPUs are developing to a higher level in all directions, such as integration, function, speed, reliability, and application fields. Ⅲ The Classification and Application of MCUMCUs are classified into two types based on their memory type: those with no on-chip ROM  and those with on-chip ROM,  The chip without on-chip ROM  must be used externally with EPROM (typically 8031); the chip with on-chip ROM  is classified as on-chip EPROM (typically 87C51), MASK on-chip mask ROM  (typically 8051), on-chip Flash (typically 89C51), and other types.MCUs are classified into two types based on their intended use: general-purpose and special-purpose. It is classified into4, 8, 16, and 32-bit MCUs based on the width of the data bus and the number of data bytes that can be processed at the same time.Figure 2 MCU product category At present, the most widely used MCU market in China is in the consumer electronics  field, followed by the industrial field and the automotive electronics  market. Consumer electronics  include home appliances, televisions, game consoles, and audio and video systems. Industrial fields include smart homes, automation, medical applications, and new energy generation and distribution. The automotive field includes automotive powertrains and safety control systems. Industrial MCU Industrial MCU products  are primarily used for motor control operation, data acquisition control, and other functions in motor control, instrumentation, low-voltage power distribution, power tools, industrial robots, and other application scenarios.Figure 3 Electric-Vehicle-ChargerThe number of MCU devices is increasing as the complexity of industrial equipment increases. Consider industrial robots: at least ten MCU products  are used in a single industrial robot.Home Appliance MCU MCU is widely used in household appliances, mainly used to realize system control, motor control, panel display control, and other functions.The home appliance market is mainly divided into small household appliances and everyone electricity, small household appliances including kitchen appliances (microwave oven, induction cooker, soybean milk machine, etc.), household appliances (vacuum cleaner, electric fan, electric heater, etc.), personal life small household appliances (electric toothbrush, hairdryer, etc.), everyone electricity mainly for air conditioning, refrigerator, washing machine, and other white appliances.Figure 4 Induction-heating-cooker-app-block-diagramAt the moment, 32-bit MCUs have become the market's mainstream due to their higher specifications and performance, as well as their constantly decreasing cost, and are widely used in automotive electronics.  industrial control/medical, and other fields; however, there are still a large number of application scenarios requiring simple control, and low-value MCUs have cost advantages, so they continue to occupy a large market.BitApplication4Calculator, auto instrument, auto anti-theft device, pager, wireless phone, CD player, LCD dynamic controller, children's toys, scales, chargers, Tire gauge, thermometer, remote control, etc8Electrical appliances, ammeter, motor controller, electric toy machine, pager, fax machine, telephonograph, keyboard and USB, etc16Mobile phones, digital cameras and video recorders, etc32Smart home, IoT, motor and frequency conversion control, security monitoring, fingerprint identification, touch keys, Modem, GPS, STB, Workstation, ISDN telephone, laser printer and color fax machine, etc64Advanced workstation, multimedia interactive system, advanced TV game instrument, advanced terminal, etc.According to IC Insights, the global MCU market is about 16.4 billion dollars in 2019 and could reach about 20 billion dollars by 2023.The scale of China's MCU market was about 25.6 billion yuan in 2019, accounting for about 26% of the global market, with a compound growth rate of 9% from 2015 to 2019.In terms of the global market, the auto circuit accounts for 33% of the global MCU market. According to IC Insights data, the automotive MCU market space will reach $8.1 billion in 2023, the overall growth rate is considerable; At the moment, 32-bit MCUs have become the market's mainstream due to their higher specifications and performance, as well as their constantly decreasing cost, and are widely used in automotive electronics.  industrial control/medical, and other fields; however, there are still a large number of application scenarios requiring simple control, and low-value MCUs have cost advantages, so they continue to occupy a large market.Figure 5  MCU Market StructureFrom the perspective of pattern, the top five global automotive MCU market shares in 2020 were Renesas, NXP, Infineon, Texas Instruments and Microchip, accounting for 87% in total.Ⅳ China MCU Technology and Well-known ManufacturersMCU market is still dominated by overseas leaders, and Chinese high-quality manufacturers are gradually making breakthroughs in the segmented fields, and their share is expected to increase rapidly under the background of accelerated localization in China.The global MCU market is expected to grow further, with the global MCU market size reaching $16.4 billion in 2019 and $20 billion in 2023.On the demand side, improvements in automotive electrification, accelerated IoT  penetration, increased demand for intelligent frequency conversion in home appliances, rapid iteration of wearable devices, and steady growth in industrial control continue to drive the rapid growth of the MCU industry. (Using MCU as an example, the global market compound growth rate from 2020 to 2023 is 7.7 percent, and the market space is expected to be 8.1 billion dollars by 2023)On the supply side, the MCU industry is experiencing a continuous shortage due to the epidemic in 2020. Infineon, NXP.  and ST  , as well as other overseas MCU large factories, have appeared several times to dozens of times the price, with delivery times of more than 50 weeks; persistent shortages are expected to last at least through the end of 2021 and the first quarter of 2022.In terms of circuit barriers, the requirements of automobile circuits in the MCU downstream field are the highest, followed by industrial and home appliance circuits, and the relative requirements of consumer electronics  are slightly lower, according to MCU product environmental temperature, yield, and service life, and other parameters.According to the industry competition pattern, Chinese MCU manufacturers have a low market share, benefit from accelerated replacement due to stock shortages in the short term, and have ample room for improvement in the long term:The global MCU market is more concentrated, with a microchip, ST  MICROELECTRONICS, Renesas, TI, NXP  , Infineon, and other manufacturers occupying more than 80% of the market share; China's MCU market is approximately 25 billion yuan, and the total market share of domestic MCU manufacturers is less than 12%, primarily concentrated in the consumer market, which has ample room for expansion.The shortage of goods leads to the acceleration of the pace of China's MCU manufacturers, in the automotive, industrial, and consumer circuit, the pace of China's MCU certification continues to accelerate. Renesas Electronics - the world's first automotive MCU manufacturer Renesas was founded in 2003 by the merger of Hitachi Semiconductor division and Mitsubishi Electric Semiconductor division. Its main business covers automotive, industrial, communications, and other fields. Renesas is the world's first automotive MCU manufacturer, accounting for 30% of the automotive MCU market in 2020.Renesas MCU has a complete product line covering EV/HEV, powertrain, electric vehicle, vehicle dashboard, vehicle network, chassis control, ADAS, and other application fields.Microchip technology -8 bit MCU main features, acquisition of Atmel to supplement the strength of 32 bit MCUMicrochip Technology Corporation (Microchip) was founded in 1989, Microchip technology is the world's leading supplier of single-chip and analog semiconductors. The company's main business is the microcontroller, memory products, analog interface, and mixed information products, technology licensing, and so on.The products are mainly used in embedded control systems and IoT-related industries, including data processing, Medical Internet + (IoT), smart city, Industry 4.0, intelligent healthcare, etc. Major customers include Intel, Dell, Lockheed Martin, HP, Boeing, etc. STST -ARM architecture MCU king ST was founded in 1987, its products are mainly used in automotive products, computer peripherals, communication systems, consumer products, industrial automation control systems, and other aspects. Its major customers include Apple, blackberry, Bosch, Cisco, Conti, HP, Nokia, Obata, Samsung, and Western Digital.MCU vehicle grade products accounted for 32.13% of the company's revenue. St holds 8.5% of the current MCU market and is the leader in the segmented 32bitMCU  market.ST has been deeply engaged in the automotive semiconductor field for many years, and the company has a complete industrial chain, its products have a very high-cost performance ratio, and occupy a dominant position in the MCU of vehicle regulation level. Its customers include Nissan, Audi, SAIC, Tesla, and many other companies. NXP - the world's leading automotive MCU manufacturer NXP Semiconductor was founded in 2006. It was formerly the semiconductor division of Philips. NXP's main business is MCU, MPU, and other products, which can be widely used in automotive electronics  , industrial control, smart city, smart home, and wearable products. Its MCU/MPU based on the S32 automotive platform has obvious advantages in safety and efficiency and has been adopted by mainstream OEMs around the world.The industry's first crossover MCU was independently developed by NXP: I. MX RT series. Such products have been recognized by many Internet platforms (such as Amazon) for their high integration, cost performance, and security.NXP's acquisition of Freescale (founded by MOTOROLA) in 2015 gives it a deeper presence in the automotive industry. In 2020, 47% of its revenue came from vehicle MCU. At present, the company accounts for 27.8% of the global automotive MCU industry, ranking second in the world. NXP  provides complete semiconductor solutions for intelligent vehicles including automotive entertainment systems, Advanced Driver Assistance Systems (ADAS). Sino Wealth Electronics - China's largest home appliance MCU manufacturer Sino Wealth Electronic Ltd. is an MCU integrated circuit design company, the main products include 8-bit Flash MCU, 8-bit OTP/Mask MCU, 16-bit  DSP , 4-bit OTP/Mask MCU, widely used in household appliances, automotive, industrial control, security, and other fields;In the field of small household appliances, the company's competitors are mainly ABOV from Korea and Holtek from Taiwan. In the field of white household appliances, the company's competitors are mainly from Europe and America, including Renesas, NEC, TI, STM, and so on. Ⅴ The Basic Functions of MCUInternal-function diagramFor most MCUs, the following functions are the most common and basic. The description methods for different MCUs may differ, but the essence is essentially the same.1. Timer: Although there are many different types of Timers, they can be divided into two categories. The first is a Timer with a fixed time interval, which means that its timing is set by the system and cannot be controlled by the user program. The system only provides a few different types of Timers. The user program is given a fixed time interval, such as 32Hz, 16Hz, 8Hz, and so on. Because Timers of this type are relatively common in 4-bit MCUs,they can be used to implement clock, timing, and other related functions.The other type is Programmable Timer. The timing of this type of Timer can be controlled by the user's program. The control methods include the selection of the clock source, the selection of the prescale number, and the setting of the preset number, etc. There are Most MCUs have all three at the same time, and some may have one or both of them. This kind of Timer application is very flexible, and the actual use is also ever-changing. One of the most common applications is to use it to achieve PWM  output.Since the clock source can be freely selected, such Timers are generally combined with the Event Counter.2. IO port: Any MCU has a certain number of IO ports. Without IO ports, the MCU will lose the channel of communication with the outside world. According to the configurable situation of the IO port, it can be divided into the following types:Pure input or pure output : This type of IO port is determined by the MCU hardware design, and can only be input or output, and cannot be set in real-time by software.3. Directly read and write IO port: For example, the IO port of MCS-51 belongs to this type of IO port. When the read IO port command is executed, it is an input port; when the write IO port command is executed, it is automatically an output port.Program programming to set the direction of input and output: the input or output of this type of IO port is set by the program according to the actual needs, the application is more flexible, and can realize some bus-level applications, such as12C bus, various LCD, LED Driver control bus, etc.When using the IO port, this point must be kept in mind: for the input port, there must be a clear level signal to ensure that it cannot be floated (this can be achieved by adding a pull-up or pull-down resistor); and for the output port, the output state level must be Considering its external connection, it should be ensured that there is no source current or sink current in Standby or static state.External interrupts: External interrupts are a basic function of most MCUs. They are commonly used for real-time signal generation, data sampling, and state detection. Rising edge, falling edge, and level triggering are all interrupting methods. In most cases, the external interrupt is handled via the input port. If it is an IO port, the interrupt function will only be enabled when it is set as an input port; if it is set as an output port, the external interrupt function will be automatically closed (with some exceptions in ATMEL's ATiny series, where the output port can also trigger the interrupt function). The application of external interrupt is as follows:Detection of external trigger signals: One is based on real-time requirements, such as thyristor control, detection of sudden signals, and so on, while the other is based on power savings.Measurement of signal frequency:: To ensure that the signal is not missed, an external interrupt is the best option.Decoding data: To reduce design costs in the field of remote control applications, it is frequently necessary to use software to decode various encoded data, such as Manchester and PWM encoding.Button detection and system wake-up: In order for the MCU to enter the Sleep state, it must be woken up via an external interrupt. The most basic form is a button, and the level change is caused by the button's action.4. Communication interface: The communication interface provided by MCU generally includes SPI interface, UART. I2C interface, etc., which are described as follows:SPI interface: This type of interface is the most basic communication method provided by most MCUs. Its data transmission is controlled by a synchronous clock. The signals include SDI (serial data input), SDO (serial data output), SCLK (serial clock), and Ready signal; in some cases, there may be no Ready signal; this type of interface can work in Master mode or Slave mode, the popular saying is to see who provides the clock signal, the party providing the clock is the Master, and the opposite party It is Slaver.UART(Universal Asynchronous Receive Transmit):It belongs to the most basic asynchronous transmission interface. Its signal lines only have two Rx and Tx lines. The basic data format is: Start Bit + Data Bit(7-bits/8-bits) + Parity Bit(Even, Odd or None) + Stop Bit(1~2Bit). The time occupied by one bit of data is called Baud Rate .For most MCUs, the length of data bits, data check mode (odd check, even check or no check), Stop Bit length and Baud Rate can be flexibly set through program programming. Certainly. The most common way of this type of interface is to communicate with the serial port of the PC.I2C interface: I2C  is a data transmission protocol developed by Philips. It also uses two signals to implement: SDAT (serial data input and output) and SCLK (serial clock). The biggest advantage is that multiple devices can be attached to this bus, and they can be identified and accessed through addresses; one of the biggest advantages of the I2C  bus is that it is very convenient to use software to implement through the IO port, and the data rate of its transmission is completely controlled by SCLK. To control, it can be fast or slow, unlike the UART  interface, which has strict rate requirements.5. Watchdog: Watchdoga basic configuration of most MCUs, can only allow the program to reset it but not close it (some are set when the program is burned in, such as Microchip PIC  series MCUs), while some MCUs are It is determined by a specific method whether it is turned on or not. For example, in Samsung's KS57 series, as long as the program accesses the Watchdog  register, it is automatically turned on and cannot be turned off again. Generally speaking, the reset time of the watchdog can be set by the program. The most basic application of Watchdog  is to provide a self-recovery ability for the MCU to crash due to unexpected failure.Ⅵ Learning Methods - Using MCUThe basic principles and functions of any MCU are similar. The only difference is the configuration and quantity of its peripheral function modules and the instruction system.For the instruction system, although it seems to be different in form, it is only a difference in symbols, and the meanings it represents, the functions to be completed, and the addressing modes are similar.To learn about an MCU, the first thing you need to know is its ROM space, RAM space, number of IO ports, number of timers and timing methods, peripheral function modules (Peripheral Circuit) provided, interrupt sources, operating voltage, and power consumption, etc.After understanding these MCU Features, the next step is to compare the functions of the selected MCU with the required functions of the actual project development and clarify which resources are currently required and which are not used in this project.For the functions that need to be used in the project but are not provided by the selected MCU, it is necessary to carefully understand the relevant information of the MCU, to use an indirect method to achieve it. For example, the developed project needs to communicate with the COM port of the PC, and If the selected MCU does not provide a UART  port, it can be implemented through external interrupts.For the resources needed for project development, you need to carefully understand and read the Manua*, while for the unneeded function modules, you can ignore or browse. For MCU learning, the application is the key and the main purpose.For beginners or designers who use this MCU for the first time, they may encounter a lot of ambiguous descriptions of the functions of the MCU. For this kind of problem, there are two ways to solve it, one is to write a special verification program to understand the functions described in the data; the other can be ignored for the time being. Leave it to modify and improve when debugging. The former method is suitable for projects with loose time and beginners, while the latter method is suitable for those who have some experience in single-chip development or when the project schedule is more urgent.Don't take the time to learn the command system in particular. The instruction system is simply a logical description symbol. During programming, you can only check the relevant instructions in accordance with the logic requirements of the program. As your programming skills improve, you will become more proficient in the instruction system.Ⅶ Six Main Dimensions of MCU Products for Future ImprovementStronger computing performance: MCU towards 500Mhz main frequency, MPU increase more processor cores;Additional wireless connection functions: More RF modules have been integrated.Low power consumption, high energy efficiency ratio: integrated analog chip, and low power analog peripheralsContinued support for hardware accelerators: high integration of algorithms and toolsSafety: improve anti-interference ability and safetyCost-effective: reduce costⅧ Programming of MCUThe programming of MCUs and PCs differ significantly. Although C-based MCU development tools are becoming more popular, assembly language remains the most concise and efficient programming language for designers who are efficient program code and like to use assembly.Circuit diagram to build your own microcontroller programmerThe basic framework for MCU programming is roughly the same, divided into the initialization part (the biggest difference between MCU programming and PC programming), the main program loop body, and the interrupt handler. as shown below:1.Initialization: The most basic and important step in the design of all MCU programs is an initialization, which generally includes the following:Mask all interrupts and set the stack pointer to In general, the initialization section does not want any interruptions to occur.Clearing the system's RAM and displaying the Memory: Although it is not always necessary, it is recommended to develop good programming habits for the sake of reliability and consistency, particularly to avoid accidental errors.IO port initialization: Set the input and output modes of the relevant IO port based on the project's application requirements. Set the pull-up or pull-down resistance for the input port, and the initial resistance for the output port.Interrupt setup: Enable and set interrupt trigger conditions for all interrupt sources required by the project, and close unnecessary interrupts that are not used.Initialization of other functional modules: For all peripheral functional modules of MCU that need to be used, corresponding Settings must be carried out according to the application requirements of the project. For example, Baud Rate, data length, verification mode and Stop Bit length should be set for communication of UART  , and clock source should be set for Programmer Timer. Frequency and Reload Data, etc.Initialization of parameters: after completing the initialization of MCU hardware and resources, the following is the initialization of some variables and data used in the program. This part of initialization needs to be designed according to the specific project and the overall arrangement of the program. For some applications that use EEPROM to store the number of prefab items, it is recommended to copy the relevant data to THE RAM of MCU during initialization to improve the speed of data access and reduce the power consumption of the system (in principle, access to the external EEPROM will increase the power consumption of the power supply).2.Main program loop body: Most MCUs run continuously for a long time, so their main program bodies are basically designed in a looping manner. For applications with multiple working modes, there may be many Each loop body is converted between each other through state flags. For the main program body, the following modules are generally arranged:Calculation procedures: Calculation procedures are generally time-consuming, so it is strongly opposed to processing in any interrupt, especially multiplication and division operations.Processing programs with low or no real-time requirements;Display transfer program: mainly for applications with external LED and LCD Driver.3. Interrupt handler: The interrupt program is mainly used to handle tasks and events with high real-time requirements, such as detection of external sudden signals, detection, and processing of buttons, timing counting, LED display scanning, etc.Under normal circumstances, the interrupt program should keep the code as concise as possible. For functions that do not need to be processed in real-time, the trigger flag can be set in the interrupt, and then the main program executes the specific transaction - this is very important, especially for low-power, low-speed MCUs, is necessary to ensure timely responses to all interrupts.4. There are various MCU processing methods for various task bodies.For example, for low-speed, low-power MCU (Fosc=32768Hz) applications, considering that such projects are handheld devices and use ordinary LCD, the response to buttons and display response requires high real-time performance, so generally Timed interrupts are used to process button actions and data display; for high-speed MCUs, such as Fosc>1MHz applications, since the MCU has enough time to execute the main program loop body at this time, it can only be interrupted at the corresponding Various trigger flags are set in the program, and all tasks are executed in the main program body.5. In MCU programming, special attention should be paid to:Avoid situations where the same variable or data is accessed or set in both the interrupt and the main body. The effective prevention method is to arrange the processing of such data in a module, and decide whether to execute the relevant operation of the data by judging the trigger flag; In other bodies (mainly interrupts), only the trigger flag is set where the processing of the data is required. This ensures that data execution is predictable and unique.Ⅸ Summary of the MCU Programming EngineerTo develop a good habit of summarizing, summarizing is not only a summary of their learning, but also a review and deepening of the learning process, but also to avoid the second error.Before writing the program, we should have a solid understanding of the project so that we can start with a solid idea and a general framework. It is critical to consider the layout and what makes the most sense. To determine which module should be completed first, specific steps for the module, how to name each function, and the relationship with other modules. Take a piece of paper and scribble down significant progress.For C language modular programming, we should first divide each module, a module programming, determine a sequence, and then write the next module based on the success of the previous one. When it comes to header files, write the module's header file after you've finished writing the module.Do not ignore the fact that the program must be unreasonable to comprehend its origins and find a solution. When looking for a source, it should be pertinent; you can search for relevant data on the Internet or consult with others. For example, the primary function of another project was incorporated into this project. Some functions are named multiple times. Step by step analysis of the cause, also according to the experimental phenomenon. When defining the port, the incorrect interface was selected. When you can't solve a problem, it's sometimes good to take a break. Things can go wrong no matter how simple they seemThe problems of code utilization efficiency, anti-interference, and MCU reliability continue to plague MCU application development. Ⅹ How to Develop MCU 1How to reduce program bugsThe following are the over-arching management parameters that should be considered during system operation in order to reduce program bugs.Physical parameters: These are primarily system input parameters that include excitation parameters, acquisition and processing operating parameters, and result parameters at the end of processing.Resource parameters: These are primarily the resources of the system's circuits, devices, and functional units, such as memory capacity, storage unit length, and stacking depth.These application parameters are frequently expressed as the application conditions of some single-chip microcomputers and functional units. The term "process parameter" refers to a parameter that changes in an orderly manner during the system's operation.2How to improve the efficiency of C language programming codeIt is an inevitable trend of the development and application of MCU to use C language to design MCU. If you are programming in C, it is best to be familiar with the C compiler you are using to achieve maximum efficiency. First test the number of statement lines in the assembly language corresponding to each C language compilation, so that you can clearly know the efficiency. When programming in the future, use the statement with the highest compilation efficiency. Each C compiler will have certain differences, so the compilation efficiency will also be different. The code length and execution time of an excellent embedded system C compiler is only 5-20% longer than the same functional degree written in assembly language.C language can be used for complex and time-critical projects, but the premise is that you are very familiar with the C language and C compiler of the MCU system and that you pay special attention to the data types and algorithms that the C compiler system can support. Although C is the most commonly used high-level language, the C language compilation system varies due to MCU manufacturer differences, particularly in the operation of some special function modules. As a result, if you don't understand these features, you'll have a lot of trouble debugging, which will result in lower execution efficiency than assembly language.3 How to Solve the MCU Anti-Interference ProblemThe most effective way to prevent interference is to remove interference sources and cut off interference paths, but this is often difficult to do, so we can only conclude that MCU's anti-interference ability is insufficient. While improving the anti-interference capability of hardware systems, software anti-interference has received increasing attention due to its flexible design, ability to save hardware resources, and high reliability.As for the program run fly, in fact, can also use software trap and watchdog to pull the program back to reset state, so the MCU software anti-interference is the most important to deal with the reset state.In most cases, MCU will have some sign registers that can be used to determine the reason for the reset; alternatively, you can bury some tokens in RAM yourself. Different reset causes can be determined in each program reset by judging these signs. You can also use different flags to jump directly to the corresponding program. In this manner, the program will run indefinitely, and the user will be unaware that it has been reset.4How to test the reliability of the MCU systemWhen a MCU system design is completed, there will be different test items and methods for different MCU system products, but some must be tested:lTest the completeness of the software functions of the MCUlPower-on and power-off testlAging testlTests such as ESD and EFT Sometimes, we can also simulate the damage that may occur in human use. For example, the contact port of the MCU system is intentionally rubbed with the human body or clothing fabric, thereby testing the antistatic ability. Use a high-power electric drill to work close to the MCU system to test the anti-electromagnetic interference ability.To sum up, the MCU has become an important aspect of the development and application of the computer.Most of the functions that must be realized by analog circuits or digital circuits in the past can now be realized by software methods using a single-chip microcomputer. This control technology in which software replaces hardware is also called micro-control technology, which is a revolution of traditional control technology.In addition, in the process of development and application, we must master the skills and improve the efficiency, so as to facilitate its wider use.Ⅺ 5 Tips to Solve the Questions About the MCU CrystalCrystal oscillator for MCUCommon causes of the crystal can not vibratePCB wiring error;Microcontroller quality issues;Crystal vibration quality issues;The load capacitance or matching capacitance does not match the crystal oscillator or the capacitor quality is incorrect;PCB board damp, resulting in impedance mismatch and inability to vibrate;The crystal oscillator circuit is too long;There is a line between the feet of crystal;Influence of peripheral circuit.You are advised to rectify faults one by one as follows: 1Remove the possibility of circuit error so that you can compare the recommended circuit of the corresponding type of microcontroller.2 Rule out the possibility of poor peripheral components; because peripheral components are nothing more than resistance and capacitance.3Rule out the possibility of using a crystal oscillator as a stop oscillator because you will not be experimenting with just one or two crystal oscillators.4Try changing the capacitor at both ends of the crystal; perhaps the crystal oscillator will begin to vibrate; please refer to the crystal oscillator capacitor size instructions.5In PC  B wiring, crystal oscillator circuit wiring should be as short as possible and as close to IC as possible, not between crystal oscillator feet. Ⅻ Summary of Chip OperationThe operation of the chip is mainly the operation of the registers in the chip. The registers in the chip have their unique address mapped on the memory, which is the operation of the corresponding address. To learn the chip, first look at the sequence diagram, then understand the corresponding registers, understand how to operate, define the required port (the program can recognize), write and read the operation program.Cross-sectional-views-of-chip-operationHow data is written to the chip, how it is read out, and through which port it is input or read.When connecting a chip through a bus, the first step is to understand the protocol of the bus. The chip connected to the I2c bus is controlled by the bus.1One 74HC595 lattice is used for column selection, and the other two are used for color selection. The lattice is equivalent to a set of diodes.The diode lights up only when one end is switched to a high level and the other to a low level. Just one end of the selection of different, bright different colors.Timer working mode selection: Set timer T1 in the high four digits and timer T0 in the low four digits. Then the last two characters of each mode set the working mode. When using interrupts, note that after entering the interrupt, the reset should be reset.2Serial port transceiver: Baud rate is generally set in mode 2 (automatic reloading initial value) because different devices have different data processing capabilities, the baud rate is set mainly to take care of low-speed devices and for communication between each other. The interrupt flag bit should be cleared by the software. When setting the serial port interrupt, either sending or receiving can enter the interrupt function, so pay attention to setting the interrupt function. (Self-sense generally sets a function, as the upper machine or lower machine).If you send interrupts, you have to figure out how to enter interrupts the first time, so you send them once and then you can enter interrupts. Only one byte can be sent at a time, and only after TI is set to one can the next byte be sent.3Pcf8591ad conversion, there are four channels of input, read PC  F8591, which channel, read is that channel input voltage, after the conversion of data stored in the chip, then read. Read to write the address of the chip, the son writes device address (0 x40 | channel number) and then reads the data.4Da conversion is to write the device address into the chip first, then write the sub-address (0x40) and then write the digital quantity to be converted. Device address chip information is introduced.5For the liquid crystal display, write data display, he will always display, do not continue to refresh, to change, only re-input.6For THE DS1302 clock chip, reading data is read out of the first data at the falling edge of the eighth clock when writing data, and then prepare for the next output. Pay attention to the writing of the program, but also pay attention to the position of the return value.7In Ds1302, the register is specified first, and then data is written to it. The registers on the chip data indicate the address. 8Initialization is best to write, in case you forget later. When reading or writing, the first operation is the lowest or highest bid, which can be judged according to the sequence diagram.9For the infrared transceiver, receiving, he is according to the length of time between the two falling edges to determine the high level or low level, write a program, first with the timer to determine the length of time, save, and then into binary (the program written to see more, very good).10Stepper motor: mainly used as switches, stepper motor torque decreases with the increase of speed. It is mainly used for automatic feeding of parts processing on machine tools. It can also be used in high-precision control places.Stepper motor is an open-loop control element stepper motor that converts electric pulse signal into angular displacement or linear displacement. In the case of the overload, motor speed, stop position depends only on the pulse signal frequency and pulse number, and are not affected by load change, when the stepper driver receives a pulse signal, it is driving a stepper motor according to set the direction of a fixed Angle, known as the "step Angle", its rotation is based on the Angle of the fixed step by step. The angular displacement can be controlled by controlling the number of pulses to achieve accurate positioning. At the same time, the speed and acceleration of the motor can be controlled by controlling the pulse frequency, achieving the purpose of speed regulation.11Servo motor : Servo motor refers to the engine that controls the operation of mechanical components in a servo system. It is an indirect transmission device for auxiliary motors. Servo motors can control speed, position accuracy is very accurate, voltage signal can be converted into torque and speed to drive the control object. Servo motor rotor speed is controlled by the input signal, and can respond quickly, in the automatic control system, used as an executive element, and has the characteristics of mechanical and electrical time constant is small, high linearity, starting voltage, etc., can receive the electrical signal into the motor shaft angular displacement or angular velocity output. It is divided into DC and AC servo motors. Its main characteristic is that when the signal voltage is zero, there is no rotation phenomenon, and the speed decreases uniformly with the increase of torque.12Chinese Characters overview: To output Chinese characters on display or printer, Chinese characters are designed into a dot matrix graph according to graphic symbols, and corresponding dot matrix codes (glyphs) are obtained.The unified encoding for the representation of Chinese characters in the computer is called the internal code (such as national code), and the internal code is unique (equivalent to the id number of the character). The encoding of Chinese characters formed to facilitate the input of Chinese characters is the input code, which belongs to the external code of Chinese characters. The input code varies with the encoding mode and is diverse. The Chinese character code formed for displaying and printing Chinese characters is the character code, and the computer finds the character code in the character library through the character code and realizes its conversion.Machine code: According to the GB code, each Chinese character has a certain binary code, but this code will conflict with THE ASCII code when handled internally by the computer. To solve this problem, the first byte of each GB code is incremented by 1. Because ASCII code only uses 7 bits, the "1" on the first digit can be used as a symbol to identify Chinese character codes. When the computer processes the code with the first digit of "1", it will be interpreted as the information of Chinese characters, and when it processes the code with the first digit of "0", it will be interpreted as the ASCII code. After such processing, the national code (internal code) is the machine's internal code.If put this "mouth" word graphic "." With "0" instead, you can very vividly get the "mouth" glyphs :0000H 0004H 3FFAH 2004H2004H 2004H2004H 2004H2004H 2004H2004H 2004H 3FFAH 2004H 0000H 0000H. Computer to output "mouth", find shows that character first address, according to the "mouth" machine code after calculation, to find a "mouth" glyph code, and then according to the glyph code (to) in binary character generator, in turn, scan control on the screen, which is where the "0" of the binary empty, is a place where "1" swept out of the window, Then you get the character graph of the mouth.Chinese characters are arranged according to the order of national standard codes and stored in the memory in the form of binary files, which constitute the Chinese character font library, also known as the Chinese character font library, called the Chinese character library1312864 liquid crystal: Each display point corresponds to a binary number, with 1 indicating on and 0 indicating off. The RAM that stores this lattice information is called the display data memory. To display a graph or Chinese character is to write the corresponding lattice information into the corresponding storage unit.When the horizontal address = 0FH, it will be reset to 00H, but it will not automatically add one to the vertical address. Therefore, when writing multiple data in a row, the program needs to determine whether the vertical address needs to be reset14GDRAM: Drawing display RAM provides 128×8 bytes of memory space. When changing the drawing RAM, the horizontal and vertical coordinate values are successively written, and then two bytes of data are written to the drawing RAM. The address counter (AC) will automatically increment the horizontal address (X address) and reset to 00H when the horizontal address is 0XFH. Vertical addresses will not be carried automatically plus 1. The drawing display must be turned off during writing to the drawing RAM,For C, a defined variable is automatically allocated space and its address is the name of the variable. Through this name, the data can be recruited in memory, and the new data can be obtained through an operation. In assembly, the programmer needs to define the storage space and send the data to the accumulator for operation, and the programmer needs to operate every step. In C, this is done by the compiler.FAQ1. What is the main function of microcontroller?Microcontroller is a compressed micro computer manufactured to control the functions of embedded systems in office machines, robots, home appliances, motor vehicles, and a number of other gadgets. A microcontroller is comprises components like - memory, peripherals and most importantly a processor.2. What is an example of a microcontroller?The examples of 8-bit microcontrollers are Intel 8031/8051, PIC1x, and Motorola MC68HC11 families. The 16-bit microcontroller performs greater precision and performance as compared to the 8-bit.3. What are the elements of a microcontroller?Therefore, the microcontroller must also satisfy the five basic elements of input, calculation, storage, output, and control. These are called five elements of microcontrollers.4. Which is best microprocessor or microcontroller?If you need access to large amounts of really fast memory then a microprocessor is likely your best option. A microcontroller is already embedded with memory so the memory choices are fewer than with a microprocessor. The maximum amount of FLASH memory available with most microcontrollers is usually around 2MB.5. What is difference between BIOS and CMOS?The BIOS is the program that starts a computer up, and the CMOS is where the BIOS stores the date, time, and system configuration details it needs to start the computer. ... CMOS is a type of memory technology, but most people use the term to refer to the chip that stores variable data for startup.6. Is CMOS a RAM or ROM?RAM and ROM are the products, but Complimentary Metal Oxide Semiconductor (CMOS) is the process they are built in. CMOS uses two different types of transistors to achieve a lower overall power consumption.7. Whats an RTC battery?The Real Time Clock (RTC) battery provides power for the internal clock/calendar and for maintaining system configuration settings. This error can occur when a machine has been left turned-off for an extended period of time (approximately one to four months), and it is the result of a depleted RTC battery.            
kynix On 2022-01-12   1711
Motors, Solenoids, Driver Boards/Modules

Is Raspberry Pi a MCU? Uses Analysis

Introduction Do you use Raspberry Pi? or What are doing with it? Is it a microcontroller (MCU for microcontroller unit) or microcomputer? or SoC (system-on-chip)? As a beginner, is it better to buy a microcontroller or a Raspberry Pi? Look at the following content. Raspberry Pi Explained Catalog Introduction Ⅰ Basic Definition Ⅱ Raspberry Pi vs MCU Ⅲ What Can We Do with Raspberry Pi? Ⅳ Where do I start to Learn Raspberry Pi? Ⅴ FAQ Ⅰ Basic Definition Raspberry Pi is actually a tiny embedded computer. It uses ARM microcontroller chip, and linux operating system or windows. It can regard as a small desktop computer when connects with a monitor, keyboard, and network (network port or wifi). With the release of Windows 10 IoT, Raspberry Pi can also run Windows.The single-chip microcomputer refers to the central processing unit core with some peripheral interface circuits on it, which is also called the microcontroller unit (MCU), or SoC. 8051 chips, avr chips, arm chips, etc. are all called single-chip microcontrollers, while Intel’s 80x86 series are central processing unit (CPU) and cannot be called MCU.It uses very large-scale integrated circuit technology to integrate the central processing unit CPU with data processing capabilities, RAM, ROM, multiple I/O ports and interrupt systems, timers/counters and other functions (may also include display driving circuits, pulse width modulation circuits, analog multiplexers, A/D converters and other circuits) are integrated on a silicon chip to form a small and complete microcomputer system. It is widely used in the field of industrial control. Figure 1. Raspberry Pi Setting Ⅱ Raspberry Pi vs MCU Next, let's take a look at the difference between the Raspberry Pi and the MCU and introduce in detail what can we do with the Raspberry Pi?The single-chip microcomputer is an microcontroller, and the Raspberry Pi is a single-board computer with arm-architecture processor. Early MCUs were peripherals for ROM and IO with slow speed, and it could not run time-sharing operating systems such as Linux or Windows. But the Raspberry Pi can run an operating system like Linux, or deploy servers or cloud computing. That is, the Raspberry Pi can perform many operations that cannot be done by a single-chip microcomputer.The size of the single-chip microcomputer is relatively small, and the internal chip is used as a computer system. Its structure is simple, but the function is perfect, it is very convenient to use, and it can be modularized. The most important thing is that although the development cycle of the single-chip microcomputer is relatively short, it is basically based on a specific task and the code must be re-programmed every time, which is very troublesome.The Raspberry Pi is actually a computer motherboard. It can be programmed, compiled, and run directly locally. If you want to add or delete functions to the original program, or switch from the current task to a different new task, you do not need to burn programs like a single-chip microcomputer according to different tasks or updates. Use Raspberry Pi to control peripherals by operating GPIO basically through various libraries, and if you connect it to the Internet, you can operate it remotely. Figure 2. Raspberry Pi GPIO In general, each has its own advantages. The MCU is cheap and suitable for general consumer products. After all, the Raspberry Pi is a card-type computer with an embedded operating system running on it. That is, a low-power general-purpose computer. For electronic geeks, the back-end data processing and GUI for complex control systems are still very good for satisfying embedded learning. Ⅲ What Can We Do with Raspberry Pi? After reading the above, since Raspberry Pi has the features of a computer, this means you’re able to do most things a desktop computer can do such as document editing, playing HD video, playing games, coding and much more.Obviously it won’t have as much power as a desktop PC but since it is a lot cheaper they make for great little computers you can play around with.Here lists some items you can do:1) Wireless HotspotUsing the Internet cable and USB wireless network card, after configuration, it can be used as a wireless hotspot.2) Mechanical ProsthesesMIT Media Lab researchers use it as a controller for mechanical prostheses.3) Easy Homemade NotebookConnect the Raspberry Pi to the LCD panel, add the mouse, keyboard and power supply, and find a beautiful case and put it on, finally it becomes a simple homemade notebook.4) WiFi CarAn IBM engineer installed it on a model car, and then used WiFi signals to control the car’s actions.5) Send Dynamics RemotelyWeather enthusiasts tied it to a detection balloon and used it to send a tweet in the stratosphere.6) Control Door SwitchThere are also people who use the Raspberry Pi to control the garage door and combine it with Siri to remotely control the garage switch.7) Surveillance ShootingA camera is connected as a small shooting device, which is small in size and easy to hide.8) Back Up EmailsOne of the most important functions of my Raspberry Pi is to back up emails. Use a software called getmail to check every mail using POP or IMAP protocol, and check the mail of each account regularly. Then save the email to an mbox file, which can be copied to another computer at any time for long-term email archiving.9) Build a RSS ReaderMiniflux, a self-hosted web-based RSS client that can be installed on the Raspberry Pi. Like many people, when Google announced that it would close Google Reader on July 1st, I also started to migrate personal data. I used rss2email for a while and let it send every item of RSS to my mailbox. But in fact, I don't like this method very much, so I spent some time looking for alternatives to Google Reader and tried rss2email and found miniflux finally. Installing miniflux on the Raspberry Pi is very simple, you only need to install PHP and a web server software in advance, such as nginx or Apache.10) Build a WebsiteOne obvious use of Raspberry Pi is as a backend server for websites. Because it has enough capacity to handle static websites, some web frameworks are not a problem. I built a Flask framework on it, and I even heard that some people built a Wordpress directly on the Raspberry Pi.11) Home Network StorageOnly consumes very low power, Raspberry Pi can become a perfect NAS (Network Attached Storage). Before I connected a 500GB laptop hard drive to the Raspberry Pi and installed an operating system on it. I can store many files on it that need to be transferred between different computers. Then connect via SFTP, you can access it on any machine at home (even if you are not at home, it will not be a problem as long as the routing settings are correct). You can also install Samba on your Pi so that both Mac and PC can access it more easily.12) Site MonitoringUse Raspberry Pi is to detect websites that are important to me. I wrote a Python script and ran it regularly to make sure that these websites responded with a 200 status code (which means everything is normal). If the script determines that there is a problem with the website or cannot be accessed, it will email me the overall situation of the incident. The Python module I use is Requests, and the email module is smtplib.13) Event ReminderUse Raspberry Pi to email me important events that I need to remember. I used Google Calendar before, but I only use it for simple events. So I replaced it with a Raspberry Pi, and a Python script for timed tasks is enough. I set the date, time, and message to remember. These parameters will be passed to my Python script, and on that day it will send the message to my mailbox to remind me of the day’s events.14) Family AlbumMy Raspberry Pi also supports a private website that contains all my family photos. I set up verification information so only people I want them to see can enter the site. This is much more reliable than your Facebook photo album, because your account on Facebook may be deleted, and the photos will be seen by strangers by chance. Here is a method, just use PHP to get the photos in a folder on the Raspberry Pi.15) JukeboxI mentioned above that I use Pi as a network storage, so all my music is also on it. I connected a stereo speaker to my Pi and used mpg123 to play music on the command line of the Raspberry Pi. Although there are many other mp3 players and graphical interfaces, I still choose mpg123 because it is easy to install and use. Figure 3. Raspberry Pi Projects Ⅳ Where do I start to Learn Raspberry Pi? If you are really interested in it and want to get started. How, and what do you need? 1) A Raspberry Pi. So, obviously you’ll need he actual board. If you don’t have it, you cant really do what you want. So find a website or store and buy one. Depending on the type and model you get, they can range from as low as 10$ to 50$. Pretty affordable.2) A monitor. So, you don’t actually need a monitor. But it is going to be so much easier. You can actually buy displays the Pi company has made specifically made for the Pi. These however are a little more expensive.You could also use your TV as a monitor, providing both the TV and the Pi can be hooked up via HDMI. VGA to HDMI would work too. Many different solutions can be used when it comes to the cable you use for a monitor, or all around screen. Adapters come in all shapes, sizes and forms. 3) A power source. You’ll need to power the Pi to use it. Most of the time, you will get a little charger to use with the Pi. Using this specific charger will probably be the best, as it will always pull enough power from the wall into your Pi.4) A mouse, and keyboard. You will need a mouse and keyboard. This is pretty much mandatory. Well, only for the actual screen portion of the Pi. Models 3 B+ and up have built in Bluetooth, so you can have cordless mouse and keyboard if you would like. That’s pretty cool.5) Depending on the model, you will need an Ethernet cable to have internet. Models 3 B+ and up have a built in WiFi chip. So you can have a wireless internet connection if you so please.6) A microSD card with the image you want to use. When you buy the Pi, you will need to have an SD card. The newer models use microSD cards. Putting the SD card into the Pi without anything on it wont do anything though, you'll need an image. Images for the Pi can be found along the internet for downloads. The standard image used for the Pi right now is NOOBS Debian.7) Time, patience and dedication. These are very important when working with the Pi. Why? Because the Pi is powerful, yet it can be confusing at times, especially for a “noob”.   Ⅴ FAQ 1. What is Raspberry Pi mainly used for?The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. 2. What are some good Raspberry Pi projects?Best Raspberry Pi Projects for BeginnersMusic Streaming.Security System.Weather Station.Arcade Machine.NAS.Digital Photo Frame.Retro Handheld Console.Robot. 3. Can a Raspberry Pi run Windows?The Raspberry Pi 4 can handle Microsoft Edge, the calculator app, and more, all via the power of Windows 11. It can even run Minecraft, albeit in an undesirable state. 4. Can Raspberry Pi go on Internet?If you want to connect your Raspberry Pi to the internet, you can plug an Ethernet cable into it (if you have a Raspberry Pi Zero, you'll need a USB-to-Ethernet adapter as well). If your model is a Raspberry Pi 4, Raspberry Pi 3, or Raspberry Pi Zero W, you can also connect to a wireless network. 5. How do I setup a Raspberry Pi network?Configuring the Raspberry Pi Ethernet Port With a Static IP.Step 1: Review Current Network Settings.Step 2: Backup the Current Network Configuration.Step 3: Modify the Network Settings. To edit the network setting you must edit the dhcpcd.Step 4: Restart the Raspberry Pi.Step 5: Test the New Network Setup. 6. How is Raspberry Pi different from microcontroller?The main difference between them is: Arduino is microcontroller board, while Raspberry Pi is a microprocessor based mini computer (SBC). The Microcontroller on the Arduino board contains the CPU, RAM and ROM. 7. Is Raspberry Pi zero a microcontroller?A Raspberry Pi is not a microcontroller, it is a single board computer. Neither. The chip itself is an SOC or system on chip, so it has almost all the parts of a computer on a single die. 8. Is the Raspberry Pi a system on a chip?Raspberry Pi SBCs feature a Broadcom system on a chip (SoC) with an integrated ARM-compatible central processing unit (CPU) and on-chip graphics processing unit (GPU), while Raspberry Pi Pico has a RP2040 system on chip with an integrated ARM-compatible central processing unit (CPU). 9. Can you use a microcontroller with a Raspberry Pi?Meet the Raspberry Pi Pico, a tiny little microcontroller that lets you build hardware projects with some code running on the microcontroller. Unlike computers, microcontrollers don't run traditional operating systems. 10. Is Raspberry Pi 3b a microcontroller?The Raspberry Pi is a single board computer with Microprocessor whereas Arduino is considered as Microcontroller unit. The Raspberry Pi can run an OS (Linux Distribution) and also consumes more power. Since Arduino is microcontroller device it has no operating system and can only run a single program or sketch. 11. What is Raspberry Pi used for in IoT?How can IoT Applications use Raspberry Pi? With an in-built quadcore processor, Raspberry Pi can serve as the “Internet Gateway” for IoT devices. Powered by a cloud network, Pi acts as a web server for uploading and transiting sensor data on IoT platforms. 12. What is the difference between microprocessor and microcontroller?KEY DIFFERENCESMicroprocessor consists of only a Central Processing Unit, whereas Micro Controller contains a CPU, Memory, I/O all integrated into one chip. ... Microprocessor uses an external bus to interface to RAM, ROM, and other peripherals, on the other hand, Microcontroller uses an internal controlling bus. 13. What kind of computer is Raspberry Pi?The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. 14. Can I use a Raspberry Pi as my main computer?Aside from the hard drive crash, the Raspberry Pi was a perfectly serviceable desktop for web browsing, writing articles, and even some light image editing. ... 4 GB of ram is just enough for a desktop. My 13 Chromium tabs, including a Youtube video, are using just over half of the 4 GB of available memory. 15. Which OS is better for Raspberry Pi?Raspbian. Raspbian is a Debian-based engineered especially for the Raspberry Pi and it is the perfect general-purpose OS for Raspberry users.
kynix On 2021-12-30   1156

Kynix

Kynix was founded in 2008, specializing in the electronic components distribution business. We adhere to honesty and ethics as our business philosophy and have gradually established an excellent reputation and credibility in our international business. With the accurate quotation, excellent credit, reasonable price, reliable quality, fast delivery, and authentic service, we have won the praise of the majority of customers.

Follow us

Join our mailing list!

Be the first to know about new products, special offers, and more.

Kynix

  • How to purchase

  • Order
  • Search & Inquiry
  • Shipping & Tracking
  • Payment Methods
  • Contact Us

  • Tel: 00852-6915 1330
  • Email: info@kynix.com
  • Follow Us

authentication

Kynix

© 2008-2026 kynix.com all rights reserve.