885|2

410

帖子

3

TA的资源

纯净的硅(高级)

楼主
 

【CW32L052测评】 段码LCD显示屏计数测试 [复制链接]

 

这篇来测试板子上的段码显示屏,显示计数操作。

 

一、硬件部分

1.1、段码LCD显示屏部分电路图

 

1.2、LCD的显示寄存器

 

在例程的基础上,修改LCD屏的驱动函数,没有段码屏的资料,按照例程一点点修改显示寄存器的值测试对应的段位

 

 

二、程序

 

2.1、fun_lcd.c

/**
 * [url=home.php?mod=space&uid=1307177]@File[/url]  cw32l052_lcd.c
 * [url=home.php?mod=space&uid=1315547]@author[/url]  WHXY
 * [url=home.php?mod=space&uid=159083]@brief[/url]  * [url=home.php?mod=space&uid=252314]@version[/url]  0.1
 * [url=home.php?mod=space&uid=311857]@date[/url]  2022-01-20
 *
 * @copyright Copyright (c) 2022
 *
 */

/* Includes ------------------------------------------------------------------*/
#include "cw32l052_lcd.h"
#include "cw32l052_rcc.h"


/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/**
 * @brief  LCD ????,?LCD????????????
 * @param  None
 * @retval None
 */
void LCD_DeInit(void)
{
    /* Enable LCD reset state */
    CW_SYSCTRL->APBRST1_f.LCD = 0;
    /* Release LCD from reset state */
    CW_SYSCTRL->APBRST1_f.LCD = 1;

}

/**
 * @brief ???LCD???
 *
 * @param LCD_InitStruct LCD?????????
 */
void LCD_Init(LCD_InitTypeDef* LCD_InitStruct)
{
    /* Check function parameters */
    assert_param(IS_LCD_CLOCK(LCD_InitStruct->LCD_ClockSource));
    assert_param(IS_LCD_DUTY(LCD_InitStruct->LCD_Duty));
    assert_param(IS_LCD_BIAS(LCD_InitStruct->LCD_Bias));
    assert_param(IS_LCD_VOLTAGE_SOURCE(LCD_InitStruct->LCD_VoltageSource));
    assert_param(IS_LCD_SCAN_FREQ(LCD_InitStruct->LCD_ScanFreq));

    CW_LCD->CR0 = (CW_LCD->CR0 & (~(LCD_CR0_INRS_Msk | LCD_CR0_DUTY_Msk | LCD_CR0_BIAS_Msk))) | \
                  (LCD_InitStruct->LCD_VoltageSource | LCD_InitStruct->LCD_Duty | LCD_InitStruct->LCD_Bias);
    CW_LCD->CR1 = (CW_LCD->CR1 & (~(LCD_CR1_LCDFS_Msk | LCD_CR1_CLKCS_Msk))) | \
                  (LCD_InitStruct->LCD_ScanFreq | LCD_InitStruct->LCD_ClockSource);
}


/**
 * @brief ?????LCD???
 *
 * @param NewState DISABLE ENABLE
 */
void LCD_Cmd(FunctionalState NewState)
{
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    CW_LCD->CR0_f.EN = (uint32_t)NewState;
}

/**
 * @brief ??LCD??????,??Bias????????????,???
 *
 * @param LCD_ContrastLevel LCD_Contrast_Level_0~LCD_Contrast_Level_15
 *                          LCD_Contrast_Level_0?????
 *                          LCD_Contrast_Level_15?????
 */
void LCD_ContrastConfig(uint32_t LCD_ContrastLevel)
{
    assert_param(IS_LCD_CONTRAST(LCD_ContrastLevel));

    CW_LCD->CR0_f.CONTRAST = LCD_ContrastLevel;
}

/**
 * @brief ??LCD?????,??LCD Bias????????????
 *
 * @param LCD_INRS_Level LCD_INRS_LEVEL_0~LCD_INRS_LEVEL_3
 *                       LCD_INRS_LEVEL_0 ??????,????
 *                       LCD_INRS_LEVEL_3 ??????,????
 */
void LCD_DriveVoltageConfig(uint32_t LCD_INRS_Level)
{
    assert_param(IS_LCD_INRS(LCD_INRS_Level));

    CW_LCD->CR0_f.INRS = LCD_INRS_Level;
}

/**
 * @brief Bias??????????,???????????
 *
 * @param NewState ENABLE DISABLE
 */
void LCD_ChargeBumpCmd(FunctionalState NewState)
{
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    CW_LCD->CR0_f.BUMP = (uint32_t)NewState;
}

/**
 * @brief ??????????
 *
 * @param LCD_ChargeClock LCD_CHARGER_CLOCK_2KHZ LCD_CHARGER_CLOCK_4KHZ
 *                        LCD_CHARGER_CLOCK_8KHZ LCD_CHARGER_CLOCK_16KHZ
 */
void LCD_ChargeClockConfig(uint32_t LCD_ChargeClock)
{
    assert_param(IS_LCD_CHARGE_CLOCK(LCD_ChargeClock));

    CW_LCD->CR0_f.CPCLK = LCD_ChargeClock;
}

/**
 * @brief ?????LCD????DMA???
 *
 * @param NewState ENABLE DISABLE
 */
void LCD_DMACmd(FunctionalState NewState)
{
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    CW_LCD->CR1_f.DMAEN = (uint32_t)NewState;
}

/**
 * @brief ??LCD?????
 *
 * @param LCD_ScanFreq LCD_SCAN_FREQ_64HZ LCD_SCAN_FREQ_128HZ LCD_SCAN_FREQ_256HZ LCD_SCAN_FREQ_512HZ
 */
void LCD_ScanFreqConfig(uint32_t LCD_ScanFreq)
{
    assert_param(IS_LCD_SCAN_FREQ(LCD_ScanFreq));

    REGBITS_MODIFY(CW_LCD->CR1, LCD_CR1_LCDFS_Msk, LCD_ScanFreq);
}

/**
 * @brief ??LCD??????
 *
 * @param LCD_ClockSource LCD_CLOCK_SOURCE_LSI ????RC??
 *                        LCD_CLOCK_SOURCE_LSE ??????
 */
void LCD_ClockSourceConfig(uint32_t LCD_ClockSource)
{
    assert_param(IS_LCD_CLOCK(LCD_ClockSource));

    REGBITS_MODIFY(CW_LCD->CR1, LCD_CR1_CLKCS_Msk, LCD_ClockSource);
}


/**
* @brief LCD????????????,????????????????
*
* @param LCD_IntDuration ????0~63
*/
void LCD_IntOrBlinkDurationConfig(uint32_t LCD_Duration)
{
    /* Check the parameters */
    assert_param(IS_LCD_INT_DURATION(LCD_Duration));

    CW_LCD->CR1_f.BLINKCNT = LCD_Duration;
}

/**
 * @brief LCD??????????
 *
 * @param NewState ENABLE DISABLE
 */
void LCD_BlinkCmd(FunctionalState NewState)
{
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    CW_LCD->CR1_f.BLINKEN = (uint32_t)NewState;
}

/**
 * @brief ?LCD?RAM???,?1?bit COM?SEG?????,?0?bit COM?SEG?????
 *
 * @param LCD_RAMRegister LCD_RAMRegister_0~LCD_RAMRegister_13
 * @param LCD_Data
 */
void LCD_Write(uint32_t LCD_RAMRegister, uint32_t LCD_Data)
{
    /* Check the parameters */
    assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister));

    /* Copy data bytes to RAM register */

    CW_LCD->RAM[LCD_RAMRegister] = (uint32_t)LCD_Data;
}


/**
 * @brief ?????LCD???
 *
 * @param NewState ENABLE DISABLE
 */
void LCD_ITCmd(FunctionalState NewState)
{
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    CW_LCD->CR1_f.IE = (uint32_t)NewState;

}

/**
 * @brief ??LCD???????
 *
 * [url=home.php?mod=space&uid=784970]@return[/url]  ITStatus
 */
ITStatus LCD_GetITStatus(void)
{
    return (CW_LCD->CR1 & LCD_CR1_INTF_Msk) ? SET : RESET;
}

/**
 * @brief ??LCD???????
 *
 */
void LCD_ClearITPendingBit(void)
{
    CW_LCD->ICR_f.INTF = 0;
}

/**
 * @brief ??COM????????
 *
 * @param LCD_COM_x LCD_COM0~LCD_COM7 ????????????COM
 */
void LCD_COMConfig(uint32_t LCD_COM_x, FunctionalState NewState)
{
    assert_param(IS_LCD_COM(LCD_COM_x));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
    if (NewState)
    {
        CW_LCD->PINEN1 |= ((LCD_COM_x) & 0xF0000000);
        CW_LCD->PINEN2 |= ((LCD_COM_x) & 0x0F000000);
    }
    else
    {
        CW_LCD->PINEN1 &= ~((LCD_COM_x) & 0xF0000000);
        CW_LCD->PINEN2 &= ~((LCD_COM_x) & 0x0F000000);
    }
}

/**
 * @brief ??SEG0~23?????
 *
 * @param LCD_SEG_x  LCD_SEG0~LCD_SEG23 ????????????SEG
 * @param NewState ENABLE DISABLE
 */
void LCD_SEG0to23Config(uint32_t LCD_SEG_x, FunctionalState NewState)
{
    assert_param(IS_LCD_SEGX(LCD_SEG_x));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
    if (NewState)
    {
        CW_LCD->PINEN1 |= ((LCD_SEG_x) & 0x00FFFFFF);
    }
    else
    {
        CW_LCD->PINEN1 &= ~((LCD_SEG_x) & 0x00FFFFFF);
    }
}

/**
 * @brief ??SEG32~55?????
 *
 * @param LCD_SEG_y LCD_SEG32~LCD_SEG55 ????????????SEG
 * @param NewState ENABLE DISABLE
 */
void LCD_SEG32to55Config(uint32_t LCD_SEG_y, FunctionalState NewState)
{
    assert_param(IS_LCD_SEGY(LCD_SEG_y));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
    if (NewState)
    {
        CW_LCD->PINEN2 |= ((LCD_SEG_y) & 0x00FFFFFF);
    }
    else
    {
        CW_LCD->PINEN2 &= ~((LCD_SEG_y) & 0x00FFFFFF);
    }
}


/**
 * @brief ??SEG24~27?????
 *
 * @param LCD_SEG_v  LCD_SEG24~LCD_SEG27 ????????????SEG
 * @param NewState ENABLE DISABLE
 */
void LCD_SEG24to27Config(uint32_t LCD_SEG_v, FunctionalState NewState)
{
    assert_param(IS_LCD_SEGV(LCD_SEG_v));
    assert_param(IS_FUNCTIONAL_STATE(NewState));

    if (NewState)
    {
        CW_LCD->PINEN2_f.MUX = 1;
        CW_LCD->PINEN1 |= ((LCD_SEG_v) & 0x0F000000);
    }
    else
    {
        CW_LCD->PINEN1 &= ~((LCD_SEG_v) & 0x0F000000);
        if ((CW_LCD->PINEN1 & 0x0F000000) == 0x00)
        {
            CW_LCD->PINEN2_f.MUX = 0;
        }
    }
}

void LCD_Configuration(void)
{
    LCD_InitTypeDef LCD_InitStruct = {0};

    LCD_InitStruct.LCD_Bias = LCD_Bias_1_3;
    LCD_InitStruct.LCD_ClockSource = LCD_CLOCK_SOURCE_LSI;
    LCD_InitStruct.LCD_Duty = LCD_Duty_1_4;
    LCD_InitStruct.LCD_ScanFreq = LCD_SCAN_FREQ_256HZ;
    LCD_InitStruct.LCD_VoltageSource = LCD_VoltageSource_Internal;

    LCD_Init(&LCD_InitStruct); 
		LCD_COMConfig(LCD_COM0 | LCD_COM1 | LCD_COM2 | LCD_COM3, ENABLE);
    LCD_SEG0to23Config(LCD_SEG0|LCD_SEG1|LCD_SEG2|LCD_SEG3|LCD_SEG4|LCD_SEG5|LCD_SEG6|LCD_SEG7|LCD_SEG8|LCD_SEG9|LCD_SEG10|LCD_SEG13|LCD_SEG14|LCD_SEG15|LCD_SEG16|LCD_SEG17, ENABLE);
   
		LCD_Cmd(ENABLE);
		
		LCD_Write(LCD_RAMRegister_0, 0xFFFFFFFF);
		LCD_Write(LCD_RAMRegister_1, 0xFFFFFFFF);
		LCD_Write(LCD_RAMRegister_2, 0xFFFFFFFF);
		LCD_Write(LCD_RAMRegister_3, 0xFFFFFFFF);
		LCD_Write(LCD_RAMRegister_4, 0xFFFFFFFF);
		
}

void lcd_disp(uint8_t *dp)
{
	uint32_t  dp_temp;
	dp_temp=0;
	dp_temp|=((dp[6]&0xf0)<<20)|((dp[6]&0x0f)<<16)|((dp[7]&0xf0)<<4)|(dp[7]&0x0f);
	LCD_Write(LCD_RAMRegister_0, dp_temp);
	dp_temp=0;
	dp_temp|=((dp[4]&0xf0)<<20)|((dp[4]&0x0f)<<16)|((dp[5]&0xf0)<<4)|(dp[5]&0x0f);
	LCD_Write(LCD_RAMRegister_1, dp_temp);
	dp_temp=0;
	dp_temp|=((dp[2]&0x0f)<<16)|((dp[3]&0xf0)<<4)|(dp[3]&0x0f);
	LCD_Write(LCD_RAMRegister_2, dp_temp);
	dp_temp=0;
	dp_temp|=((dp[2]&0xf0)<<4)|((dp[1]&0xf0)<<20)|((dp[1]&0x0f)<<16);
	LCD_Write(LCD_RAMRegister_3, dp_temp);
	dp_temp=0;
	dp_temp|=((dp[0]&0xf0)<<4)|(dp[0]&0x0f);
	LCD_Write(LCD_RAMRegister_4, dp_temp);	
}


/************************ END OF FILE************************/

 

2.2、fun_lcd.h

#ifndef __FUN_LCD_H
#define __FUN_LCD_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "cw32l052.h"
#include "base_types.h"


/* Exported types ------------------------------------------------------------*/

/**
 * @brief  LCD Init structure definition
 */

typedef struct
{
    uint32_t LCD_ClockSource;
    uint32_t LCD_ScanFreq;
    uint32_t LCD_Duty;
    uint32_t LCD_Bias;
    uint32_t LCD_VoltageSource;
} LCD_InitTypeDef;


/* Exported constants --------------------------------------------------------*/
/******** LCD CR0 ********/

/**
 * @brief ??????????
 *
 */
#define LCD_Contrast_Level_0               ((uint32_t)0x00000000) /*!< ????? */
#define LCD_Contrast_Level_1               ((uint32_t)0x00000001) /*!<  */
#define LCD_Contrast_Level_2               ((uint32_t)0x00000002) /*!<    */
#define LCD_Contrast_Level_3               ((uint32_t)0x00000003) /*!<    */
#define LCD_Contrast_Level_4               ((uint32_t)0x00000004) /*!<    */
#define LCD_Contrast_Level_5               ((uint32_t)0x00000005) /*!<    */
#define LCD_Contrast_Level_6               ((uint32_t)0x00000006) /*!<    */
#define LCD_Contrast_Level_7               ((uint32_t)0x00000007)
#define LCD_Contrast_Level_8               ((uint32_t)0x00000008)
#define LCD_Contrast_Level_9               ((uint32_t)0x00000009)
#define LCD_Contrast_Level_10              ((uint32_t)0x0000000A)
#define LCD_Contrast_Level_11              ((uint32_t)0x0000000B)
#define LCD_Contrast_Level_12              ((uint32_t)0x0000000C)
#define LCD_Contrast_Level_13              ((uint32_t)0x0000000D)
#define LCD_Contrast_Level_14              ((uint32_t)0x0000000E)
#define LCD_Contrast_Level_15              ((uint32_t)0x0000000F) /*!< ????? */

#define IS_LCD_CONTRAST(CONTRAST)          ((CONTRAST) < 0x00000010)

/**
 * @brief ?????????
 *
 */
#define LCD_INRS_LEVEL_0                   (((uint32_t)0x00000004))   /*!< ???? */
#define LCD_INRS_LEVEL_1                   (((uint32_t)0x00000002))   /*!< ???? */
#define LCD_INRS_LEVEL_2                   (((uint32_t)0x00000001))   /*!< ???? */
#define LCD_INRS_LEVEL_3                   (((uint32_t)0x00000007))   /*!< ???? */
#define IS_LCD_INRS(INRS)                  (((INRS) == LCD_INRS_LEVEL_0) || \
                                           ((INRS) == LCD_INRS_LEVEL_1) || \
                                           ((INRS) == LCD_INRS_LEVEL_2) || \
                                           ((INRS) == LCD_INRS_LEVEL_3))
/**
* @brief LCD_Voltage_Source
*
*/

#define LCD_VoltageSource_Internal         (((uint32_t)0x00000001) << 9) /*!< Internal voltage source for the LCD */
#define LCD_VoltageSource_External         ((uint32_t)0x00000000)    /*!< External voltage source for the LCD */

#define IS_LCD_VOLTAGE_SOURCE(SOURCE)      (((SOURCE) == LCD_VoltageSource_Internal) || \
                                           ((SOURCE) == LCD_VoltageSource_External))

/**
 * @brief LCD_Duty
 *
 */
#define LCD_Duty_Static                    ((uint32_t)0x00000000)        /*!< Static duty */
#define LCD_Duty_1_2                       (((uint32_t)0x00000001) << 6) /*!< 1/2 duty    */
#define LCD_Duty_1_3                       (((uint32_t)0x00000002) << 6) /*!< 1/3 duty    */
#define LCD_Duty_1_4                       (((uint32_t)0x00000003) << 6) /*!< 1/4 duty    */
#define LCD_Duty_1_6                       (((uint32_t)0x00000005) << 6) /*!< 1/6 duty    */
#define LCD_Duty_1_8                       (((uint32_t)0x00000007) << 6) /*!< 1/8 duty    */

#define IS_LCD_DUTY(DUTY)                  (((DUTY) == LCD_Duty_Static) || \
                                           ((DUTY) == LCD_Duty_1_2) || \
                                           ((DUTY) == LCD_Duty_1_3) || \
                                           ((DUTY) == LCD_Duty_1_4) || \
                                           ((DUTY) == LCD_Duty_1_6) || \
                                           ((DUTY) == LCD_Duty_1_8))

/**
 * @brief LCD_Bias
 *
 */
#define LCD_Bias_1_2                       ((uint32_t)0x00000010)         /*!< 1/2 Bias */
#define LCD_Bias_1_3                       ((uint32_t)0x00000000)         /*!< 1/3 Bias */

#define IS_LCD_BIAS(BIAS)                  (((BIAS) == LCD_Bias_1_2) || \
                                           ((BIAS) == LCD_Bias_1_3))

#define LCD_BUMP_ENABLE                    (((uint32_t)0x00000001) << 3)
#define LCD_BUMP_DISABLE                   ((uint32_t)0x00000000)

#define LCD_CHARGER_CLOCK_2KHZ             ((uint32_t)0x00000000)
#define LCD_CHARGER_CLOCK_4KHZ             (((uint32_t)0x00000001))
#define LCD_CHARGER_CLOCK_8KHZ             (((uint32_t)0x00000002))
#define LCD_CHARGER_CLOCK_16KHZ            (((uint32_t)0x00000003))
#define IS_LCD_CHARGE_CLOCK(CLOCK)         (((CLOCK) == LCD_CHARGER_CLOCK_2KHZ) || \
                                           ((CLOCK) == LCD_CHARGER_CLOCK_4KHZ) || \
                                           ((CLOCK) == LCD_CHARGER_CLOCK_8KHZ) || \
                                           ((CLOCK) == LCD_CHARGER_CLOCK_16KHZ) )

/******** LCD CR1 ********/

#define LCD_SCAN_FREQ_64HZ                 (((uint32_t)0x00000003) << 8)
#define LCD_SCAN_FREQ_128HZ                ((uint32_t)0x00000000)
#define LCD_SCAN_FREQ_256HZ                (((uint32_t)0x00000001) << 8)
#define LCD_SCAN_FREQ_512HZ                (((uint32_t)0x00000002) << 8)
#define IS_LCD_SCAN_FREQ(FREQ)             (((FREQ) == LCD_SCAN_FREQ_64HZ) || \
                                           ((FREQ) == LCD_SCAN_FREQ_128HZ) || \
                                           ((FREQ) == LCD_SCAN_FREQ_256HZ) || \
                                           ((FREQ) == LCD_SCAN_FREQ_512HZ))

#define LCD_CLOCK_SOURCE_LSI               ((uint32_t)0x00000000)
#define LCD_CLOCK_SOURCE_LSE               (((uint32_t)0x00000001) << 7)
#define IS_LCD_CLOCK(CLOCK)                (((CLOCK) == LCD_CLOCK_SOURCE_LSI) || \
                                           ((CLOCK) == LCD_CLOCK_SOURCE_LSE))


/** @defgroup LCD_BlinkMode
* @{
*/

#define LCD_BlinkMode_Off                  ((uint32_t)0x00000000)        /*!< Blink disabled            */
#define LCD_BlinkMode_On                   (((uint32_t)0x00000001) << 6) /*!< Blink disabled            */

#define IS_LCD_INT_DURATION(DURATION)      ((DURATION) < 64)


#define LCD_RAMRegister_0                  ((uint32_t)0x00000000) /*!< LCD RAM Register 0  */
#define LCD_RAMRegister_1                  ((uint32_t)0x00000001) /*!< LCD RAM Register 1  */
#define LCD_RAMRegister_2                  ((uint32_t)0x00000002) /*!< LCD RAM Register 2  */
#define LCD_RAMRegister_3                  ((uint32_t)0x00000003) /*!< LCD RAM Register 3  */
#define LCD_RAMRegister_4                  ((uint32_t)0x00000004) /*!< LCD RAM Register 4  */
#define LCD_RAMRegister_5                  ((uint32_t)0x00000005) /*!< LCD RAM Register 5  */
#define LCD_RAMRegister_6                  ((uint32_t)0x00000006) /*!< LCD RAM Register 6  */
#define LCD_RAMRegister_7                  ((uint32_t)0x00000007) /*!< LCD RAM Register 7  */
#define LCD_RAMRegister_8                  ((uint32_t)0x00000008) /*!< LCD RAM Register 8  */
#define LCD_RAMRegister_9                  ((uint32_t)0x00000009) /*!< LCD RAM Register 9  */
#define LCD_RAMRegister_10                 ((uint32_t)0x0000000A) /*!< LCD RAM Register 10 */
#define LCD_RAMRegister_11                 ((uint32_t)0x0000000B) /*!< LCD RAM Register 11 */
#define LCD_RAMRegister_12                 ((uint32_t)0x0000000C) /*!< LCD RAM Register 12 */
#define LCD_RAMRegister_13                 ((uint32_t)0x0000000D) /*!< LCD RAM Register 13 */

#define IS_LCD_RAM_REGISTER(REGISTER)      (((REGISTER) == LCD_RAMRegister_0) || \
                                           ((REGISTER) == LCD_RAMRegister_1) || \
                                           ((REGISTER) == LCD_RAMRegister_2) || \
                                           ((REGISTER) == LCD_RAMRegister_3) || \
                                           ((REGISTER) == LCD_RAMRegister_4) || \
                                           ((REGISTER) == LCD_RAMRegister_5) || \
                                           ((REGISTER) == LCD_RAMRegister_6) || \
                                           ((REGISTER) == LCD_RAMRegister_7) || \
                                           ((REGISTER) == LCD_RAMRegister_8) || \
                                           ((REGISTER) == LCD_RAMRegister_9) || \
                                           ((REGISTER) == LCD_RAMRegister_10) || \
                                           ((REGISTER) == LCD_RAMRegister_11) || \
                                           ((REGISTER) == LCD_RAMRegister_12) || \
                                           ((REGISTER) == LCD_RAMRegister_13) )

#define LCD_FLAG_INTF                      (((uint32_t) 0x00000001) << 12)
#define IS_LCD_GET_FLAG(LCD_FLAG)          ((LCD_FLAG) == LCD_FLAG_INTF)
#define IS_LCD_CLEAR_FLAG(LCD_FLAG)        ((LCD_FLAG) == LCD_FLAG_INTF)

#define LCD_COM0                           (((uint32_t)0x00000001) << 24)
#define LCD_COM1                           (((uint32_t)0x00000001) << 25)
#define LCD_COM2                           (((uint32_t)0x00000001) << 26)
#define LCD_COM3                           (((uint32_t)0x00000001) << 27)
#define LCD_COM4                           (((uint32_t)0x00000001) << 28)
#define LCD_COM5                           (((uint32_t)0x00000001) << 29)
#define LCD_COM6                           (((uint32_t)0x00000001) << 30)
#define LCD_COM7                           (((uint32_t)0x00000001) << 31)
#define IS_LCD_COM(COM)                    (((COM) & 0xFF000000) <= 0xFF000000)


#define LCD_SEG0                           (((uint32_t)0x00000001))
#define LCD_SEG1                           (((uint32_t)0x00000001) << 1)
#define LCD_SEG2                           (((uint32_t)0x00000001) << 2)
#define LCD_SEG3                           (((uint32_t)0x00000001) << 3)
#define LCD_SEG4                           (((uint32_t)0x00000001) << 4)
#define LCD_SEG5                           (((uint32_t)0x00000001) << 5)
#define LCD_SEG6                           (((uint32_t)0x00000001) << 6)
#define LCD_SEG7                           (((uint32_t)0x00000001) << 7)
#define LCD_SEG8                           (((uint32_t)0x00000001) << 8)
#define LCD_SEG9                           (((uint32_t)0x00000001) << 9)
#define LCD_SEG10                          (((uint32_t)0x00000001) << 10)
#define LCD_SEG11                          (((uint32_t)0x00000001) << 11)
#define LCD_SEG12                          (((uint32_t)0x00000001) << 12)
#define LCD_SEG13                          (((uint32_t)0x00000001) << 13)
#define LCD_SEG14                          (((uint32_t)0x00000001) << 14)
#define LCD_SEG15                          (((uint32_t)0x00000001) << 15)
#define LCD_SEG16                          (((uint32_t)0x00000001) << 16)
#define LCD_SEG17                          (((uint32_t)0x00000001) << 17)
#define LCD_SEG18                          (((uint32_t)0x00000001) << 18)
#define LCD_SEG19                          (((uint32_t)0x00000001) << 19)
#define LCD_SEG20                          (((uint32_t)0x00000001) << 20)
#define LCD_SEG21                          (((uint32_t)0x00000001) << 21)
#define LCD_SEG22                          (((uint32_t)0x00000001) << 22)
#define LCD_SEG23                          (((uint32_t)0x00000001) << 23)
#define IS_LCD_SEGX(SEGX)                  ((SEGX) <= 0x00FFFFFF && (SEGX) > 0x00000000)


#define LCD_SEG24                          (((uint32_t)0x00000001) << 24)
#define LCD_SEG25                          (((uint32_t)0x00000001) << 25)
#define LCD_SEG26                          (((uint32_t)0x00000001) << 26)
#define LCD_SEG27                          (((uint32_t)0x00000001) << 27)
#define IS_LCD_SEGV(SEGV)                  ((SEGV) == LCD_SEG24 ||\
                                            (SEGV) == LCD_SEG25 ||\
                                            (SEGV) == LCD_SEG26 ||\
                                            (SEGV) == LCD_SEG27)


#define LCD_SEG32                          (((uint32_t)0x00000001))
#define LCD_SEG33                          (((uint32_t)0x00000001) << 1)
#define LCD_SEG34                          (((uint32_t)0x00000001) << 2)
#define LCD_SEG35                          (((uint32_t)0x00000001) << 3)
#define LCD_SEG36                          (((uint32_t)0x00000001) << 4)
#define LCD_SEG37                          (((uint32_t)0x00000001) << 5)
#define LCD_SEG38                          (((uint32_t)0x00000001) << 6)
#define LCD_SEG39                          (((uint32_t)0x00000001) << 7)
#define LCD_SEG40                          (((uint32_t)0x00000001) << 8)
#define LCD_SEG41                          (((uint32_t)0x00000001) << 9)
#define LCD_SEG42                          (((uint32_t)0x00000001) << 10)
#define LCD_SEG43                          (((uint32_t)0x00000001) << 11)
#define LCD_SEG44                          (((uint32_t)0x00000001) << 12)
#define LCD_SEG45                          (((uint32_t)0x00000001) << 13)
#define LCD_SEG46                          (((uint32_t)0x00000001) << 14)
#define LCD_SEG47                          (((uint32_t)0x00000001) << 15)
#define LCD_SEG48                          (((uint32_t)0x00000001) << 16)
#define LCD_SEG49                          (((uint32_t)0x00000001) << 17)
#define LCD_SEG50                          (((uint32_t)0x00000001) << 18)
#define LCD_SEG51                          (((uint32_t)0x00000001) << 19)
#define LCD_SEG52                          (((uint32_t)0x00000001) << 20)
#define LCD_SEG53                          (((uint32_t)0x00000001) << 21)
#define LCD_SEG54                          (((uint32_t)0x00000001) << 22)
#define LCD_SEG55                          (((uint32_t)0x00000001) << 23)
#define IS_LCD_SEGY(SEGY)                  ((SEGY) <= 0x00FFFFFF && (SEGY) > 0x00000000)

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void LCD_DeInit(void);
void LCD_Init(LCD_InitTypeDef* LCD_InitStruct);
void LCD_Cmd(FunctionalState NewState);
void LCD_ContrastConfig(uint32_t LCD_ContrastLevel);
void LCD_DriveVoltageConfig(uint32_t LCD_INRS_Level);
void LCD_ChargeBumpCmd(FunctionalState NewState);
void LCD_ChargeClockConfig(uint32_t LCD_ChargeClock);
void LCD_DMACmd(FunctionalState NewState);
void LCD_ScanFreqConfig(uint32_t LCD_ScanFreq);
void LCD_ClockSourceConfig(uint32_t LCD_ClockSource);
void LCD_IntOrBlinkDurationConfig(uint32_t LCD_Duration);
void LCD_BlinkCmd(FunctionalState NewState);
void LCD_Write(uint32_t LCD_RAMRegister, uint32_t LCD_Data);
void LCD_ITCmd(FunctionalState NewState);
ITStatus LCD_GetITStatus(void);
void LCD_ClearITPendingBit(void);
void LCD_COMConfig(uint32_t LCD_COM_x, FunctionalState NewState);
void LCD_SEG0to23Config(uint32_t LCD_SEG_x, FunctionalState NewState);
void LCD_SEG32to55Config(uint32_t LCD_SEG_y, FunctionalState NewState);
void LCD_SEG24to27Config(uint32_t LCD_SEG_v, FunctionalState NewState);
void LCD_Configuration(void);
void lcd_disp(uint8_t *dp);

#ifdef __cplusplus
}
#endif

#endif /*__CW32L052_LCD_H */
/**
  * @}
  */

 

2.3、main.c

#include "main.h"

const uint8_t disp[10]={0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B};
const uint8_t disp_p[10]={0xFD,0xE0,0xBE,0xFA,0xE3,0xDB,0xDF,0xF0,0xFF,0xFB};

void rcc_config(void)
{
	RCC_HSI_Enable(RCC_HSIOSC_DIV2);
	RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
	RCC_PCLKPRS_Config(RCC_PCLK_DIV1);
	__RCC_FLASH_CLK_ENABLE();
  RCC_HSE_Enable(RCC_HSE_MODE_CLK,24000000,RCC_HSE_DRIVER_LEAST,RCC_HSE_FLT_OPEN);
	FLASH_SetLatency(FLASH_Latency_2);
	RCC_HSI_Enable( RCC_HSIOSC_DIV1 );
	RCC_SysClk_Switch(RCC_SYSCLKSRC_HSI);
	RCC_SystemCoreClockUpdate(48000000);
	
	__RCC_GPIOF_CLK_ENABLE();
	__RCC_GPIOE_CLK_ENABLE();
	__RCC_GPIOD_CLK_ENABLE();
	__RCC_GPIOC_CLK_ENABLE();
	__RCC_GPIOB_CLK_ENABLE();
	__RCC_GPIOA_CLK_ENABLE();
	__RCC_LCD_CLK_ENABLE();
  
  CW_SYSCTRL->AHBEN  = 0xFFFFFFFF;
  CW_SYSCTRL->APBEN1 = 0xFFFFFFFF;
  CW_SYSCTRL->APBEN2 = 0xFFFFFFFF;
}

int32_t main(void)
{
	uint8_t dp[8];
	uint8_t i=0;
	uint16_t tp=0;
	uint32_t dp1=0;
	uint32_t dp_temp=0;
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	rcc_config();
	init_uart();
	init_led();
	init_spi_flash();

	InitTick( 48000000 );                  //初始化SysTick
	LCD_Configuration();
	SPI_FLASH_Test();
	dp[0]=disp[0];
	dp[1]=disp[0];
	dp[2]=disp[0];
	dp[3]=disp[0];
	dp[4]=disp[0];
	dp[5]=disp[0];
	dp[6]=disp[0];
	dp[7]=disp[0];
		
	while (1)
	{
		if(tp>9999)
		{
			tp=0;
		}
		else
		{
			tp++;
		}
		dp[3]=disp[tp/1000];
		dp[2]=disp[((tp%1000)/100)];
		dp[1]=disp[((tp%1000)%100)/10];
		dp[0]=disp[((tp%1000)%100)%10];
		led2_tog();
		SysTickDelay(100);
		lcd_disp(dp);

	}
}

 

三、程序运行

下载程序后,运行开发板,运行视频如下:

cw32l052

 

最新回复

段式LCD看起来就有一种工业复古感。   详情 回复 发表于 2023-7-24 20:18
点赞 关注
 
 

回复
举报

1668

帖子

0

TA的资源

五彩晶圆(初级)

沙发
 

已看段码LCD显示屏计数测试视频,完美

 
 
 

回复

7452

帖子

2

TA的资源

五彩晶圆(高级)

板凳
 

段式LCD看起来就有一种工业复古感。

个人签名

默认摸鱼,再摸鱼。2022、9、28

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表