硬件平臺
STM32開發(fā)板
功能實現(xiàn)
??在OLED屏上實現(xiàn)字符串滾動顯示。
??0.96寸OLED分辨率為128*64(128列,64行)。我們可以定義二維數(shù)組緩沖區(qū)buff[64][128],先將要顯示的數(shù)據(jù)放在緩沖驅(qū)動中,然后按固定頻率將數(shù)據(jù)更新到屏幕上。
示例效果
STM32驅(qū)動OLED屏滾動顯示
軟件設(shè)計
?顯示一列數(shù)據(jù)函數(shù)
/*
函數(shù)功能: 顯示一列
函數(shù)參數(shù):
u8 x - 橫坐標位置
u8 y - 縱坐標位置
u8 size -字體大小
u8 *p - 源數(shù)據(jù)
說 明:保證縱向為8的倍數(shù)
取模方式:縱向取模,以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
滾動顯示函數(shù)(左移顯示)
/******************************字符串滾動顯示****************************
**左移滾動顯示
** u8 x,u8 y --- 顯示的起始位置
** u8 size --- 字體大小
** u8 *p --- 需要滾動顯示的數(shù)據(jù)
** u8 number --- 要顯示的漢字個數(shù)
*******************************************************************/
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)//完整顯示完一行數(shù)據(jù)
{
x0=0;
data+=size/8;//數(shù)據(jù)的起始位置往后移動
}
offset++;
if(offset>=number*size+128)//保存顯示的數(shù)據(jù)完整滾動完一遍
{
offset=0; //歸位
x0=x;
data=p;//數(shù)據(jù)地址歸位
}
}
}
主函數(shù)
/*測試數(shù)據(jù): 縱向取模,以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},/*"學(xué)",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},/*"習(xí)",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},/*"發(fā)",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);//滾動顯示
}
}
結(jié)論:0.96寸OLED屏硬件自帶滾動顯示效果,但使用OLED屏硬件方式實現(xiàn)滾動無法靈活顯示,采用軟件方式實現(xiàn)滾動顯示更加靈活便捷。
審核編輯:符乾江
-
STM32
+關(guān)注
關(guān)注
2270文章
10914瀏覽量
356712 -
OLED屏
+關(guān)注
關(guān)注
0文章
162瀏覽量
20879 -
滾動顯示
+關(guān)注
關(guān)注
0文章
10瀏覽量
5714
發(fā)布評論請先 登錄
相關(guān)推薦
評論