本帖最后由 jinglixixi 于 2022-11-28 17:58 编辑
#申请原创#
EVB-L0130开发板上,最直观的显示器件是LCD屏。但在官方的例程中却并没有直接给出一个可供调用的显示函数,所提供的只是一个点亮各笔段的演示程序,要实现数据的显示功能,只有自己动手去解决了。 该显示屏的显示面板如图1所示,但从点亮笔段的演示中可以发现并不是所有的笔段都能点亮的。
图1 显示面板 此外,通过实测该LCD屏的相关资料介绍与实际情况也是存在出入的,见表1和表2所示。 表1 相关资料的内容 表2 实测的内容 为获得表2的内容,可通过如下的程序来实现: int main(void)
{
BOARD_Init();
app_slcd_init();
GPIO_Init_Type gpio_init;
gpio_init.Pins = GPIO_PIN_5;
gpio_init.PinMode = GPIO_PinMode_In_PullUp;
gpio_init.Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &gpio_init);
app_slcd_display();
while(1);
}
void app_slcd_display(void)
{
uint32_t p;
p=1;
while(1)
{
/* Clear all segment bits. */
SLCD_ClearAllSegBits(BOARD_SLCD_PORT);
for (uint32_t com_x = 0u; com_x < BOARD_SLCD_COM_NUM; com_x++)
{
app_slcd_seg_bits[0u] = 0u;
app_slcd_seg_bits[1u] = 0u;
for (uint32_t seg_y = p; seg_y < p+1; seg_y++)
{
if (app_slcd_seg_pin_buff[seg_y] < 32u)
{
app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[seg_y] );
}
else
{
app_slcd_seg_bits[1u] |= (1u << (app_slcd_seg_pin_buff[seg_y] - 32u) );
}
SLCD_SetCOMxSegBits(BOARD_SLCD_PORT, com_x, (uint32_t * )app_slcd_seg_bits);
app_delay(200u);
}
}
while( GPIO_ReadInDataBit(BOARD_KEY0_GPIO_PORT, BOARD_KEY0_GPIO_PIN)==1);
if(p<28) p=p+1;
app_delay(100u);
}
}
在编译下载程序后,每按下一次K2键,就显示出对应笔段的内容,以便分析和使用。 借助表2的帮助,可通过下面的程序来实现数字的显示测试: 数字符号显示: int main(void)
{
BOARD_Init();
app_slcd_init();
app_display(0);
app_delay(500);
app_display(1);
app_delay(500);
app_display(2);
app_delay(500);
app_display(3);
app_delay(500);
app_display(4);
app_delay(500);
app_display(5);
app_delay(500);
app_display(6);
app_delay(500);
app_display(7);
app_delay(500);
app_display(8);
app_delay(500);
app_display(9);
app_delay(500);
while(1);
}
void app_display(char ch)
{
unsigned char n,w;
unsigned char tab[10]={0xbe,0x06,0x7c,0x5e,0xc6,0xda,0xfa,0x0e,0xfe,0xde};
w=tab[ch];
SLCD_ClearAllSegBits(BOARD_SLCD_PORT);
app_slcd_seg_bits[0u] = 0u;
app_slcd_seg_bits[1u] = 0u;
for (uint32_t com_x = 0u; com_x < BOARD_SLCD_COM_NUM; com_x++)
{
if((w&0x01)==1) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[5] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[5] ));
if((w&0x10)!=0) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[1] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[1] ));
SLCD_SetCOMxSegBits(BOARD_SLCD_PORT, com_x, (uint32_t * )app_slcd_seg_bits);
w=w>>1;
}
}
在显示数据时,常离不开小数点的实验,控制小数点的测试语句如下: LCD_DisplayNumber(1,6,0); app_delay(500); LCD_DisplayNumber(1,8,0); app_delay(500); 控制小数点的关键程序为: for (uint32_t com_x = 0u; com_x < BOARD_SLCD_COM_NUM; com_x++)
{
if((w&0x01)==1) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[k] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[k] ));
if((w&0x10)!=0) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[j] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[j] ));
if((Point==1)&&(com_x==0)) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[k]);
SLCD_SetCOMxSegBits(BOARD_SLCD_PORT, com_x, (uint32_t * )app_slcd_seg_bits);
w=w>>1;
}
实现多个小号数字出现的程序为: int main(void)
{
BOARD_Init();
app_slcd_init();
SLCD_ClearAllSegBits(BOARD_SLCD_PORT);
app_slcd_seg_bits[0u] = 0u;
app_slcd_seg_bits[1u] = 0u;
LCD_DisplayNumber(1,8,0);
app_delay(500);
LCD_DisplayNumber(2,0,0);
while(1);
}
测试多个大号数字出现的语句为: app_delay(500); LCD_DisplayNumberD(5,0,1); app_delay(500); LCD_DisplayNumberD(6,5,0);
app_delay(500); LCD_DisplayNumberD(7,2,1); app_delay(500); LCD_DisplayNumberD(8,3,0);
app_delay(500); LCD_DisplayNumberD(9,4,1); app_delay(500); LCD_DisplayNumberD(10,9,0);
实现大号数字显示的函数为: void LCD_DisplayNumberD(uint8_t Index,char ch,uint8_t Point)
{
char j,k;
uint8_t w;
unsigned char tab[10]={0xd7,0x06,0xe3,0xa7,0x36,0xb5,0xe5,0x07,0xf7,0xb7};
w=tab[ch];
if(Index==5)
{
j=6;
k=7;
}
if(Index==6)
{
j=8;
k=9;
}
if(Index==7)
{
j=13;
k=14;
}
if(Index==8)
{
j=18;
k=17;
}
if(Index==9)
{
j=20;
k=19;
}
if(Index==10)
{
j=26;
k=27;
}
app_slcd_seg_bits[0u] = 0u;
for (uint32_t com_x = 0u; com_x < BOARD_SLCD_COM_NUM; com_x++)
{
if((w&0x01)==1) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[k] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[k] ));
if((w&0x10)!=0) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[j] );
else app_slcd_seg_bits[0u] &= (~(1u << app_slcd_seg_pin_buff[j] ));
if(Point==1)
{
if ( com_x == 3u) app_slcd_seg_bits[0u] |= (1u << app_slcd_seg_pin_buff[k]);
}
SLCD_SetCOMxSegBits(BOARD_SLCD_PORT, com_x, (uint32_t * )app_slcd_seg_bits);
w=w>>1;
}
}
在与ADC相配合进行采集数据显示时,其效果如图2所示。
图2 显示采集数据
这样我们就可以利用LCD屏来进行人机交互了,而无需全部倚仗着串口的帮助。
|