Production of keil electronic clock based on RASC (Renesas RA) (5)----driving LED digital tube

overview

This article mainly introduces how to use e2studio to drive the digital tube of the Renesas RA2E1 development board.

hardware preparation

First, you need to prepare a development board. Here I am preparing a development board with chip model R7FA2E1A72DFL:

insert image description here

insert image description here

video tutorial

https://www.bilibili.com/video/BV1Bx4y197iy/

keil electronic clock production based on RASC (Renesas RA)----(5) drive LED digital tube

Description of digital tube

You can know from the manual that the digital tube is a common cathode.
insert image description here

Check the schematic diagram at the same time, you can see that the digital tube is connected to the corresponding pin of the MCU.
insert image description here

Configure these IOs as output ports. When the red is high and the blue is low, the LED is on.
insert image description here

Configure the IO port

Configure the IOs connected to the digital tubes as Output mode (Initial Low) mode.
insert image description here

Nixie tube display library

The control and teaching of the digital tube is as follows.
insert image description here

The figure below lists the segments that light up when the nixie tube displays 0 to F. For example, when the number 0 is displayed, all segments except the G segment in the middle are lit. The number 1 only lights up segment B and segment C.

insert image description here

The project here is an electronic clock, so the fonts to be used are 0-9. The font library of temperature and humidity will be added later.
Create new smg.c and smg.h files to save the driver of the digital tube.
insert image description here

Save them to the SRC folder.

insert image description here

smg.c

/*
 * smg.c
 *
 *  Created on: 2023年6月29日
 *      Author: a8456
 */

#include "smg.h"
#include "hal_data.h"


void smg_num(int num)
{
    
    
    switch(num)
    {
    
    
        case 0:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_OPEN;
            SMG_F_OPEN;
            SMG_G_CLOSE;
            SMG_DP_CLOSE;
            break;
        }
        case 1:
        {
    
    
            SMG_A_CLOSE;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_CLOSE;
            SMG_E_CLOSE;
            SMG_F_CLOSE;
            SMG_G_CLOSE;
            SMG_DP_CLOSE;
            break;
        }
        case 2:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_CLOSE;
            SMG_D_OPEN;
            SMG_E_OPEN;
            SMG_F_CLOSE;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 3:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_CLOSE;
            SMG_F_CLOSE;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 4:
        {
    
    
            SMG_A_CLOSE;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_CLOSE;
            SMG_E_CLOSE;
            SMG_F_OPEN;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 5:
        {
    
    
            SMG_A_OPEN;
            SMG_B_CLOSE;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_CLOSE;
            SMG_F_OPEN;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 6:
        {
    
    
            SMG_A_OPEN;
            SMG_B_CLOSE;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_OPEN;
            SMG_F_OPEN;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 7:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_CLOSE;
            SMG_E_CLOSE;
            SMG_F_CLOSE;
            SMG_G_CLOSE;
            SMG_DP_CLOSE;
            break;
        }
        case 8:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_OPEN;
            SMG_F_OPEN;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }
        case 9:
        {
    
    
            SMG_A_OPEN;
            SMG_B_OPEN;
            SMG_C_OPEN;
            SMG_D_OPEN;
            SMG_E_CLOSE;
            SMG_F_OPEN;
            SMG_G_OPEN;
            SMG_DP_CLOSE;
            break;
        }




    }



}

void smg_1(int num)
{
    
    
    SMG_1_OPEN;
    SMG_2_CLOSE;
    SMG_3_CLOSE;
    SMG_4_CLOSE;

    smg_num(num);

}


void smg_2(int num)
{
    
    
    SMG_1_CLOSE;
    SMG_2_OPEN;
    SMG_3_CLOSE;
    SMG_4_CLOSE;
    smg_num(num);

}



void smg_3(int num)
{
    
    
    SMG_1_CLOSE;
    SMG_2_CLOSE;
    SMG_3_OPEN;
    SMG_4_CLOSE;
    smg_num(num);

}



void smg_4(int num)
{
    
    

    SMG_1_CLOSE;
    SMG_2_CLOSE;
    SMG_3_CLOSE;
    SMG_4_OPEN;
    smg_num(num);

}


void smg_1_p(void)
{
    
    
    SMG_1_OPEN;
    SMG_2_CLOSE;
    SMG_3_CLOSE;
    SMG_4_CLOSE;

    SMG_A_OPEN;
    SMG_B_OPEN;
    SMG_C_CLOSE;
    SMG_D_CLOSE;
    SMG_E_OPEN;
    SMG_F_OPEN;
    SMG_G_OPEN;
    SMG_DP_CLOSE;

}





void smg_1_close(void)
{
    
    
    SMG_1_OPEN;
    SMG_2_CLOSE;
    SMG_3_CLOSE;
    SMG_4_CLOSE;

    SMG_A_CLOSE;
    SMG_B_CLOSE;
    SMG_C_CLOSE;
    SMG_D_CLOSE;
    SMG_E_CLOSE;
    SMG_F_CLOSE;
    SMG_G_CLOSE;
    SMG_DP_CLOSE;

}


void smg_2_close(void)
{
    
    
    SMG_1_CLOSE;
    SMG_2_OPEN;
    SMG_3_CLOSE;
    SMG_4_CLOSE;

    SMG_A_CLOSE;
    SMG_B_CLOSE;
    SMG_C_CLOSE;
    SMG_D_CLOSE;
    SMG_E_CLOSE;
    SMG_F_CLOSE;
    SMG_G_CLOSE;
    SMG_DP_CLOSE;
}



void smg_3_close(void)
{
    
    
    SMG_1_CLOSE;
    SMG_2_CLOSE;
    SMG_3_OPEN;
    SMG_4_CLOSE;

    SMG_A_CLOSE;
    SMG_B_CLOSE;
    SMG_C_CLOSE;
    SMG_D_CLOSE;
    SMG_E_CLOSE;
    SMG_F_CLOSE;
    SMG_G_CLOSE;
    SMG_DP_CLOSE;
}



void smg_4_close(void)
{
    
    
    SMG_1_CLOSE;
    SMG_2_CLOSE;
    SMG_3_CLOSE;
    SMG_4_OPEN;

    SMG_A_CLOSE;
    SMG_B_CLOSE;
    SMG_C_CLOSE;
    SMG_D_CLOSE;
    SMG_E_CLOSE;
    SMG_F_CLOSE;
    SMG_G_CLOSE;
    SMG_DP_CLOSE;
}








void smg_maohao_open(int num)
{
    
    

    SMG_1_CLOSE;
    SMG_2_CLOSE;

    if(num)//开启冒号
    {
    
    
        SMG_3_OPEN;
        SMG_4_OPEN;
        SMG_A_CLOSE;
        SMG_B_CLOSE;
        SMG_C_CLOSE;
        SMG_D_CLOSE;
        SMG_E_CLOSE;
        SMG_F_CLOSE;
        SMG_G_CLOSE;
        SMG_DP_OPEN;


    }
    else
    {
    
    
        SMG_3_CLOSE;
        SMG_4_CLOSE;

        SMG_A_CLOSE;
        SMG_B_CLOSE;
        SMG_C_CLOSE;
        SMG_D_CLOSE;
        SMG_E_CLOSE;
        SMG_F_CLOSE;
        SMG_G_CLOSE;
        SMG_DP_CLOSE;

    }
}

void ceshi_smg(void)
{
    
    
    for(int i=0;i<40;i++)
    {
    
    
        if(i<10)
        {
    
       smg_1(i);}

        else if(i>=10&&i<20)
        {
    
        smg_2(i-10);}

        else if(i>=20&&i<30)
        {
    
        smg_3(i-20);}

        else if(i>=30&&i<40)
        {
    
       smg_4(i-30);}


        R_BSP_SoftwareDelay(100U, BSP_DELAY_UNITS_MILLISECONDS);
    }
     smg_maohao_open(1);





}

smg.h

/*aa
 *
 *  Created on: 2023年6月29日
 *      Author: a8456
 */

#ifndef SMG_H_
#define SMG_H_
#define SMG_A_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_HIGH)
#define SMG_B_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_05_PIN_00, BSP_IO_LEVEL_HIGH)
#define SMG_C_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_02_PIN_13, BSP_IO_LEVEL_HIGH)
#define SMG_D_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_08, BSP_IO_LEVEL_HIGH)
#define SMG_E_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_07, BSP_IO_LEVEL_HIGH)
#define SMG_F_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_02, BSP_IO_LEVEL_HIGH)
//旧版PCB
//#define SMG_G_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_HIGH)
//新版PCB
#define SMG_G_OPEN  R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, BSP_IO_LEVEL_HIGH)
#define SMG_DP_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_02_PIN_12, BSP_IO_LEVEL_HIGH)


#define SMG_A_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_LOW)
#define SMG_B_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_05_PIN_00, BSP_IO_LEVEL_LOW)
#define SMG_C_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_02_PIN_13, BSP_IO_LEVEL_LOW)
#define SMG_D_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_08, BSP_IO_LEVEL_LOW)
#define SMG_E_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_07, BSP_IO_LEVEL_LOW)
#define SMG_F_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_02, BSP_IO_LEVEL_LOW)
//旧版PCB
//#define SMG_G_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_LOW)
//新版PCB
#define SMG_G_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, BSP_IO_LEVEL_LOW)
#define SMG_DP_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_02_PIN_12, BSP_IO_LEVEL_LOW)

#define SMG_1_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_04, BSP_IO_LEVEL_LOW)
#define SMG_2_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_01, BSP_IO_LEVEL_LOW)
#define SMG_3_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_00, BSP_IO_LEVEL_LOW)
//旧版PCB
//#define SMG_4_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, BSP_IO_LEVEL_LOW)
//新版PCB
#define SMG_4_OPEN R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_LOW)


#define SMG_1_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_04, BSP_IO_LEVEL_HIGH)
#define SMG_2_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_01, BSP_IO_LEVEL_HIGH)
#define SMG_3_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_00, BSP_IO_LEVEL_HIGH)
//旧版PCB
//#define SMG_4_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, BSP_IO_LEVEL_HIGH)
//新版PCB
#define SMG_4_CLOSE R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_HIGH)


void smg_num(int num);

void smg_1(int num);
void smg_2(int num);
void smg_3(int num);
void smg_4(int num);

void smg_1_p(void);


void smg_1_close(void);
void smg_2_close(void);
void smg_3_close(void);
void smg_4_close(void);
void smg_maohao_open(int num);

void ceshi_smg(void);
#endif /* SMG_H_ */

Import the file just now.
insert image description here
insert image description here

After adding, you need to add the corresponding header file to the main program.

#include "smg.h"

insert image description here

Add a test program.
insert image description here

main program

#include "hal_data.h"
#include <stdio.h>
#include "smg.h"
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER

fsp_err_t err = FSP_SUCCESS;
volatile bool uart_send_complete_flag = false;
/* Callback function */
void user_uart_callback(uart_callback_args_t *p_args)
{
    
    
    /* TODO: add your own code here */
    if(p_args->event == UART_EVENT_TX_COMPLETE)
     {
    
    
         uart_send_complete_flag = true;
     }
}


#ifdef __GNUC__                                 //串口重定向
    #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
    #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{
    
    
        err = R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);
        if(FSP_SUCCESS != err) __BKPT();
        while(uart_send_complete_flag == false){
    
    }
        uart_send_complete_flag = false;
        return ch;
}

int _write(int fd,char *pBuffer,int size)
{
    
    
    for(int i=0;i<size;i++)
    {
    
    
        __io_putchar(*pBuffer++);
    }
    return size;
}



/*******************************************************************************************************************//**
 * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
 * is called by main() when no RTOS is used.
 **********************************************************************************************************************/
void hal_entry(void)
{
    
    
    /* TODO: add your own code here */

/**********************串口设置***************************************/
    /* Open the transfer instance with initial configuration. */
       err = R_SCI_UART_Open(&g_uart9_ctrl, &g_uart9_cfg);
       assert(FSP_SUCCESS == err);

/**********************数码管测试***************************************/
       ceshi_smg();

       while(1)
       {
    
    
       printf("hello world!\n");
       R_BSP_SoftwareDelay(1000U, BSP_DELAY_UNITS_MILLISECONDS);
       }



#if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
#endif
}

Join the test program for the digital tube.

Guess you like

Origin blog.csdn.net/qq_24312945/article/details/132010734