CW32L083开发板上有8个段码LCD显示,使其显示为0-9数字。
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;
__RCC_LCD_CLK_ENABLE();
RCC_LSI_Enable();
LCD_Init(&LCD_InitStruct); //基本配置
// BTL004 LCD 对应的连接
//PA12 COM3
//PA11 COM2
//PA10 COM1
//PA09 COM0
//PA08 SEG0
//PC09 SEG1
//PC08 SEG2
//PC07 SEG3
//PC06 SEG4
//PD15 SEG32
//PD14 SEG33
//PD13 SEG34
//PD12 SEG35
//PD11 SEG36
//PD10 SEG37
//PD09 SEG38
//PD08 SEG39
//PB15 SEG5
//PB14 SEG6
//PB13 SEG7
// 分配引脚
LCD_COMConfig(LCD_COM0 | LCD_COM1 | LCD_COM2 | LCD_COM3, ENABLE);
LCD_SEG0to23Config(0x0000FF, ENABLE);
LCD_SEG32to55Config(0x0000FF,ENABLE);
CW_LCD- >RAM[0] = 0;
CW_LCD- >RAM[1] = 0;
CW_LCD- >RAM2 = 0;
CW_LCD- >RAM3 = 0;
CW_LCD- >RAM4 = 0;
CW_LCD- >RAM5 = 0;
CW_LCD- >RAM6 = 0;
CW_LCD- >RAM7 = 0;
CW_LCD- >RAM8 = 0;
CW_LCD- >RAM9 = 0;
CW_LCD- >RAM10 = 0;
CW_LCD- >RAM11 = 0;
CW_LCD- >RAM12 = 0;
CW_LCD- >RAM13 = 0;
LCD_Cmd(ENABLE);
CW_LCD- >RAM0 = 0x0f0f;
LCD_ContrastConfig(LCD_Contrast_Level_2);
LCD_DriveVoltageConfig(LCD_INRS_LEVEL_0);
}
/* 段码低8(左) */
static uint8_t num_L[10] = {
0x0d, //0
0x00, //1
0x0e, //2
0x0a, //3
0x03, //4
0x0b, //5
0x0f, //6
0x00, //7
0x0f, //8
0x0b, //9
};
/* 段码高8(右) */
static uint8_t num_H[10] = {
0x07,
0x06,
0x03,
0x07,//3
0x06,//4
0x05, //5
0x05, //
0x07, //7
0x07, //8
0x07, //9
};
void show_num(int8_t num)
{
//显示第7个数码管
CW_LCD- >RAM0 = num_H[num]< < 8 | num_L[num];
//显示第6个数码管
CW_LCD- >RAM0 |= (num_H[num]< < 8 | num_L[num]) < < 16;
//显示第5个数码管
CW_LCD- >RAM1 = num_L[num];
CW_LCD- >RAM8 = num_H[num];
//显示第4个数码管
CW_LCD- >RAM8 |= num_H[num]< < 16 | num_L[num]< < 8;
//显示第3个数码管
CW_LCD- >RAM8 |= num_L[num]< < 24;
CW_LCD- >RAM9 = num_H[num];
//显示第2个数码管
CW_LCD- >RAM9 |= num_H[num]< < 16 | num_L[num]< < 8;
//显示第1个数码管
CW_LCD- >RAM1 |= num_H[num]< < 8;
CW_LCD- >RAM9 |= num_L[num]< < 24;
//显示第0个数码管
CW_LCD- >RAM1 |= num_H[num]< < 24 | num_L[num]< < 16;
}
#include "main.h"
void RCC_Configuration(void);
int32_t main(void)
{
uint8_t i=0;
CW_SYSCTRL- >AHBEN_f.GPIOC = 1U; //Open GPIOA Clk
CW_GPIOC- >ANALOG_f.PIN2 = 0U; //Digital
CW_GPIOC- >BRR_f.BRR2 = 1U; //Reset PA00
CW_GPIOC- >DIR_f.PIN2 = 0U; //Output
RCC_Configuration();
LCD_Configuration();
while(1)
{
CW_GPIOC- >TOG = bv2;
FirmwareDelay( 8000000 );
//从零显示到8
show_num(i);
i++;
if(i==10)
i=0;
}
}
void RCC_Configuration(void)
{
/* 0. HSI使能并校准 */
// RCC_HSI_OUT();
RCC_HSI_Enable(RCC_HSIOSC_DIV6);
/* 1. 设置HCLK和PCLK的分频系数 */
RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
RCC_PCLKPRS_Config(RCC_PCLK_DIV1);
// RCC_HCLK_OUT();
// __breakpoint(0);
/* 2. 使能PLL,通过HSI倍频到64MHz */
RCC_PLL_Enable(RCC_PLLSOURCE_HSI, 8000000, RCC_PLL_MUL_8); // HSI 默认输出频率8MHz
// RCC_PLL_OUT();
///< 当使用的时钟源HCLK大于24M,小于等于48MHz:设置FLASH 读等待周期为2 cycle
///< 当使用的时钟源HCLK大于48M,小于等于72MHz:设置FLASH 读等待周期为3 cycle
__RCC_FLASH_CLK_ENABLE();
FLASH_SetLatency(FLASH_Latency_3);
/* 3. 时钟切换到PLL */
RCC_SysClk_Switch(RCC_SYSCLKSRC_PLL);
RCC_SystemCoreClockUpdate(64000000);
/* 4. 配置外设时钟 */
// __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();
}
下载到开发板后就可以周期的全屏显示0-9的数字了。
全部0条评论
快来发表一下你的评论吧 !