I still remember that after I finished learning STM32, I felt like I knew nothing, and basically relied on the knowledge of microcontrollers to get through the final test. Then, I actually always wanted to learn STM32 well, but I felt that learning too much was not a good thing. I always felt that it was not a bad thing to learn a lot, but I always felt that there should be one skill that you are very outstanding in among the skills you have learned.
//
//Design: DC motor speed regulation, change the duty cycle by pressing buttons to achieve the purpose of speed regulation, and display various parameters at the same time
//Author: Touch
//Time :2017.6.5
//
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h
" #include "lcd.h"
#include "key.h"
#include "pwm.h"
int main(void)
{
unsigned int duty_cycle=0;
unsigned int k=0;
u8 t=0;
u16 led0pwmval=0;
u8 dir=1;
delay_init(); //Delay function initializationuart_init
(9600); //Serial port initialized to 9600
LED_Init(); //Initialize the hardware interface connected to the LED
LCD_Init();
KEY_Init();
TIM1_PWM_Init(899,0); //No frequency division. PWM frequency = 72000 / (899 + 1) = 80Khz
POINT_COLOR = RED; // Set the font to red
// Fixed display area
LCD_ShowString (70, 20, 200, 16, 16,"DC_Motor Project");
LCD_ShowString (20, 50, 200, 16, 16,"Author: TH ZJW LZH");
LCD_ShowString (20, 70, 200, 16, 16,"Teacher: LD");
LCD_ShowString (20, 130, 200, 16, 16,"Menu:"); LCD_ShowString (20, 150, 200, 16, 16
,"Max_Vaule"); LCD_ShowString (
160, 150, 200, 16, 16,"900");
LCD_ShowString(20,170,200,16,16,"Down_Mode");
LCD_ShowString(20,190,200,16,16,"Up_Mode");
LCD_ShowString(20,210,200,16,16,"Stop_Mode"); //Resolution 320*240
LCD_ShowString(20,230,200 ,16,16,"Duty_cycle");
LCD_ShowString(180,230,200,16,16,"%");
LCD_ShowString(20,250,200,16,16,"Air_Grade");
LCD_ShowString(90,300,200,16,16,"2017/6/5");
while(1)
{
LCD_ShowxNum(150,210,led0pwmval,4,16,0); //计数值
duty_cycle=led0pwmval/9; //占空比定义
if(led0pwmval==50) duty_cycle=5;
if(led0pwmval==100) duty_cycle=9;
if(led0pwmval==900) duty_cycle=99;
LCD_ShowxNum(160,230,duty_cycle,2,16,0);
if(duty_cycle>=0 &&duty_cycle<33) k=1;
if(duty_cycle>=33&&duty_cycle<66) k=2;
if(duty_cycle>=66&&duty_cycle<99) k=3;
switch(k)
{
case 1:LCD_ShowString(160,250,200,16,16,"Little");break;
case 2:LCD_ShowString(160,250,200,16,16,"Middle");break;
case 3:LCD_ShowString(160,250,200,16,16,"Heavy");break;
default:LCD_ShowString(160,250,200,16,16,"Little");break;
}
t=KEY_Scan(0); //得到键值
switch(t)
{
case KEY0_PRES: //1
{
LED0=!LED0;
//PWM
led0pwmval=led0pwmval-50;
if(led0pwmval>5000)
{
led0pwmval=0;
}
TIM_SetCompare1(TIM1,led0pwmval);
delay_ms(60);
//显示
}
break;
case KEY1_PRES: //2
{
LED1=!LED1;
delay_ms(10);
led0pwmval=led0pwmval+50;
if(led0pwmval>850)
{
led0pwmval=899;
}
TIM_SetCompare1(TIM1,led0pwmval);
delay_ms(60);
}
break;
case WKUP_PRES: //3
{
LED0=!LED0;
LED1=!LED1;
//PWM
led0pwmval=0;
TIM_SetCompare1(TIM1,led0pwmval);
//显示
}
break;
default:
delay_ms(10);
break;
}
}
}
Previous article:STM32 common IO port simulates serial port
Next article:STM32 study notes: basic timing functions of general timers
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- An easy-to-understand tutorial on the msp430 microcontroller
- [TI recommended course] #PFC power supply design and inductor design calculation#
- [Distributed temperature and humidity acquisition system] + STM32H745I-LWIP program
- Summary: TI LAUNCHXL-CC2650 evaluation report
- [LAUNCHXL-CC2650] Run the SDK built-in routine
- [Liquid Level Sensor Evaluation] LED Liquid Level Indicator
- Power module source knowledge you will understand after reading it - leakage inductance
- Intelligent Temperature Controller Based on FPGA
- How to understand these four statements in STM32F103RCT6? The return statement should be declared before the main function, right?
- MSP430 JTAG interface and BSW interface