12864的OLED简单显示程序.docx
- 文档编号:28765416
- 上传时间:2023-07-19
- 格式:DOCX
- 页数:26
- 大小:20.96KB
12864的OLED简单显示程序.docx
《12864的OLED简单显示程序.docx》由会员分享,可在线阅读,更多相关《12864的OLED简单显示程序.docx(26页珍藏版)》请在冰豆网上搜索。
12864的OLED简单显示程序
OLED12864程序.哥瞎写的
/*___________________________OLED12864.c_____*/
#include"stm32f4xx.h"
#include"oled12864.h"
#include"codetab.h"
#defineDEFAULT_PRT_START_ROW2//默认显示字符串的起始行数
#defineDEFAULT_PRT_END_ROW7//默认显示字符串的中止行数
u8default_prt_nowrow;
u8oled_buf[8][128];
/*********延时函数**********/
voidoled12864_delay(intn_count)
{
while(n_count)
{
n_count--;
}
}
/*********************LCD全屏************************************/
voidoled12864_fill_full(unsignedcharbmp_dat)
{
unsignedchary,x;
OLED12864_CS=0;//使能片选
for(y=0;y<8;y++)
{
oled12864_wr_cmd(0xb0+y);
oled12864_wr_cmd(0x01);
oled12864_wr_cmd(0x10);
for(x=0;x { //oled12864_delay(10000); oled12864_wr_data(bmp_dat); } } OLED12864_CS=1; } /*********************LCD复位************************************/ voidoled12864_cls(void) { unsignedchary,x; OLED12864_CS=0;//使能片选 for(y=0;y<8;y++) { oled12864_wr_cmd(0xb0+y); oled12864_wr_cmd(0x01); oled12864_wr_cmd(0x10); for(x=0;x oled12864_wr_cmd(0); } OLED12864_CS=1; } /*********************LCD初始化************************************/ voidoled12864_init(void) { //manual_spi_init(); OLED12864_CS=0;//使能片选 //MAN_SPI_SCL=1; //MAN_SPI_SDA=1; OLED12864_DC=1; OLED12864_RST=0; oled12864_delay(400000); OLED12864_RST=1;//从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 oled12864_wr_cmd(0xae);//--turnoffoledpanel oled12864_wr_cmd(0x00);//---setlowcolumnaddress oled12864_wr_cmd(0x10);//---sethighcolumnaddress oled12864_wr_cmd(0x3f);//--setstartlineaddressSetMappingRAMDisplayStartLine(0x00~0x3F) oled12864_wr_cmd(0x81);//--setcontrastcontrolregister oled12864_wr_cmd(0xcf);//SetSEGOutputCurrentBrightness oled12864_wr_cmd(0xa0);//--SetSEG/ColumnMapping0xa0左右反置0xa1正常 oled12864_wr_cmd(0xc0);//SetCOM/RowScanDirection0xc0上下反置0xc8正常 oled12864_wr_cmd(0xa6);//--setnormaldisplay oled12864_wr_cmd(0xa8);//--setmultiplexratio(1to64) oled12864_wr_cmd(0x3f);//--1/64duty oled12864_wr_cmd(0xd3);//-setdisplayoffsetShiftMappingRAMCounter(0x00~0x3F) oled12864_wr_cmd(0x00);//-notoffset oled12864_wr_cmd(0xd5);//--setdisplayclockdivideratio/oscillatorfrequency oled12864_wr_cmd(0x80);//--setdivideratio,SetClockas100Frames/Sec oled12864_wr_cmd(0xd9);//--setpre-chargeperiod oled12864_wr_cmd(0xf1);//SetPre-Chargeas15Clocks&Dischargeas1Clock oled12864_wr_cmd(0xda);//--setcompinshardwareconfiguration oled12864_wr_cmd(0x12); oled12864_wr_cmd(0xdb);//--setvcomh oled12864_wr_cmd(0x40);//SetVCOMDeselectLevel oled12864_wr_cmd(0x20);//-SetPageAddressingMode(0x00/0x01/0x02) oled12864_wr_cmd(0x02);// oled12864_wr_cmd(0x8d);//--setChargePumpenable/disable oled12864_wr_cmd(0x14);//--set(0x10)disable oled12864_wr_cmd(0xa4);//DisableEntireDisplayOn(0xa4/0xa5) oled12864_wr_cmd(0xa6);//DisableInverseDisplayOn(0xa6/a7) oled12864_wr_cmd(0xaf);//--turnonoledpanel oled12864_fill_full(0x02);//初始清屏 oled12864_set_pos(0,0); default_prt_nowrow=DEFAULT_PRT_START_ROW; OLED12864_CS=1; } //无x,y值审查 //white为1,black为0 voidoled12864_draw_point(u8x,u8y,u8white_black) { u8tmp1,tmp2; staticu8pre_x,pre_y; tmp2=(y%8); tmp2=1< y>>=3; if(white_black) { tmp1=oled_buf[y][x];//取得当前值 tmp1|=tmp2; } else { tmp1=oled_buf[y][x]; tmp1&=(! tmp2); } oled_buf[y][x]=tmp1; } //放一个8×6字符串 //注意column是0~128,row是0~7 voidoled12864_put_86char(charcolumn6,charrow,char*ch) { charncount=0; charc; charmax_ncount=(X_WIDTH-column6)/6; while(ch[ncount]! =0&&ncount<=max_ncount) { c=ch[ncount++]; c-=32; oled_buf[row][column6]=F6x8[c][0]; column6++; oled_buf[row][column6]=F6x8[c][1]; column6++; oled_buf[row][column6]=F6x8[c][2]; column6++; oled_buf[row][column6]=F6x8[c][3]; column6++; oled_buf[row][column6]=F6x8[c][4]; column6++; oled_buf[row][column6]=F6x8[c][5]; column6++; } } //按照默认方式显示一行数据,并清空下一行 voidoled12864_printf(char*ch) { oled12864_put_86char(0,default_prt_nowrow,ch); default_prt_nowrow++; if(default_prt_nowrow>DEFAULT_PRT_END_ROW) default_prt_nowrow=DEFAULT_PRT_START_ROW; oled12864_put_86char(0,default_prt_nowrow,"--------------------"); } //oled内容按oled_buf[]刷新 voidoled12864_refresh(void) { unsignedchary,x; u16u16Tmp; intnCount; OLED12864_CS=0;//使能片选 for(y=0;y<8;y++) { oled12864_set_pos(0,y); OLED12864_DC_DATA; OLED12864_CS=0;//使能片选 for(x=0;x { u16Tmp=oled_buf[y][x]; //oled12864_delay(10000); //while(SPI1->SR&0x0080);//等待BSY变成0 for(nCount=0;nCount<9;nCount++); SPI1->DR=u16Tmp; //oled12864_wr_data(oled_buf[y][x]); } } OLED12864_CS=1; } /*___________________________OLED12864.h_____*/ #ifndef__OLED12864_H__ #define__OLED12864_H__ #include"stm32f4_bitband.h" #include"manual_SPI.h" #defineOLED12864_DCPAout(8) #defineOLED12864_DC_HGPIOA->BSRRL=1<<8 #defineOLED12864_DC_LGPIOA->BSRRH=1<<8 #defineOLED12864_DC_DATAOLED12864_DC_H #defineOLED12864_DC_CMDOLED12864_DC_L #defineOLED12864_RSTPAout(3) #defineOLED12864_CSPAout(4) #defineOLED12864_CS_HGPIOA->BSRRL=1<<4 #defineOLED12864_CS_LGPIOA->BSRRH=1<<4 #defineOLED_SPI//用手动SPI方式 #defineOLED_HIGH1 #defineOLED_LOW0 #defineOLED_DC_C0 #defineOLED_DC_D1 #defineXLevelL0x00 #defineXLevelH0x10 #defineXLevel((XLevelH&0x0F)*16+XLevelL) #defineMax_Column128 #defineMax_Row64 #defineBrightness0xCF #defineX_WIDTH128 #defineY_WIDTH64 #defineOLED_BLACK_POINT0 #defineOLED_WHITE_POINT1 #defineOLED_COLUMN6(x)(x*6) /*********延时函数**********/ voidoled12864_delay(intn_count); /*********oled写数据********/ //注意,没有片选,需要在调用函数中片选 #ifdefOLED_8080 #defineOLED12864_WRPAout(6) #defineOLED12864_WR_HGPIOA->BSRRL=1<<6 #defineOLED12864_WR_LGPIOA->BSRRH=1<<6 #defineOLED12864_RDPAout(7) #defineOLED12864_RD_HGPIOA->BSRRL=1<<7 #defineOLED12864_RD_LGPIOA->BSRRH=1<<7 #defineOLED12864_8080_DATAGPIOB->ODR void__inlineoled12864_wr_data(u8data) { OLED12864_8080_DATA=data; OLED12864_DC_H;//写数据信号 //OLED12864_CS=0; OLED12864_WR_L;//写信号 OLED12864_WR_H; //OLED12864_CS=1; OLED12864_DC_H; } /*********OLED写命令********/ void__inlineoled12864_wr_cmd(u8data) { OLED12864_8080_DATA=data; OLED12864_DC_L;//写命令信号 //OLED12864_CS=0; OLED12864_WR_L;//写信号 OLED12864_WR_H; //OLED12864_CS=1; OLED12864_DC_H; } #endif #ifdefOLED_MANUAL_SPI /*********oled写数据********/ void__inlineoled12864_wr_data(u8data) { OLED12864_CS_L;//拉低CS OLED12864_DC=OLED_HIGH; manual_spi_sendbyte(data); } /*********OLED写命令********/ void__inlineoled12864_wr_cmd(u8data) { OLED12864_CS_L;//拉低CS OLED12864_DC=OLED_LOW; manual_spi_sendbyte(data); OLED12864_CS_H;//拉低CS } #endif #ifdefOLED_SPI /*********oled写数据********/ void__inlineoled12864_wr_data(u8data) { intn; OLED12864_CS_L; OLED12864_DC=OLED_HIGH; SPI1->DR=data; //while(SPI1->SR&0x0080);//等待BSY变成0 for(n=0;n<9;n++); OLED12864_CS_H; } /*********OLED写命令********/ void__inlineoled12864_wr_cmd(u8data) { intn; OLED12864_CS_L;//拉低CS OLED12864_DC=OLED_LOW; SPI1->DR=data; //while(SPI1->SR&0x0080);//等待BYS变成0 for(n=0;n<9;n++); OLED12864_CS_H;//拉低CS } #endif //#defineoled12864_wr_cmd(data)OLED12864_8080_DATA=data;\ //OLED12864_DC_L;\ //OLED12864_WR_L;\ //OLED12864_WR_H;\ //OLED12864_DC_H; /**********oled设置坐标********/ void__inlineoled12864_set_pos(u8x,u8y) { oled12864_wr_cmd(0xb0+y); oled12864_wr_cmd((x>>4)|0x10); oled12864_wr_cmd(x&0x0f); } /*********************LCD全屏************************************/ voidoled12864_fill_full(unsignedcharbmp_dat); /*********************LCD复位************************************/ voidoled12864_cls(void); /*********************LCD初始化************************************/ voidoled12864_init(void); /******************画点,无x,y值审查******************************/ voidoled12864_draw_point(u8x,u8y,u8white_black); //放一个8×6字符串 voidoled12864_put_86char(charcolumn6,charrow,char*ch); //按照默认方式显示一行数据,并清空下一行 voidoled12864_printf(char*ch); //oled内容按oled_buf[]刷新 voidoled12864_refresh(void); #endif /*_____________________________codetab.h______*/ #ifndef__CODETAB_H__ #define__CODETAB_H__ /************************************6*8的点阵************************************/ constunsignedcharF6x8[][6]= { 0x00,0x00,0x00,0x00,0x00,0x00,//sp 0x00,0x00,0x00,0x2f,0x00,0x00,//! 0x00,0x00,0x07,0x00,0x07,0x00,//" 0x00,0x14,0x7f,0x14,0x7f,0x14,//# 0x00,0x24,0x2a,0x7f,0x2a,0x12,//$ 0x00,0x62,0x64,0x08,0x13,0x23,//% 0x00,0x36,0x49,0x55,0x22,0x50,//& 0x00,0x00,0x05,0x03,0x00,0x00,//' 0x00,0x00,0x1c,0x22,0x41,0x00,//( 0x00,0x00,0x41,0x22,0x1c,0x00,//) 0x00,0x14,0x08,0x3E,0x08,0x14,//* 0x00,0x08,0x08,0x3E,0x08,0x08,//+ 0x00,0x00,0x00,0xA0,0x60,0x00,//, 0x00,0x08,0x08,0x08,0x08,0x08,//- 0x00,0x00,0x60,0x60,0x00,0x00,//. 0x00,0x20,0x10,0x08,0x04,0x02,/// 0x00,0x3E,0x51,0x49,0x45,0x3E,//0 0x00,0x00,0x42,0x7F,0x40,0x00,//1 0x00,0x42,0x61,0x51,0x49,0x46,//2 0x00,0x21,0x41,0x45,0x4B,0x31,//3 0x00,0x18,0x14,0x12,0x7F,0x10,//4 0x00,0x27,0x45,0x45,0x45,0x39,//5 0x00,0x3C,0x4A,0x49,0x49,0x30,//6 0x00,0x01,0x71,0x09,0x05,0x03,//7 0x00,0x36,0x49,0x49,0x49,0x36,//8 0x00,0x06,0x49,0x49,0x29,0x1E,//9 0x00,0x00,0x36,0x36,0x00,0x00,//: 0x00,0x00,0x56,0x36,0x00,0x00,//; 0x00,0x08,0x14,0x22,0x41,0x00,//< 0x00,0x14,0x14,0x14,0x14,0x14,//= 0x00,0x00,0x41,0x22,0x14,0x08,//> 0x00,0x02,0x01
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 12864 OLED 简单 显示 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)