【GD32L233C-START Review】Touch screen control LED based on serial communication
[Copy link]
This post was last edited by jinglixixi on 2022-2-13 10:38
The parameters can be set by using the touch operation of the DWIN smart screen, and the set parameters can be output via serial communication.
If this parameter is received, the peripheral can be controlled.
If this parameter is received, the peripheral can be controlled.
To this end, a function of controlling the LED by touch operation is designed here. The circuit connection is shown in Figure 1, that is, the TX2 and GND pins of the smart screen are connected to the RX and GND of the GD32L233 development board respectively to form a serial communication channel.
Figure 1 Circuit connection
In this way, after receiving the setting parameters, you can control the status of the 4 LED lights on the development board according to the parameter values.
When using the serial port debugging assistant, you can observe the data sent by the touch operation, as shown in Figure 2.
Figure 2 Data output effect
According to the instruction structure of the smart screen, the set parameters are the contents of the last two bytes. Taking "5A A5 06 83 10 70 01 00 01" as an example, "00 01" is the parameter value.
For this purpose, a program can be written on the development board side to receive the data sent by the smart screen and extract the parameter value. Then, in the main program, the LED can be controlled to produce different effects according to the different parameter values.
The contents of the main program are:
int main(void)
{
uint16_t n;
led_init();
systick_config();
nvic_irq_enable(USART0_IRQn, 0);
playm();
gd_eval_com_init(EVAL_COM);
usart_interrupt_disable(USART0, USART_INT_TBE);
while(1)
{
rx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_RBNE);
while(rx_counter < nbr_data_to_read);
n=tx_buffer[6] = rx_buffer[8];
if(n==1)
{
playm();
gd_eval_led_on(LED1);
}
if(n==2)
{
playm();
gd_eval_led_on(LED2);
}
if(n==3)
{
playm();
gd_eval_led_on(LED3);
}
if(n==4)
{
playm();
gd_eval_led_on(LED4);
}
if(n==5)
{
playm();
}
if(n==6)
{
gd_eval_led_on(LED1);
gd_eval_led_on(LED2);
gd_eval_led_on(LED3);
gd_eval_led_on(LED4);
}
delay_1ms(200);
rx_counter=0;
usart_interrupt_enable(USART0, USART_INT_RBNE);
delay_1ms(200);
}
}
After the program is compiled and downloaded, touch operations can be provided to produce the control effects shown in Figures 3 to 5.
Figure 3 Light up all LEDs
Figure 4 Light up the specified LED
Figure 5 Turn off all LEDs
On this basis, if a W2812 color light ring is added to one side of the development board, colorful color effects can be produced to create a lighting atmosphere for the environment.
Since W2812 is a single-bus device, it only needs one GPIO pin to complete its control. Its signal pin is connected to PB10. The connection relationship is shown in Figure 6.
Figure 6 Device connection
The main program to realize W2812 control is:
int main(void)
{
uint16_t n;
led_init();
systick_config();
nvic_irq_enable(USART0_IRQn, 0);
playm();
gd_eval_com_init(EVAL_COM);
usart_interrupt_disable(USART0, USART_INT_TBE);
WS2812B_Init();
while(1)
{
rx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_RBNE);
while(rx_counter < nbr_data_to_read);
n=tx_buffer[6] = rx_buffer[8];
if(n==1)
{
WS2812B_DisplayAllRed();
}
if(n==2)
{
WS2812B_DisplayAllGreen();
}
if(n==3)
{
WS2812B_DisplayAllBlue();
}
if(n==4)
{
WS2812B_Displayyellow();
}
if(n==5)
{
WS2812B_DisplayMAGENTA();
}
if(n==6)
{
WS2812B_DisplayGBLUE();
}
if(n==7)
{
WS2812B_DisplayAll();
}
delay_1ms(200);
rx_counter=0;
usart_interrupt_enable(USART0, USART_INT_RBNE);
delay_1ms(200);
}
}
After the program is compiled and downloaded, the control effects are shown in Figures 7 to 9.
Figure 7 Display effect 1
Figure 8 shows the effect 2
Figure 9 shows the effect 3
Demo video:
|