数据输出函数是通过读取字符库数组来显示字符的,其代码如下:void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
{
LCD_write_Data(font6x8[c][line]);
}
}
字符库数组的结构如下:unsigned char font6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
... ...
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
}
主函数的代码为:int main(void)
{
HAL_Init();
/* 配置系统时钟到2 MHz */
SystemClock_Config();
/* 配置LED2 */
BSP_LED_Init(LED2);
/* 配置 TIM 的外围情况 */
/* TIM2 配置: 输入捕捉模式
外部信号连接到 TIM2 的通道2 引脚为PB.03
使用上升沿触发,TIM2 的CCR2 用于 计数的频率值 */
TimHandle.Init.Period = 0xFFFF;
TimHandle.Init.Prescaler = 0;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_IC_Init(&TimHandle) != HAL_OK)
{
/* I初始化报错 */
Error_Handler();
}
/* 设置输入捕捉通道2 */
sICConfig.ICPolarity = TIM_ICPOLARITY_RISING;
sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
sICConfig.ICPrescaler = TIM_ICPSC_DIV1;
sICConfig.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIM_CHANNEL_2) != HAL_OK)
{
/* 配置报错 */
Error_Handler();
}
/* 以中断模式启动输入捕捉 */
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK)
{
/* 启动报错 */
Error_Handler();
}
LCD_Init(); // LCD5110初始化
jm(); // 显示界面
// 设置显示格式
LCD_set_XY(0,1);
LCD_write_char('C');
LCD_write_char('1');
LCD_write_char('=');
LCD_set_XY(0,2);
LCD_write_char('C');
LCD_write_char('2');
LCD_write_char('=');
LCD_set_XY(0,3);
LCD_write_char(' ');
LCD_write_char('d');
LCD_write_char('=');
LCD_set_XY(0,4);
LCD_write_char(' ');
LCD_write_char('f');
LCD_write_char('=');
while(1)
{ // 显示捕捉值
LCD_write_number(30,1,uwIC2Value1);
LCD_write_number(30,2,uwIC2Value2);
LCD_write_number(30,3,uwDiffCapture);
LCD_write_number(30,4,uwFrequency);
delay_1ms(1000); // 控制采集数据的显示间隔
}
}
|