完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
STM32驱动OLED屏完成汉字串滚动显示
硬件平台
在OLED屏上实现字符串滚动显示。示例效果 STM32驱动OLED屏滚动显示 软件设计 显示一列数据函数 /* 函数功能: 显示一列 函数参数: u8 x - 横坐标位置 u8 y - 纵坐标位置 u8 size -字体大小 u8 *p - 源数据 说 明:保证纵向为8的倍数 取模方式:纵向取模,以8个点为单位进行取模,高位在前 */ void OLED_DrawRecData2(u8 x,u8 y,u8 size,const u8 *p) { u8 y0=y; //保存y坐标 u8 i,j; u8 data=0; for(i=0;i data=*(p+i); //显示上半部分 for(j=0;j<8;j++) { if(data&0x80)OLED_DrawPoint(x,y0,1); //点亮OLED指定位置灯 else OLED_DrawPoint(x,y0,0); //关闭 data<<=1; //继续判断高位 y0++; //纵坐标自增 } } } 滚动显示函数(左移显示) /******************************字符串滚动显示**************************** **左移滚动显示 ** u8 x,u8 y --- 显示的起始位置 ** u8 size --- 字体大小 ** u8 *p --- 需要滚动显示的数据 ** u8 number --- 要显示的汉字个数 *******************************************************************/ void OLED_Left_Move_Display(u8 x,u8 y,u8 size,u8 *p,u8 number) { int x0=x;//显示的起始位置 int i=0; u8 *data=p; u16 cnt=0,offset=0; while(1) { for(cnt=0,i=x0;i<128;i++) { OLED_DrawRecData2(i,y,size,data+cnt);//显示一列 cnt+=size/8;//一列的偏移量 } OLED_RefreshGRAM(); //更新一次显示 x0--;//左移显示 if(x0<=0)//完整显示完一行数据 { x0=0; data+=size/8;//数据的起始位置往后移动 } offset++; if(offset>=number*size+128)//保存显示的数据完整滚动完一遍 { offset=0; //归位 x0=x; data=p;//数据地址归位 } } } 主函数 /*测试数据: 纵向取模,以8个点为单位进行取模,高位在前*/ u8 font_test2[28][32]= { {0x20,0x08,0x24,0x10,0x22,0x60,0x21,0x80,0x26,0x41,0x39,0x32,0x02,0x04,0x0C,0x18,0xF0,0x60,0x13,0x80,0x10,0x60,0x10,0x18,0x14,0x04,0x18,0x02,0x00,0x01,0x00,0x00},/*"欢",0*/ {0x02,0x00,0x02,0x02,0x42,0x04,0x33,0xF8,0x00,0x04,0x00,0x02,0x3F,0xF2,0x20,0x22,0x40,0x42,0x00,0x02,0x3F,0xFE,0x20,0x42,0x20,0x22,0x3F,0xC2,0x00,0x02,0x00,0x00},/*"迎",1*/ {0x00,0x84,0x10,0x84,0x10,0x88,0x14,0x88,0x13,0x90,0x10,0xA0,0x10,0xC0,0xFF,0xFF,0x10,0xC0,0x10,0xA0,0x11,0x90,0x16,0x88,0x10,0x88,0x10,0x84,0x00,0x84,0x00,0x00},/*"来",2*/ {0x20,0x01,0x20,0x02,0x20,0x04,0x20,0x18,0x20,0x60,0x3F,0x80,0x22,0x00,0x22,0x00,0x22,0x02,0x22,0x01,0x22,0x02,0x23,0xFC,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00},/*"万",3*/ {0x10,0x41,0x12,0x42,0x12,0x44,0x12,0x58,0xFF,0xE0,0x12,0x40,0x12,0x40,0x10,0x40,0x00,0x00,0x7F,0xFF,0x40,0x10,0x44,0x08,0x5B,0x10,0x60,0xE0,0x00,0x00,0x00,0x00},/*"邦",4*/ {0x00,0x00,0x00,0x10,0x00,0x20,0x00,0x42,0xFE,0xC4,0x93,0x48,0x92,0x71,0x92,0x42,0x92,0x4C,0x92,0x70,0x92,0x42,0xFE,0x41,0x00,0x42,0x00,0x7C,0x00,0x00,0x00,0x00},/*"易",5*/ {0x01,0x00,0x01,0x00,0x77,0xFE,0x11,0x24,0x11,0x24,0x11,0x24,0x17,0xFE,0xF1,0x00,0x10,0x81,0x11,0x02,0x1E,0x0C,0x12,0xF0,0x72,0x0C,0x02,0x82,0x03,0x01,0x00,0x00},/*"嵌",6*/ {0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00},/*"学",7*/ {0x00,0x00,0x40,0x10,0x40,0x18,0x40,0x10,0x48,0x20,0x44,0x20,0x43,0x20,0x40,0x40,0x40,0x40,0x40,0x82,0x40,0x81,0x40,0x02,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00},/*"习",8*/ {0x01,0x00,0x01,0x00,0x77,0xFE,0x11,0x24,0x11,0x24,0x11,0x24,0x17,0xFE,0xF1,0x00,0x10,0x81,0x11,0x02,0x1E,0x0C,0x12,0xF0,0x72,0x0C,0x02,0x82,0x03,0x01,0x00,0x00},/*"嵌",9*/ {0x00,0x01,0x00,0x02,0x00,0x04,0x00,0x08,0x00,0x30,0x80,0xC0,0x47,0x00,0x38,0x00,0x07,0x00,0x00,0xC0,0x00,0x30,0x00,0x0C,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x00},/*"入",10*/ {0x08,0x00,0x08,0x04,0x09,0x06,0x09,0x04,0x09,0xFC,0x09,0x08,0x09,0x08,0x08,0x08,0x08,0x00,0xFF,0xC0,0x08,0x30,0x08,0x08,0x88,0x04,0x68,0x02,0x08,0x1F,0x00,0x00},/*"式",11*/ {0x01,0x00,0x41,0x01,0x41,0x02,0x41,0x0C,0x7F,0xF0,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x7F,0xFF,0x41,0x00,0x41,0x00,0x41,0x00,0x01,0x00,0x00,0x00},/*"开",12*/ {0x00,0x00,0x00,0x04,0x18,0x08,0x68,0x31,0x08,0xC1,0x0B,0x01,0x1D,0x82,0xE9,0x62,0x09,0x14,0x09,0x08,0x09,0x14,0x49,0x22,0x29,0xC2,0x08,0x01,0x00,0x01,0x00,0x00},/*"发",13*/ }; int main(void) { u8 *p; BEEP_Init(); //初始化蜂鸣器 LED_Init(); //初始化LED灯 KEY_Init(); //初始化按键 USART1_Init(115200); //初始化串口1 OLED_Init(); //OLED显示屏初始化 OLED_Clear(0x00); //清屏 p=font_test2[0]; //要显示的字符串 while(1) { OLED_Left_Move_Display(127,10,16,p,14);//滚动显示 } } 结论:0.96寸OLED屏硬件自带滚动显示效果,但使用OLED屏硬件方式实现滚动无法灵活显示,采用软件方式实现滚动显示更加灵活便捷。 |
|
|
|
确实是高质量的总结,也可以局部刷新的,有OLED屏需求可以calll(可以提供技术支持,微信同)
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1767 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1619 浏览 1 评论
1069 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
724 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1673 浏览 2 评论
1935浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
728浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
567浏览 3评论
592浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
551浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 01:16 , Processed in 0.943228 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号