![]() |
zhuls 發(fā)表于 2023-10-21 09:10 按鍵按下,索引反白顯示上下移動,不刷新可以正常顯示,有些是做到了,函數(shù)該怎么寫 |
zhuls 發(fā)表于 2023-10-23 13:40 樓主,我發(fā)了一張圖,就是光標索引上下移動,顯示反白 |
你查一下OLED的顯示屏指令集,指令集是有的 |
這段代碼給你參考一下,改自你貼上來的代碼:
|
sr861126 發(fā)表于 2023-10-24 11:22 如果只是這樣,那就依我之前說的: “在調(diào)的顯示字符串函數(shù)中,傳遞一個反白顯示的參數(shù),并層層傳遞到打點顯示的函數(shù)里,把字符數(shù)據(jù)取反就成了。” 在漢顯函數(shù)“中景園電子科技”時,把反白標志置位,并原樣傳送到最底層的打點函數(shù)里就可以了。 |
sr861126 發(fā)表于 2023-10-18 17:57 用iCloud |
zhuls 發(fā)表于 2023-10-16 14:27 是的是的 |
zhuls 發(fā)表于 2023-10-23 13:40 光標發(fā)白是,光標移動到菜單項反白,字體不反白還是黑色的 |
sr861126 發(fā)表于 2023-10-23 09:12 不太明白你說的意思。 比如12864,只能顯示漢字 4行*8字,你想要的: 是有5行*8字的內(nèi)容,通過按鍵,顯示一、二、三、四行或二、三、四、五行的內(nèi)容? 還是當(dāng)有5行*8字的內(nèi)容,在屏幕的右側(cè)出現(xiàn)類似WINDOWS的滾動條,少于5行則不顯示? 還是光標在第一行時,第一行字符反顯,通過按鍵移動到第二行時,第二行字符反顯,第一行變回正顯? 還是就光標所在的位置閃爍(反顯+正顯交替)? 還是其它什么的,能配圖說明一下嗎? |
zhuls 發(fā)表于 2023-10-16 14:27 我要顯示光標上下翻動,顯示白色滾動條,該怎么設(shè)置函數(shù) |
師傅,我的意思是光標顯示位置反白,不是字體反白 |
sr861126 發(fā)表于 2023-10-20 18:25 就“刷新”而言,如果新的內(nèi)容占位(字符串長度)大于舊的內(nèi)容,直接寫入就行了。反之要先清除舊內(nèi)容,再寫入新內(nèi)容。否則會出現(xiàn)顯示殘留、花屏、亂碼==。 |
zhuls 發(fā)表于 2023-10-19 09:10 刷新就是清空上一次顯示的嗎? |
feeling1791 發(fā)表于 2023-10-19 10:22 多謝,我看看,不明白的再請教了 |
發(fā)個武功秘籍給你,用這個GUI,基本你能想到的都可以實現(xiàn) |
34.51 KB, 下載次數(shù): 14
sr861126 發(fā)表于 2023-10-18 17:57 這個要刷新顯示數(shù)據(jù)的, 從: 〖1、00000〗 〖2、00000〗 〖3、00000〗 【4、00000】 到: 〖1、00000〗 【2、00000】 〖3、00000〗 〖4、00000〗 就要刷新第2行和第4行的當(dāng)數(shù)據(jù) |
zhuls 發(fā)表于 2023-10-18 09:41 按鍵控制索引號上下移動,這個函數(shù)怎么添加變量呢? |
取反一下就行了 |
sr861126 發(fā)表于 2023-10-17 15:42 void OLED_DrawPoint(u8 x,u8 y,u8 t) { u8 pos,bx,temp=0; if(x>127||y>63)return;//超出范圍了. pos=7-y/8; //這段代碼可以寫成以下樣子 bx=y%8; //if(t)OLED_GRAM[x][7-y/8]|=1<<(7-y%8); temp=1<<(7-bx); //if(t)OLED_GRAM[x][7-y/8]|=~(1<<(7-y%8)); if(t)OLED_GRAM[x][pos]|=temp; //這2行就是正反顯了 else OLED_GRAM[x][pos]&=~temp; //這2行就是正反顯了 |
請教一下,哪個函數(shù)可以實現(xiàn)反顯,移動菜單項目顯示滾動條 #include "OLED_I2C.h" #include "delay.h" #include "codetab.h" u8 OLED_GRAM[128][8]; extern unsigned char character[]; void IIC_Start() { OLED_SCLK_Set() ; OLED_SDIN_Set(); OLED_SDIN_Clr(); OLED_SCLK_Clr(); } /********************************************** //IIC Stop **********************************************/ void IIC_Stop() { OLED_SCLK_Set() ; // OLED_SCLK_Clr(); OLED_SDIN_Clr(); OLED_SDIN_Set(); } void IIC_Wait_Ack() { //GPIOB->CRH &= 0XFFF0FFFF; //設(shè)置PB12為上拉輸入模式 //GPIOB->CRH |= 0x00080000; // OLED_SDA = 1; // delay_us(1); //OLED_SCL = 1; //delay_us(50000); /* while(1) { if(!OLED_SDA) //判斷是否接收到OLED 應(yīng)答信號 { //GPIOB->CRH &= 0XFFF0FFFF; //設(shè)置PB12為通用推免輸出模式 //GPIOB->CRH |= 0x00030000; return; } } */ OLED_SCLK_Set() ; OLED_SCLK_Clr(); } /********************************************** // IIC Write byte **********************************************/ void Write_IIC_Byte(unsigned char IIC_Byte) { unsigned char i; unsigned char m,da; da=IIC_Byte; OLED_SCLK_Clr(); for(i=0;i<8;i++) { m=da; OLED_SCLK_Clr(); m=m&0x80; if(m==0x80) { OLED_SDIN_Set(); } else OLED_SDIN_Clr(); da=da<<1; OLED_SCLK_Set(); OLED_SCLK_Clr(); } } /********************************************** // IIC Write Command **********************************************/ void Write_IIC_Command(unsigned char IIC_Command) { IIC_Start(); Write_IIC_Byte(0x78); //Slave address,SA0=0 IIC_Wait_Ack(); Write_IIC_Byte(0x00); //write command IIC_Wait_Ack(); Write_IIC_Byte(IIC_Command); IIC_Wait_Ack(); IIC_Stop(); } /********************************************** // IIC Write Data **********************************************/ void Write_IIC_Data(unsigned char IIC_Data) { IIC_Start(); Write_IIC_Byte(0x78); //D/C#=0; R/W#=0 IIC_Wait_Ack(); Write_IIC_Byte(0x40); //write data IIC_Wait_Ack(); Write_IIC_Byte(IIC_Data); IIC_Wait_Ack(); IIC_Stop(); } void WriteCmd(unsigned char I2C_Command)//寫命令 { Write_IIC_Command(I2C_Command); } void WriteDat(unsigned char I2C_Data)//寫數(shù)據(jù) { Write_IIC_Data(I2C_Data); } void OLED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能A端口時鐘 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度50MHz GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化GPIOD3,6 GPIO_SetBits(GPIOC,GPIO_Pin_13|GPIO_Pin_14); delay_ms(100); //這里的延時很重要 WriteCmd(0xAE); //display off WriteCmd(0x20); //Set Memory Addressing Mode WriteCmd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid WriteCmd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7 WriteCmd(0xc8); //Set COM Output Scan Direction WriteCmd(0x00); //---set low column address WriteCmd(0x10); //---set high column address WriteCmd(0x40); //--set start line address WriteCmd(0x81); //--set contrast control register WriteCmd(0x0f); //亮度調(diào)節(jié) 0x00~0xff WriteCmd(0xa1); //--set segment re-map 0 to 127 WriteCmd(0xa6); //--set normal display WriteCmd(0xa8); //--set multiplex ratio(1 to 64) WriteCmd(0x3F); // WriteCmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content WriteCmd(0xd3); //-set display offset WriteCmd(0x00); //-not offset WriteCmd(0xd5); //--set display clock divide ratio/oscillator frequency WriteCmd(0xf0); //--set divide ratio WriteCmd(0xd9); //--set pre-charge period WriteCmd(0x22); // WriteCmd(0xda); //--set com pins hardware configuration WriteCmd(0x12); WriteCmd(0xdb); //--set vcomh WriteCmd(0x20); //0x20,0.77xVcc WriteCmd(0x8d); //--set DC-DC enable WriteCmd(0x14); // WriteCmd(0xaf); //--turn on oled panel } void OLED_SetPos(unsigned char x, unsigned char y) //設(shè)置起始點坐標 { WriteCmd(0xb0+y); WriteCmd(((x&0xf0)>>4)|0x10); WriteCmd((x&0x0f)|0x01); } void OLED_Fill(unsigned char fill_Data)//全屏填充 { unsigned char m,n; for(m=0;m<8;m++) { WriteCmd(0xb0+m); //page0-page1 WriteCmd(0x00); //low column start address WriteCmd(0x10); //high column start address for(n=0;n<128;n++) { WriteDat(fill_Data); } } } void OLED_CLS(void)//清屏 { OLED_Fill(0x00); } //-------------------------------------------------------------- // Prototype : void OLED_ON(void) // Calls : // Parameters : none // Description : 將OLED從休眠中喚醒 //-------------------------------------------------------------- void OLED_ON(void) { WriteCmd(0X8D); //設(shè)置電荷泵 WriteCmd(0X14); //開啟電荷泵 WriteCmd(0XAF); //OLED喚醒 } //-------------------------------------------------------------- // Prototype : void OLED_OFF(void) // Calls : // Parameters : none // Description : 讓OLED休眠 -- 休眠模式下,OLED功耗不到10uA //-------------------------------------------------------------- void OLED_OFF(void) { WriteCmd(0X8D); //設(shè)置電荷泵 WriteCmd(0X10); //關(guān)閉電荷泵 WriteCmd(0XAE); //OLED休眠 } void OLED_Set_Pos(unsigned char x, unsigned char y) { WriteCmd(0xb0+y); WriteCmd(((x&0xf0)>>4)|0x10); WriteCmd((x&0x0f)); } //-------------------------------------------------------------- // Prototype : void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize) // Calls : // Parameters : x,y -- 起始點坐標(x:0~127, y:0~7); ch[] -- 要顯示的字符串; TextSize -- 字符大小(1:6*8 ; 2:8*16) // Description : 顯示codetab.h中的ASCII字符,有6*8和8*16可選擇 //-------------------------------------------------------------- void OLED_ShowStr(unsigned char x, unsigned char y, char ch[], unsigned char TextSize) { unsigned char c = 0,i = 0,j = 0; switch(TextSize) { case 1: { while(ch[j] != '\0') { c = ch[j] - 32; if(x > 126) { x = 0; y++; } OLED_SetPos(x,y); for(i=0;i<6;i++) WriteDat(F6x8[c][i]); x += 6; j++; } }break; case 2: { while(ch[j] != '\0') { c = ch[j] - 32; if(x > 120) { x = 0; y++; } OLED_SetPos(x,y); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i]); OLED_SetPos(x,y+1); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i+8]); x += 8; j++; } }break; } } void OLED_ShowStr1(unsigned char x, unsigned char y, char ch[], unsigned char TextSize) { unsigned char c = 0,i = 0,j = 0; switch(TextSize) { case 1: { while(ch[j] != '\0') { c = ch[j] - 32; if(x > 126) { x = 0; y++; } OLED_SetPos(x,y); for(i=0;i<6;i++) WriteDat(F6x8[c][i]); x += 6; j++; } }break; case 2: { while(ch[j] != '\0') { c = ch[j] - 32; if(x > 120) { x = 0; y++; } OLED_SetPos(x,y); for(i=0;i<8;i++) WriteDat(~F8X16[c*16+i]); OLED_SetPos(x,y+1); for(i=0;i<8;i++) WriteDat(~F8X16[c*16+i+8]); x += 8; j++; } }break; } } void OLED_ShowoneStr(unsigned char x, unsigned char y,char ch) { unsigned char c = 0,i = 0; c = ch - 32; OLED_SetPos(x,y); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i]); OLED_SetPos(x,y+1); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i+8]); } //-------------------------------------------------------------- // Prototype : void OLED_ShowCN(unsigned char x, unsigned char y, unsigned char N) // Calls : // Parameters : x,y -- 起始點坐標(x:0~127, y:0~7); N:漢字在codetab.h中的索引 // Description : 顯示codetab.h中的漢字,16*16點陣 //-------------------------------------------------------------- void OLED_ShowCN(unsigned char x, unsigned char y, unsigned char N) { unsigned char wm=0; unsigned int adder=32*N; OLED_SetPos(x , y); for(wm = 0;wm < 16;wm++) { WriteDat(F16x16[adder]); adder += 1; } OLED_SetPos(x,y + 1); for(wm = 0;wm < 16;wm++) { WriteDat(F16x16[adder]); adder += 1; } } u8 OLED_findoneCN(u8 ch1,u8 ch2) { u8 j=0; while(character[j]!='\0') { if(ch1==character[j]&&ch2==character[j+1]) return j/2+1; j+=2; } return 0; } void OLED_Show(u8 x, u8 y,u8 ch[]) { int j=0,k; while(ch[j] != '\0') { if(ch[j]>0x80)//漢字 { k=OLED_findoneCN(ch[j],ch[j+1]); if(k!=0)OLED_ShowCN(j*8+x,y,k-1); j+=2; } else//ASCLL { OLED_ShowoneStr(j*8+x,y,ch[j]); j++; } } } void OLED_DrawPoint(u8 x,u8 y,u8 t) { u8 pos,bx,temp=0; if(x>127||y>63)return;//超出范圍了. pos=7-y/8; //這段代碼可以寫成以下樣子 bx=y%8; //if(t)OLED_GRAM[x][7-y/8]|=1<<(7-y%8); temp=1<<(7-bx); //if(t)OLED_GRAM[x][7-y/8]|=~(1<<(7-y%8)); if(t)OLED_GRAM[x][pos]|=temp; else OLED_GRAM[x][pos]&=~temp; } //在指定位置顯示一個字符,包括部分字符 //x:0~127 //y:0~63 //mode:0,反白顯示;1,正常顯示 //size:選擇字體 16/12 void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 size,u8 mode) { u8 temp,t,t1; u8 y0=y; u8 csize=(size/8+((size%8)?1:0))*(size/2); //得到字體一個字符對應(yīng)點陣集所占的字節(jié)數(shù) chr=chr-' ';//得到偏移后的值 for(t=0;t<csize;t++) { if(size==12)temp=F6x8[chr][t]; //調(diào)用1206字體 // else if(size==16)temp=asc2_1608[chr][t]; //調(diào)用1608字體 // else if(size==24)temp=asc2_2412[chr][t]; //調(diào)用2412字體 else return; //沒有的字庫 for(t1=0;t1<8;t1++) { if(temp&0x80)OLED_DrawPoint(x,y,mode); else OLED_DrawPoint(x,y,!mode); temp<<=1; y++; if((y-y0)==size) { y=y0; x++; break; } } } } |
在調(diào)的顯示字符串函數(shù)中,傳遞一個反白顯示的參數(shù),并層層傳遞到打點顯示的函數(shù)里,把字符數(shù)據(jù)取反就成了。 |
Powered by 單片機教程網(wǎng)