(六)Protues仿真STM32单片机控制8x8LED显示 – ARMFUN
1,配置CUBEMX,将PA0~7,PAB0~7配置为GPIO OUTPUT模式
2,GPIOA负责8bit数据,高电平有效,GPIOB负责行选则,低电平有效,编写行刷新函数
void disp_set_row(unsigned char dat,char sel)
{
GPIOB->ODR=0xff;//关闭行选,防止将数据显示到旧行产生重影
GPIOA->ODR=dat;//更新数据
switch(sel)//打开新行
{
case 0:GPIOB->ODR=0xfe;break;
case 1:GPIOB->ODR=0xfd;break;
case 2:GPIOB->ODR=0xfb;break;
case 3:GPIOB->ODR=0xf7;break;
case 4:GPIOB->ODR=0xef;break;
case 5:GPIOB->ODR=0xdf;break;
case 6:GPIOB->ODR=0xbf;break;
case 7:GPIOB->ODR=0x7f;break;
}
}
3,定义一个显示缓冲区屏幕是8x8=64bit,需要定义一个长度为8的uchar数组,编写扫描点阵驱动函数,此函数需要定义3~10ms调用一次,实现逐行点亮LED
unsigned char dispbuff[8];
void disp_scan()
{
static char scan=0;
disp_set_row(dispbuff[scan],scan);
scan++;
if(scan>=8)
scan=0;
}
4,定义显示的图形,并且每次调用更换图形,此函数需要定时100ms以上调用一次,防止图形切换太快影子重叠。
unsigned char pic1[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,};
unsigned char pic2[8]={0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff,};
unsigned char pic3[8]={0x0,0x7e,0x42,0x42,0x42,0x42,0x7e,0x0,};
unsigned char pic4[8]={0x0,0x0,0x3c,0x24,0x24,0x3c,0x00,0x0,};
unsigned char pic5[8]={0x0,0x0,0x00,0x18,0x18,0x00,0x00,0x0,};
unsigned char pic6[8]={0x00,0x00,0x00,0x0,0x0,0x0,0x0,0x0,};
void disp_pic_switch()
{
static char sel=0;
switch(sel)
{
case 0:memcpy(dispbuff,pic1,8);break;
case 1:memcpy(dispbuff,pic2,8);break;
case 2:memcpy(dispbuff,pic3,8);break;
case 3:memcpy(dispbuff,pic4,8);break;
case 4:memcpy(dispbuff,pic5,8);break;
case 5:memcpy(dispbuff,pic6,8);break;
}
sel++;
if(sel>=6)
sel=0;
}
标签:case,break,char,8x8LED,ODR,0x0,STM32,单片机,0xff
From: https://blog.csdn.net/qqk808/article/details/142435486