[GD32L233C-START Review] ML Component Control
[Copy link]
With the serial communication function of the GD32L233C-START development board, not only can the devices and functional modules controlled by serial communication be controlled, but also data can be sent to the host computer through the serial port to realize the driving of interface controls.
MicroLab is a multifunctional auxiliary tool. The interface design and display functions it provides can intuitively reflect the changes in test data in a component-based manner.
There are many types of ML components, such as scales, instrument panels, batteries, progress balls, and digital tubes. Figure 1 is a display interface made with ML components, and Figure 2 shows the display effect driven by data.
Figure 1 ML interface form
Figure 2 Data driven effect
In MicroLab, the data that drives the ML component needs to be encapsulated, which is relatively complex. To facilitate porting and use, we write the data encapsulation function based on its structural characteristics, and store the encapsulation results in an array for serial port transmission.
The corresponding array initial values are:
char zl[20]={0x58, 0x5A, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
char data[4]={0x00, 0x00, 0x00, 0x00};
The function to implement floating point conversion is:
void updateCanvas(char * data, unsigned short datalen)
{
zl[17]= data[2];
zl[18]= data[3];
}
The data encapsulation function of the ML component is:
void change(uint8_t i, uint8_t n)
{
uint8_t CV;
CV=0xC9;
if(i==0)
{
zl[9]=0xEF;
}
if(i==1)
{
zl[9]=0xE9;
}
if(i==2)
{
zl[9]=0xEA;
}
if(i==3)
{
zl[9]=0xF2;
}
if(i==4)
{
zl[9]=0xEB;
}
...
if(n==0)
{
zl[11]=0x00;
}
if(n==1)
{
zl[11]=0x01;
}
if(n==2)
{
zl[11]=0x02;
}
...
CV=CV+zl[9]+zl[11]+zl[17]+zl[18];
zl[19]=CV;
}
The main program to achieve the driving effect shown in Figure 2 is:
int main(void)
{
int16_t i,n;
float x = 57;
unsigned short msglen;
char * tbuffer;
systick_config();
nvic_irq_enable(USART0_IRQn, 0);
gd_eval_com_init(EVAL_COM);
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
updateCanvas( (char *)&x, sizeof(float));
change(1, 0);
while(tx_counter < 20) {
}
delay_1ms(100);
x = 60;
updateCanvas( (char *)&x, sizeof(float));
change(2, 0);
tx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
while(tx_counter < 20) {
}
delay_1ms(100);
x = 26;
updateCanvas( (char *)&x, sizeof(float));
change(3, 0);
tx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
while(tx_counter < 20) {
}
tx_counter=0;
delay_1ms(100);
x = 75;
updateCanvas( (char *)&x, sizeof(float));
change(3, 1);
tx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
while(tx_counter < 20) {
}
tx_counter=0;
delay_1ms(100);
x = 1024;
updateCanvas( (char *)&x, sizeof(float));
change(4, 1);
tx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
while(tx_counter < 20) {
}
tx_counter=0;
delay_1ms(100);
x = 720;
updateCanvas( (char *)&x, sizeof(float));
change(4, 0);
tx_counter=0;
usart_interrupt_enable(EVAL_COM, USART_INT_TBE);
while(tx_counter < 20) {
}
while (1);
}
The test result using the serial port debugging tool is shown in Figure 3. Based on this program, dynamic data indication can be achieved by connecting corresponding sensors.
Figure 3 Serial port test results
|