本帖最后由 xcc521 于 2021-1-11 14:45 编辑
如下图,可以在任何界面显示任意大小的数码管字体,支持有效及无效部分的空心及实心绘制,可以自定义数码管体宽度及尺寸坐标等
下图均来源于开发板截图
使用非常简单,现已集成到开发板
首先自己实现画线函数
void Draw_Line(unsigned short xs,unsigned short ys,unsigned char xe,unsigned short ye,unsigned short color)
{
POINT_COLOR = color;
LCD_DrawLine(xs,ys,xe,ye);
}
#ifndef __DIGITAL_LED_H
#define __DIGITAL_LED_H
typedef struct
{
unsigned char (*IF_DrawLine)(unsigned short xs,unsigned short ys,unsigned short xe,unsigned short ye); //IO初始化函数
void (*Digital_Draw_Line)(unsigned short xs,unsigned short ys,unsigned short xe,unsigned short ye,unsigned short color);
}_Draw_Str;
extern unsigned short DIGITAL_COLOR_FRONT;
extern unsigned short DIGITAL_COLOR_FRONT_EMP;
extern unsigned short DIGITAL_COLOR_BACK;
extern _Draw_Str draw_str;
extern unsigned short DIGITAL_POINT_COLOR;
void Draw_Digital_num(unsigned short x,unsigned short y,unsigned char lw,unsigned short w,unsigned short h,unsigned char num,unsigned char fill);
/**
*起始坐标XY,数码管段线宽,显示大小宽高,显示的数字
*mode :bit7 是否填充主显示段,bit6 是否填充副显示段,bit5 是否显示副显示段 bit4 增强使能,即强制划断数码管段之间的联系
*/
void Digital_Draw_num(unsigned short x,unsigned short y,unsigned char lw,unsigned short w,unsigned short h,unsigned char num,unsigned char mode);
#endif
根据头文件使用函数
draw_str.IF_DrawLine = (void *)LCD_DrawLine;//旧接口可以不写
DIGITAL_COLOR_BACK = BLACK;
DIGITAL_COLOR_FRONT = RED;
DIGITAL_COLOR_FRONT_EMP = WHITE;
draw_str.Digital_Draw_Line = (void *)Draw_Line;
例如
Digital_Draw_num(20,20,75,440,760,6,0x90);
在20,20位置显示宽度为75的440宽760高的数码管字体6
主函数
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "digital_led.h"
//ALIENTEK战舰STM32开发板实验13
//TFTLCD显示 实验
//技术支持:www.openedv.com
//广州市星翼电子科技有限公司
void Draw_Line(unsigned short xs,unsigned short ys,unsigned char xe,unsigned short ye,unsigned short color)
{
POINT_COLOR = color;
LCD_DrawLine(xs,ys,xe,ye);
}
int main(void)
{
u8 lcd_id[12]; //存放LCD ID字符串
Stm32_Clock_Init(9); //系统时钟设置
uart_init(72,115200); //串口初始化为115200
delay_init(72); //延时初始化
LED_Init(); //初始化与LED连接的硬件接口
LCD_Init();
POINT_COLOR=RED;
sprintf((char*)lcd_id,"LCD ID:%04X",lcddev.id);//将LCD ID打印到lcd_id数组。
LCD_ShowString(30,40,210,24,24,"WarShip STM32 ^_^");
LCD_ShowString(30,70,200,16,16,"TFTLCD TEST");
draw_str.IF_DrawLine = (void *)LCD_DrawLine;
DIGITAL_COLOR_BACK = BLACK;
DIGITAL_COLOR_FRONT = RED;
DIGITAL_COLOR_FRONT_EMP = WHITE;
draw_str.Digital_Draw_Line = (void *)Draw_Line;
if(1)
{
int stp;
for(stp=0;stp<32;stp++)
{
//Draw_Digital_num(20,20,20,120,300,stp,0);
Digital_Draw_num(20,0,10,120,180,stp++%16,0x00);
Digital_Draw_num(20,200,15,120,180,stp++%16,0x20);
//Digital_Draw_num(20,400,10,120,180,stp%16,0x40);
Digital_Draw_num(20,400,20,120,180,stp++%16,0x90);
Digital_Draw_num(20,600,25,120,180,stp++%16,0x60);
Digital_Draw_num(260,0,10,120,180,stp++%16,0x80);
Digital_Draw_num(260,200,10,120,180,stp++%16,0xA0);
//Digital_Draw_num(260,400,10,120,180,stp%16,0xC0);
Digital_Draw_num(260,400,10,120,180,stp++%16,0xF0);
Digital_Draw_num(260,600,10,120,180,stp++%16,0xE0);
delay_ms(1200);
LCD_Clear(BLACK);stp -= 8;
}
for(stp=0;stp<32;stp++)
{
Digital_Draw_num(20,20,75,440,760,stp%16,0x90);
delay_ms(1200);delay_ms(1200);delay_ms(1200);
LCD_Clear(BLACK);
}
}
while(1)
{
LED0=!LED0;
LED1=!LED1;
delay_ms(100);
}
}
效果:https://www.bilibili.com/video/BV1eb411M7Rv
精英战舰代码如下
数码管显示实验.zip
(204.14 KB, 下载次数: 153)
|