標題:
OLED花樣顯示之折線圖 STM32源程序
[打印本頁]
作者:
837877663
時間:
2019-6-11 23:24
標題:
OLED花樣顯示之折線圖 STM32源程序
用STM32F103C8T6驅(qū)動0.96寸OLED顯示屏顯示折線圖,可以用于顯示溫讀,濕度等數(shù)據(jù),讓數(shù)據(jù)的變化更直觀,界面更炫酷
制作出來的實物圖如下:
IMG_20190611_225950.jpg
(3.01 MB, 下載次數(shù): 53)
下載附件
2019-6-11 23:22 上傳
單片機源程序如下:
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "usmart.h"
#include "OLED_I2C.h"
extern unsigned char BMP1[];
unsigned char BMP2[8192];
//將128*8的數(shù)組轉(zhuǎn)為128*64
void Change_to_12864(unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y,n,BMP3[1024];
for(y=0;y<64;y=y+8)
{
for(x=0;x<128;x++)
{
BMP3[j]=BMP[j];
for(n=0;n<8;n++)
{
if(BMP3[j]&0x01)
BMP2[x+(y+n)*128]=1;
BMP3[j]=BMP3[j]>>1;
}
j++;
}
}
}
//將128*64的數(shù)組轉(zhuǎn)為128*8
void Change_to_1288(unsigned char BMP4[])
{
unsigned int j=0;
unsigned char x,y,n,temp;
for(y=0;y<64;y=y+8)
{
for(x=0;x<128;x++)
{
for(n=0;n<8;n++)
{
temp|=BMP4[x+(y+n)*128]<<7;
if(n<7)
temp=temp>>1;
}
BMP1[j]=temp;
temp=0;
j++;
}
}
}
//畫線
//x1,y1:起點坐標
//x2,y2:終點坐標
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
{
u16 t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //計算坐標增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; //設(shè)置單步方向
else if(delta_x==0)incx=0;//垂直線
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;//水平線
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; //選取基本增量坐標軸
else distance=delta_y;
for(t=0;t<=distance+1;t++ )//畫線輸出
{
BMP2[uRow+uCol*128]=1;//畫點
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
//顯示全屏
void OLED_Fast(unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y;
for(y=0;y<8;y++)
{
OLED_SetPos(0,y);
for(x=0;x<128;x++)
{
WriteDat(BMP[j]);
j++;
}
}
}
//顯示折線圖
void ZXT(unsigned char num)
{
static unsigned char num2=0;
unsigned char x,y;
LCD_DrawLine(122,63-num2,126,63-num);//畫線
num2=num;
Change_to_1288((unsigned char *)BMP2);
for(x=0;x<124;x++)//畫橫軸和橫軸刻度
{
if(x%8==0&&x!=0)
BMP1[x+7*128]|=0xC0;
else
BMP1[x+7*128]|=0x80;
}
for(y=0;y<8;y++)//畫縱軸
{
BMP1[y*128]|=0xFF;
}
for(y=0;y<8;y++)//畫縱軸刻度
{
BMP1[1+y*128]|=0x80;
}
for(y=0;y<64;y++)//圖像左移4個像素
{
for(x=0;x<124;x++)
{
BMP2[x+y*128]=BMP2[x+y*128+4];
}
}
for(y=0;y<64;y++)//清除最右邊的一條畫線
{
for(x=124;x<128;x++)
{
BMP2[x+y*128]=0;
}
}
}
//LED狀態(tài)設(shè)置函數(shù)
void led_set(u8 sta)
{
LED1=sta;
}
//函數(shù)參數(shù)調(diào)用測試函數(shù)
void test_fun()
{
OLED_DrawBMP(0,0,128,8,(unsigned char *)BMP1);
}
int main(void)
{
u8 y;
u8 s[17]={44,48,55,50,53,31,40,49,48,42,38,38,25,29,46,39,47};
delay_init(); //延時函數(shù)初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級
uart_init(115200); //串口初始化為115200
LED_Init(); //LED端口初始化
I2C_Configuration();
OLED_Init();
usmart_dev.init(SystemCoreClock/1000000); //初始化USMART
OLED_CLS();
while(1)
{
ZXT(s[y]);//輸入0到63的數(shù)
OLED_Fast((unsigned char *)BMP1);
y++;
if(y==17)y=0;
delay_ms(100);
}
}
復(fù)制代碼
所有資料51hei提供下載:
OLED-顯示折線圖.7z
(209.24 KB, 下載次數(shù): 119)
2019-6-12 17:36 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
phy123
時間:
2019-10-6 16:15
像這種折線圖的應(yīng)用還是比較廣的,一般人機交互這塊用的比較多一點,比如樓主的顯示溫度與時間的關(guān)系,還可以用來展示某一時段的用電量等等。所以說,一般我們用到人機界面展示數(shù)據(jù)的時候,這種會比純顯示數(shù)據(jù)好的多
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1