If you don’t want to miss my updates, remember to check the public account in the upper right corner and set it as a star. Send a star to me!



Here are two photos from the game:


System Hardware:The system consists of the ZhiZhe development board and a 4.2-inch UART HMI serial screen. It could actually be done with the smallest core board, as the microcontroller peripherals only use the serial port. However, since a development board is required, it feels a bit wasteful.
Software Part:The software part is the core of this project.
Initially, I referenced some Minesweeper code online. There are many differences on the microcontroller, but the general idea is the same. The main challenge is the communication protocol with the serial screen. Here’s a simple piece of communication code.
Specific functionalities completed:
1. Basic Minesweeper functionality
2. When all surrounding mines are marked, open the remaining unmarked squares
// Serial receive interrupt void USART1_IRQHandler(void) { if(huart1.Instance->SR&(1<<5)) // If data is received { buf=huart1.Instance->DR; // Receiving selected square serial communication protocol if(id_flag==1) { if(buf==0xff) { id_flag=0; count=0; select_id=buff[0]; select_flag=1; } else { buff[count++]=buf; } } if(buf==0xaa) { id_flag=1; } } // Receiving selected square serial communication protocol // Opening a safe square serial communication protocol if(buf==0xbb) { safe_flag=1; } // Opening a safe square serial communication protocol // Restarting serial communication protocol if(buf==0xcc) { refreshall_flag=1; } // Restarting safe square serial communication protocol // Marking bomb serial communication protocol if(buf==0xdd) { zhadan_flag=~zhadan_flag; // Clicking once on the screen marks the bomb, clicking again cancels the marking } // Marking bomb safe square serial communication protocol }
The communication protocol with the serial screen uses the HAL library, with CubeMX assisting in development.There is dedicated software for the serial screen called UART HMI.Here’s another piece of serial screen communication code I wrote (suitable for HAL library).
/* UART HMI serial screen communication function HMISendnum1, 2, 3 are different strings and numbers concatenated. The following parameters are the serial port number, suitable for HAL library */ void HMISendnum1(char *str1,int nums,UART_HandleTypeDef uart) { HAL_StatusTypeDef Flag; uint8_t b=0xff,i; char buf1[10]; sprintf(buf1, "%s%d", str1, nums); Flag=HAL_UART_Transmit(&uart,(uint8_t*)buf1,strlen(buf1),0xffffffff); while(Flag!=HAL_OK); for(i=0;i<3;i++) { if(b!=0) { HAL_UART_Transmit(&uart,&b,1,0xff); while(Flag!=HAL_OK); } else return; } } void HMISendnum2(char *str1,int nums,char *str2,UART_HandleTypeDef uart) { HAL_StatusTypeDef Flag; uint8_t b=0xff,i; char buf1[10]; sprintf(buf1, "%s%d%s", str1, nums,str2); Flag=HAL_UART_Transmit(&uart,(uint8_t*)buf1,strlen(buf1),0xffffffff); while(Flag!=HAL_OK); for(i=0;i<3;i++) { if(b!=0) { HAL_UART_Transmit(&uart,&b,1,0xff); while(Flag!=HAL_OK); } else return; } } void HMISendnum3(char *str1,int nums1,char *str2,int nums2,UART_HandleTypeDef uart) { HAL_StatusTypeDef Flag; uint8_t b=0xff,i; char buf1[10]; sprintf(buf1, "%s%d%s%d", str1, nums1,str2,nums2); Flag=HAL_UART_Transmit(&uart,(uint8_t*)buf1,strlen(buf1),0xffffffff); while(Flag!=HAL_OK); for(i=0;i<3;i++) { if(b!=0) { HAL_UART_Transmit(&uart,&b,1,0xff); while(Flag!=HAL_OK); } else return; } } // Control the text control of the serial screen, input string commands, followed by the communication serial port number void HMISendtxt(char *str,UART_HandleTypeDef uart) { HAL_StatusTypeDef Flag; uint8_t b=0xff,i; Flag=HAL_UART_Transmit(&uart,(uint8_t*)str,strlen(str),0xff); while(Flag!=HAL_OK); for(i=0;i<3;i++) { if(b!=0) { HAL_UART_Transmit(&uart,&b,1,0xffffffff); while(Flag!=HAL_OK); } else return; } }
Other specific codes are not pasted for now. If you are interested in this project, you can add QQ: 943874487 to discuss together. You can also check young0219’s blog:
https://blog.csdn.net/weixin_43793057/article/details/106158063
Sharing a point about why the time function cannot be used in Keil:
Keil does not support the time() function, which troubled me for a long time. Since generating mines requires a random function, a random seed must be used, which requires the time() function. After many attempts, I still couldn’t use this function, so I asked a very skilled senior, who told me that Keil does not support the time function (if anyone can use it, please let me know, thanks). At the same time, he proposed another solution, using the timer value as the random seed. Initially, it didn’t work because the mines were initialized at the same time, resulting in the same random seed value. However, after adding the interface, the time entering the game became random, which can be considered a successful solution to this problem.

Graduation Project Series:
Temperature/Heart Rate/Step Count Design based on STM32
Smart Automated Light-Following Fire Extinguishing Car
51 Microcontroller + HX711 to Achieve Simple Electronic Scale
Low-Cost STM32 IoT Portable Power Meter
STM32 + OV7670 Design License Plate Recognition System
Homemade Mobile App and Arduino for Smart Monitoring and Control System
STM32F103 + NB Module + MQTT for IoT Collection System
7 Days to Complete Gesture-Controlled ESP32 WIFI Digital Photo Frame
Homemade STM32 Multimeter, Outperforming 500 Yuan Regular Brands
Homemade Simple Blood Oxygen Heart Rate Monitor STM32 + MAX30100
STM32 + Zigbee Networking Ordering System
STM32 Smart Trash Can Automatically Identifying Various Types of Trash
Based on MCU Development Board + Camera for “Artificial” Parking Assistant
STM32 and MPU6050 for Body-Sensing Gimbal Design
More Intelligent “Xiao Ai”?
STM32F4 + H7 to Achieve Bionic Robotic Dog
Low-Cost 360° Monitoring System
STM32 Version RFID Medical Order-Specific Wristband
Smart Home System Design Controlled by STM32 Microcontroller
STM32F4 E-Reader Production Tutorial
Graduation Project | Smart Infusion Monitoring System
Raspberry Pi 3B+ with OpenCV3 + PyQt5 for Face Recognition Access Control
Gesture-Controlled Dot Matrix Display Design Based on STM32
Learn and Use Immediately, Share the Whole Process of Building a Fingerprint Recognition System
Homemade Hexapod Robot, Challenging, Enter at Your Own Risk
True Human-Machine Interaction, Cloud-Based Intelligent Butler (My Graduation Project, My Heart’s Blood)
STM32 Bluetooth Smart Car (Sharing Code and Android APK)
STM32 + TI BQ76940 Design 48V BMS Solution (Data Sharing)
STM32 Slope Driving Line Following Car Production Tutorial
Simple Anti-Fatigue Driving Detection Under 100 Yuan
STM32 + OneNET for NB-IOT Power Collection System
Designing Parking Lot Management System Using ARM Platform (With Tutorial & Data)
Smart WIFI LED Light Design
LCD Digital BOOST Circuit Design
STM32 Smart Baby Crib Monitoring (Basic Version)
Project Sharing | Electric Competition Series | Artificial Intelligence | Graduate School Entrance Exam
Must-Know Knowledge Points | Graduation Project | Switch Power Supply | Job Search
We are Nimo, the founders of Darwin, who only talk about technology and not about flirting. DarwinOnline education platform aims to serve professionals in the electronics industry, providing skill training videos covering popular topics in various subfields, such as embedded systems, FPGA, artificial intelligence, etc. We also tailor hierarchical learning content for different groups, such as common knowledge points, disassembly assessments, electric competitions/smart cars/graduate exams, etc. Welcome to follow us.
