[DigiKey Creative Contest] Speedometer_Define pins for EK-RA2E1 development board using e2studio
[Copy link]
In order to display the speed, a three-digit seven-segment digital tube is used for output.
Here, only two wires are connected to the hundreds place to display the 1 in the hundreds place, and 7 wires are needed for the tens place and the ones place except the decimal place. This article introduces how to configure and use these 16 GPIOs.
First the code:
const unsigned char led[] = {
0x3f,/* 0 */
0x06,/* 1 */
0x5b,/* 2 */
0x4f,/* 3 */
0x66,/* 4 */
0x6d,/* 5 */
0x7d,/* 6 */
0x07,/* 7 */
0x7f,/* 8 */
0x6f /* 9 */
};
struct digit obj[DIGIT_MAX] =
{
{0, D3a, D3b, D3c, D3d, D3e, D3f, D3g},
{0, D2a, D2b, D2c, D2d, D2e, D2f, D2g }
};
/* the number ranges from 0 to 199 */
void show_number(uint8_t number)
{
volatile uint8_t i, j;
obj[0].value = led[number % 10];
if(number < 10)
{
obj[1].value = 0x00;
R_BSP_PinWrite(D1b, 1);
R_BSP_PinWrite(D1c, 1);
}
else if(number < 100)
{
number /= 10;
obj[1].value = led[number % 10];
R_BSP_PinWrite(D1b, 1);
R_BSP_PinWrite(D1c, 1);
}
else if(number < 200)
{
number /= 10;
obj[1].value = led[number % 10];
R_BSP_PinWrite(D1b, 0);
R_BSP_PinWrite(D1c, 0);
}
else
{
obj[0].value = 0x40;
obj[1].value = 0x40;
R_BSP_PinWrite(D1b, 1);
R_BSP_PinWrite(D1c, 1);
}
for(i=0; i< DIGIT_MAX; i++)
{
for(j=0; j< 7; j++)
{
R_BSP_PinWrite((bsp_io_port_pin_t) obj[i].pin[j], ~(obj[i].value >> j) & 0x01);
}
}
}
The pin name uses the name of the application, so how does it correspond to the actual pin?
In turn, in the configuration menu, define aliases for all the pins to be used, and then regenerate the code automatically:
The advantage is:
When we need to change the pins, we don't need to change a line of code. We just need to go to the configuration interface to reconfigure the new pins and regenerate them.
And it can also automatically generate comments!
weakness is:
This path is so strange, I searched for it for a long time.
It is also difficult to quote.
The compilation tools do not automatically search for this file.
Summary: It took me a long time to figure it out when I first started, as the IDE lacked the necessary prompts, but it was quite easy to use after I got familiar with it.
|