IOT

Tic-tac-toe Game Based on STONE TFT LCD and STM32

Summary

Tic-tac-toe is a game played on a 3 by 3 grid, similar to gobang. It gets its name because the board generally does not draw borders and the grid lines are arranged into tic-tac-toe. The tools needed for the game are only paper and pen. Then, two players representing O and X take turns to leave marks on the grid. Any three marks form a straight line, which is the winner.

This article is to use microcontroller STM32 and STONE LCD display to develop a simple tic-tac-toe game.

Materials required for the experiment

The system principle

Specify the first tap on the screen must be O, the second tap on the screen is X, has been doing this cycle. Set 8 arrays to store the number of O and X in each row, column and diagonal of each grid, as long as there are three of the same mark is the victory, then there will be a flashing red box to prove the victory of the row, column or diagonal, and then tap reset to start the game again.

The following is the flow chart :

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

STM32 and STONE LCD Display System hardware design

(A) STONE LCD display

  1. “Tic-tac-toe game” hardware design

Use STONE LCD display of Beijing STONE Technology co., ltd, the model is STWI070WT-01, with an integrated TFT display and touch controller.

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.
  1.  STVC070WT-01 product features
Physical Parameter 
Size7 inch
Resolution800×RGB×480
Pixel Spacing0.0642(W) × 0.1790(H) mm
Color262,144 colors (18 bit)
Viewing Area154.08(W) × 85.92(H) mm
Display Dimension186.4mmx105.5mm
Overall Dimension186.4mmx105.5mmx17.4mm(Standard type)186.4mmx105.5mmx23.8mm(with Ethernet port)
Net Weight300g
Display 
Backlight TypeLED
Brightness300cd/m2(Brightness can be adjustable in 100 levels)
Contrast500:1
Backlight life300,000 hours
Viewing Angle70°/70°/50°/70°(L/R/U/D)
TFT PanelA Class Industry Panel
Touch Screen4 Wire Resistance Touch /Capacitive Touch/ Without Touch Screen
Screen Mode:Digital
Processor 
CPUCortex A8
Refresh Rate1G Hz
Max Frame rate60 FPS
Interface 
Serial InterfaceRS232 / RS422 / RS485 / TTL level
Ethernet interface10M/100M (Optional)
Wireless interfaceWi-Fi / Bluetooth (Optional)
Project file downloadingUSB2.0 port or U storage Disk
Power Supply 
Rated voltage+12V DC or +5V DC
Permissible voltage range+7V DC…+28V DC or +5V DC
Max. permissible transients+28V
Time between two transients50 sec minimum
Internal Fuse2A self-recovery fuse
Power consumption3.0 W
Ambient Conditions 
Max. permissible ambient temperatureOperationStorage-20℃~ +70℃-30℃~ +80℃
Relative humidityOperationStorage55℃,85%60℃,90%
Shock loadingOperationStorage15 g/11 msec25 g/6 msec
VibrationOperationStorage0.035 mm (10 – 58 Hz)/ 1 g (58 – 500 Hz)3.5 mm (5 – 8,5 Hz)/ 1 g (8.5 – 500 Hz)
Barometric pressureOperationStorage706 to 1030 hPa581 to 1030 hPa
Noise Immunity 
Static discharge(contact discharge/air discharge)EN 61000-4-2 6 kV/8 kV
RF irradiationEN 61000-4-310 V/m, 80% AM1 kHz
Pulse modulationENV 50204900 MHz ±5 MHz10 V/meff., 50% ED, 200 Hz
RF conductionEN 61000-4-6150 kHz – 80 MHz10 V, 80% AM, 1 kHz
Burst interferenceSupply linesProcess data linesSignal linesEN 61000-4-42kV2kV1kV
Support Device 
UART PortSupportRS232 / RS422 / RS485 / TTL
Network PortSupportEthernet Port / Wi-Fi / Bluetooth
Flash MemorySupportStandard 256MB, Extend 1GB or 2GB
BuzzerSupport
RTCSupport
USB portSupportOnline Download By USB Cable
U Storage Disk InterfaceSupport.Offline Download or Copy User Data
Touch Screen4 Wire Resistance / Capacitive
Vector FontStandard TTF Format
ImageSupport PNG/JPG/BMP/SVG/GIF Format
Audio InterfaceSupport WAV formatThe length of single audio file is not limited, theoretically up to 4096 audio files, speaker power is 8 ohms 2 watts or 4 ohms 3 watts
Command SetUnified Simplified Command Sets
Memory 
Flash MemoryStandard 256MB, Extension 1GB or 2GB
Memory Amount for ImageAccording to the capability of the image, Suggest “PNG, BMP, JPG, SVG, GIF” format.

(B) STM32 board

Using a STM32 board, the chip of the STM32 is CKS32F303.

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

The STM32 family of ARM Cortex-M0, M0+, M3, M4 and M7 cores is designed for embedded applications requiring high performance, low cost and low power consumption.

  • 2.0V-3.6V power supply
  • 5V compatible I/O pins
  • Excellent safe clock mode
  • Low power mode with wake-up function
  • Internal RC oscillator
  • Embedded reset circuit
  • Operating temperature range.
  • -40°C to +85°C or 105°C

System software design

The development process of STM32 and STONE LCD display

1: create the project and load the required pictures into the project.

2: use the Stone-designer software to create, dynamically associated relationships; the main controls are: “Button”, “image”;

3: software simulation and compilation to generate executable files.

4: the LCD display is connected to the PC via USB and copy the executable file to the screen.

First create a new project as shown below.

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.
Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Secondly, import all the images into the resource

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Then, set button controls to each grid and make the buttons invisible. 

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Don’t forget to set the reset button!

The finished effect is shown below:

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

After that, add image controls to each grid in the same way, and set them all to white images.

Finally add the gif control and set it to invisible.

The parts of finished effect are shown below:

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.
Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.
Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.
Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Circuit connection diagram

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Code sharing

/* Includes ——————————————————————*/ 

#include “stm32f0xx_hal.h” 

#include “Uart.h” 

#include “string.h” 

#include “ws2812.h” 

#include “IWDG.h” 

RGB_COLOR USER_RGB_COLOR; 

unsigned char TX_Mode = 1; //Transmission type flag bit 1:232 0:TTL 

unsigned char BLINK_2=0; 

unsigned char RX3_BUF[32]; //Customized three-level receive buffer 

#define BUTTON1 0x81 

#define BUTTON2 0x82 

#define BUTTON3 0x83 

#define BUTTON4 0x84 

#define BUTTON5 0x85 

#define BUTTON6 0x86 

#define BUTTON7 0x87 

#define BUTTON8 0x88 

#define BUTTON9 0x89 

#define BUTTON0 0x8A 

#define CLEAR 0x8E 

unsigned int r_flag1 = 0; 

unsigned int quan[4][2]={0}; 

unsigned int cha [4][2]={0}; 

unsigned int quan_hang1 = 0; 

unsigned int quan_hang2 = 0; 

unsigned int quan_hang3 = 0; 

unsigned int quan_lie1 = 0; 

unsigned int quan_lie2 = 0; 

unsigned int quan_lie3 = 0; 

unsigned int quan_zuoxia = 0; 

unsigned int quan_youxia = 0; 

unsigned int cha_hang1 = 0; 

unsigned int cha_hang2 = 0; 

unsigned int cha_hang3 = 0; 

unsigned int cha_lie1 = 0; 

unsigned int cha_lie2 = 0; 

unsigned int cha_lie3 = 0; 

unsigned int cha_zuoxia = 0; 

unsigned int cha_youxia = 0; //unsigned int r_flag10 = 0; 

void SystemClock_Config(void); 

void Error_Handler(void); 

static void MX_GPIO_Init(void); 

int main(void) 

uint8_t color_buf = 0; 

//Function Selection 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 

HAL_Init(); 

/* Configure the system clock */ 

SystemClock_Config(); 

/* Initialize all configured peripherals */ 

MX_GPIO_Init(); 

TX_Mode = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_4); 

if(TX_Mode) 

MX_USART1_UART_Init(); 

//232 Initialization 

else 

MX_USART1_UART_Init2(); 

//TTl Initialization 

while(1) 

if(TX_Mode != HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_4)) 

HAL_NVIC_SystemReset(); 

//Jumper reversal, reboot and reinitialization 

if(MNG_USART1.RX_OVER_FLG ==TRUE) 

// 

Serial data receive flag bit 

RX3_BUF[0]=MNG_USART1.RX_BUF[7]; 

//Method 2:Get fixed length control name 

RX3_BUF[1]=MNG_USART1.RX_BUF[8]; 

RX3_BUF[2]=MNG_USART1.RX_BUF[9]; 

RX3_BUF[3]=MNG_USART1.RX_BUF[10]; 

RX3_BUF[4]=MNG_USART1.RX_BUF[11]; 

RX3_BUF[5]=MNG_USART1.RX_BUF[12]; 

RX3_BUF[6]=MNG_USART1.RX_BUF[13]; 

//RX3_BUF[7]=MNG_USART1.RX_BUF[14]; 

if((strcmp(“button1”,(const char *)RX3_BUF))==0) 

//Select control

color_buf = BUTTON1; 

}

if((strcmp(“button2”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON2; 

}

if((strcmp(“button3”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON3; 

}

if((strcmp(“button4”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON4; 

}

if((strcmp(“button5”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON5; 

}

if((strcmp(“button6”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON6; 

}

if((strcmp(“button7”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON7; 

}

if((strcmp(“button8”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON8; 

}

if((strcmp(“button9”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON9; 

}

if((strcmp(“button0”,(const char *)RX3_BUF))==0) 

color_buf = BUTTON0; 

}

switch (color_buf) 

case BUTTON1: 

//if(r_flag1 == 0) 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

r_flag1 ^= 1; 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image2\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 ^= 1; 

quan_hang1++; 

quan_lie1++; 

quan_youxia++;  

//memset(RX3_BUF,0,7); 

//memset(MNG_USART1.RX_BUF,0,USART1_RX_LEN); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image2\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang1++; 

cha_lie1++; 

cha_youxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

//r_flag1 = 1; 

break; 

case BUTTON2: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image3\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang1++; 

quan_lie2++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image3\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang1++; 

cha_lie2++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON3: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image4\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang1++; 

quan_lie3++; 

quan_zuoxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image4\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang1++; 

cha_lie3++; 

cha_zuoxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON4: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image5\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang2++; 

quan_lie1++; 

//memset(RX3_BUF,0,7); 

//r_flag10=1; 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image5\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang2++; 

cha_lie1++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON5: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image6\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang2++; 

quan_lie2++; 

quan_zuoxia++; 

quan_youxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image6\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang2++; 

cha_lie2++; 

cha_zuoxia++; 

cha_youxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON6: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image7\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang2++; 

quan_lie3++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02))

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image7\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang2++; 

cha_lie3++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON7: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image8\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang3++; 

quan_lie1++; 

quan_zuoxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image8\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang3++; 

cha_lie1++; 

cha_zuoxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON8: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image9\”,\”image\”:\”circle\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang3++; 

quan_lie2++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image9\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang3++; 

cha_lie2++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON9: 

if((r_flag1 == 0)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image10\”,\”image\”:\”circle\”}>ET”);

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 1; 

quan_hang3++; 

quan_lie3++; 

quan_youxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

else if((r_flag1 == 1)&&(MNG_USART1.RX_BUF[14] == 0x02)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image10\”,\”image\”:\”x\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

r_flag1 = 0; 

cha_hang3++; 

cha_lie3++; 

cha_youxia++; 

//memset(RX3_BUF,0,7); 

color_buf = CLEAR; 

}

break; 

case BUTTON0: 

r_flag1 = 0; 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image2\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image3\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image4\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image5\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image6\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image7\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image8\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image9\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1);

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_image\”,\”type\”:\”image\”,\”widget\”:\”image10\”,\”image\”:\”bai\”}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif4\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif5\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif6\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif7\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif8\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif9\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif10\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif11\”,\”visible\”:false}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

//memset(RX3_BUF,0,7); 

memset(MNG_USART1.RX_BUF,0,USART1_RX_LEN); 

break; 

default: 

MNG_USART1.RX_OVER_FLG = FALSE; 

break; 

}

//////////////////////////////////////////////////////////////////// 

if((quan_hang1==3)||(cha_hang1==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif4\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_hang2==3)||(cha_hang2==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif5\”,\”visible\”:true}>ET”);

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_hang3==3)||(cha_hang3==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif6\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_lie1==3)||(cha_lie1==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif7\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_lie2==3)||(cha_lie2==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif8\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_lie3==3)||(cha_lie3==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif9\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_zuoxia==3)||(cha_zuoxia==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif11\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

}

else if((quan_youxia==3)||(cha_youxia==3)) 

memset(MNG_USART1.TX_BUF,0,USART1_TX_LEN); 

sprintf((char *)MNG_USART1.TX_BUF, 

“ST<{\”cmd_code\”:\”set_visible\”,\”type\”:\”widget\”,\”widget\”:\”gif10\”,\”visible\”:true}>ET”); 

MNG_USART1.TX_Byte_Num = strlen((const char *)MNG_USART1.TX_BUF); 

USART_TX_Data(MNG_USART1); 

quan_hang1=quan_hang2=quan_hang3=cha_hang1=cha_hang2=cha_hang3=0; 

quan_lie1=quan_lie2=quan_lie3=cha_lie1=cha_lie2=cha_lie3=0; 

quan_zuoxia=quan_youxia=cha_zuoxia=cha_youxia=0; 

MNG_USART1.RX_OVER_FLG = FALSE; 

}

/** System Clock Configuration 

*/

void SystemClock_Config(void) 

RCC_OscInitTypeDef RCC_OscInitStruct; 

RCC_ClkInitTypeDef RCC_ClkInitStruct; 

RCC_PeriphCLKInitTypeDef PeriphClkInit; 

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 

RCC_OscInitStruct.HSIState = RCC_HSI_ON; 

RCC_OscInitStruct.HSICalibrationValue = 16; 

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; 

RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; 

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 

Error_Handler(); 

}

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 

|RCC_CLOCKTYPE_PCLK1; 

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) 

Error_Handler(); 

}

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; 

PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; 

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 

Error_Handler(); 

}

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 

/* SysTick_IRQn interrupt configuration */ 

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 

}

/** Pinout Configuration 

*/

static void MX_GPIO_Init(void) 

GPIO_InitTypeDef GPIO_InitStruct; 

/* GPIO Ports Clock Enable */ 

__HAL_RCC_GPIOA_CLK_ENABLE(); 

GPIO_InitStruct.Pin = GPIO_PIN_7; 

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP ; 

GPIO_InitStruct.Pull = GPIO_PULLDOWN; 

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 

GPIO_InitStruct.Pin = GPIO_PIN_4; 

GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 

GPIO_InitStruct.Pull = GPIO_PULLUP; 

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */ 

/**

* @brief This function is executed in case of error occurrence. 

* @param None 

* @retval None 

*/ 

void Error_Handler(void) 

/* USER CODE BEGIN Error_Handler */ 

/* User can add his own implementation to report the HAL error return state */ 

while(1) 

{

}

/* USER CODE END Error_Handler */ 

}

#ifdef USE_FULL_ASSERT 

/**

* @brief Reports the name of the source file and the source line number 

* where the assert_param error has occurred. 

* @param file: pointer to the source file name 

* @param line: assert_param error line source number 

* @retval None 

*/ 

void assert_failed(uint8_t* file, uint32_t line) 

/* USER CODE BEGIN 6 */ 

/* User can add his own implementation to report the file name and line number, 

ex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) */ 

/* USER CODE END 6 */ 

}

#endif 

/**

* @} 

*/ 

/**

* @} 

*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Final results show

Tic-tac-toe Game Based on STONE TFT LCD and STM32 IOT PlatoAiStream PlatoAiStream. Data Intelligence. Vertical Search. Ai.

Source: Plato Data Intelligence