Table of contents
1) Functional Overview
2) Pin connection
3) Framework Introduction
4) Module Description
5) Reuse rules
6) Engineering Links
1) Functional Overview
Name: Independent button control of DC motor speed regulation
Content: The corresponding motor interface needs to be connected to the uln2003 motor control terminal with a Dupont line;
5V-12V low-power motors can be accelerated and decelerated by 2 buttons respectively;
the last two digits of 8 8-segment digital tubes are used to display 0~10 levels of speed;
P3 is connected to the button; P0 is connected to 8x eight-segment digital tubes, P22 is connected to the segment code latch, and P23 is connected to the bit code latch; P1.1 is connected to an input of ULN2003; the DC motor end is connected to the corresponding output of ULN2003, and the other end is connected to VCC.
The main purpose of this article is not to introduce how to implement functions, but how to make a framework that is easy to reuse and understand. As shown in the figure below, the files in the USER file belong to the highest layer (closest to the user); the files in the FUNC folder belong to the function layer (the user layer files can call various functions implemented by the function layer, and there are also a small number of mutual calls within the function layer); the INTE folder is mainly the interrupt layer (I originally wanted to take the interrupt out separately, but the interrupt subroutine and the user layer overlap too much, so only the interrupt initialization function is implemented here, and the interrupt subroutine is still placed in the main.c file)
Note: Pay attention to the reference in main.c! (Because there is no direct correspondence between the folder in Keil and the external one, the external one was built manually by me)
--> 4.1 Delay Description: Provides two delay functions (used in I2C, key debounce, etc.)
1 #include2 3 void DelayUs2x(unsigned char t); //us level delay function declaration 4 void DelayMs(unsigned char t); //ms level delay
--> 4.2 key8 Description: Provides a key scanning function to the outside world. If a key is pressed, the corresponding key value is returned (this is 8 keys, not 4x4)
1 #include2 3 #define KeyPort P3 4 5 unsigned char KeyScan(void); //key scan function, returns the scan key value
Application example: The following KeyScan() is called to detect the key to implement the key control function~
--> 4.3 led8 Description: Provides 8x eight-segment digital tube display function (special processing is required here)
1 #include2 3 #define DataPort P0 //define the data port. When encountering DataPort in the program, replace it with P0. 4 sbit LATCH1=P2^2; //define latch enable port segment latch 5 sbit LATCH2=P2^3; // bit latch 6 7 void Display(unsigned char FirstBit,unsigned char Num);
Application example: The 2-digit integer PWN_ON to be displayed is displayed on the 8x 8-segment digital tube as follows. At the 1, the tens and ones of PWN_ON are taken respectively and then converted into the display value of the corresponding digital tube light through DuanMa; then the display function is called in the interrupt or function body with frequent periodic refresh to display (the first parameter of display is to select the number of the 8x 8-segment digital tube to start displaying, 0 means starting from the 1st position; the second parameter is to indicate how many positions to display)
Special note: display(6,2) here means to display a two-digit integer on the last two of the eight digital tubes, and the value assigned to TempData is not TempData[6] and TempData[7]!
In the future, the same method can be used to continuously expand the FUNC layer, and when encountering specific problems, adjustments can be made in main and interrupts.
https://github.com/beautifulzzzz/stc89c51-or-stc89c52
Previous article:Starting from 0, drive the 4-digit 8-segment common cathode digital tube 3461AS
Next article:Four-phase five-wire stepper motor drive design with a reduction ratio of 1/64
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Melexis uses coreless technology to reduce the size of current sensing devices
- PCB project precautions: keepout check can not be checked
- From GPS to RFID, the growing number of positioning technologies
- [Silicon Labs Development Kit Review] 2-Power on/Change LED Flashing Speed
- 24V VCC, why is the voltage only 12V after IRF3205 is turned on?
- Crystal oscillator interference with GPS signals and EMC issues
- Qorvo acquired NextInput. It seems that Qorvo has been acquiring companies all the time.
- You are invited to attend the 2018 TI Embedded Products Seminar!
- Design of the inverting input summing circuit
- [Raspberry Pi Pico Review] 1. Testing the Raspberry Pi Pico without soldering the pin headers and analyzing the Pico's power circuit
- Please advise how to avoid the microcontroller from being burned out