您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 12864的OLED简单显示程序=
OLED12864程序.哥瞎写的/*___________________________OLED12864.c_____*/#includestm32f4xx.h#includeoled12864.h#includecodetab.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;y8;y++){oled12864_wr_cmd(0xb0+y);oled12864_wr_cmd(0x01);oled12864_wr_cmd(0x10);for(x=0;xX_WIDTH;x++){//oled12864_delay(10000);oled12864_wr_data(bmp_dat);}}OLED12864_CS=1;}/*********************LCD复位************************************/voidoled12864_cls(void){unsignedchary,x;OLED12864_CS=0;//使能片选for(y=0;y8;y++){oled12864_wr_cmd(0xb0+y);oled12864_wr_cmd(0x01);oled12864_wr_cmd(0x10);for(x=0;xX_WIDTH;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);//--turnoffoledpaneloled12864_wr_cmd(0x00);//---setlowcolumnaddressoled12864_wr_cmd(0x10);//---sethighcolumnaddressoled12864_wr_cmd(0x3f);//--setstartlineaddressSetMappingRAMDisplayStartLine(0x00~0x3F)oled12864_wr_cmd(0x81);//--setcontrastcontrolregisteroled12864_wr_cmd(0xcf);//SetSEGOutputCurrentBrightnessoled12864_wr_cmd(0xa0);//--SetSEG/ColumnMapping0xa0左右反置0xa1正常oled12864_wr_cmd(0xc0);//SetCOM/RowScanDirection0xc0上下反置0xc8正常oled12864_wr_cmd(0xa6);//--setnormaldisplayoled12864_wr_cmd(0xa8);//--setmultiplexratio(1to64)oled12864_wr_cmd(0x3f);//--1/64dutyoled12864_wr_cmd(0xd3);//-setdisplayoffsetShiftMappingRAMCounter(0x00~0x3F)oled12864_wr_cmd(0x00);//-notoffsetoled12864_wr_cmd(0xd5);//--setdisplayclockdivideratio/oscillatorfrequencyoled12864_wr_cmd(0x80);//--setdivideratio,SetClockas100Frames/Secoled12864_wr_cmd(0xd9);//--setpre-chargeperiodoled12864_wr_cmd(0xf1);//SetPre-Chargeas15Clocks&Dischargeas1Clockoled12864_wr_cmd(0xda);//--setcompinshardwareconfigurationoled12864_wr_cmd(0x12);oled12864_wr_cmd(0xdb);//--setvcomholed12864_wr_cmd(0x40);//SetVCOMDeselectLeveloled12864_wr_cmd(0x20);//-SetPageAddressingMode(0x00/0x01/0x02)oled12864_wr_cmd(0x02);//oled12864_wr_cmd(0x8d);//--setChargePumpenable/disableoled12864_wr_cmd(0x14);//--set(0x10)disableoled12864_wr_cmd(0xa4);//DisableEntireDisplayOn(0xa4/0xa5)oled12864_wr_cmd(0xa6);//DisableInverseDisplayOn(0xa6/a7)oled12864_wr_cmd(0xaf);//--turnonoledpaneloled12864_fill_full(0x02);//初始清屏oled12864_set_pos(0,0);default_prt_nowrow=DEFAULT_PRT_START_ROW;OLED12864_CS=1;}//无x,y值审查//white为1,black为0voidoled12864_draw_point(u8x,u8y,u8white_black){u8tmp1,tmp2;staticu8pre_x,pre_y;tmp2=(y%8);tmp2=1tmp2;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~7voidoled12864_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_nowrowDEFAULT_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;y8;y++){oled12864_set_pos(0,y);OLED12864_DC_DATA;OLED12864_CS=0;//使能片选for(x=0;xX_WIDTH;x++){u16Tmp=oled_buf[y][x];//oled12864_delay(10000);//while(SPI1-SR&0x0080);//等待BSY变成0for(nCount=0;nCount9;nCount++);SPI1-DR=u16Tmp;//oled12864_wr_data(oled_buf[y][x]);}}OLED12864_CS=1;}/*___________________________OLED12864.h_____*/#ifndef__OLED12864_H__#define__OLED12864_H__#includestm32f4_bitband.h#includemanual_SPI.h#defineOLED12864_DCPAout(8)#defineOLED12864_DC_HGPIOA-BSRRL=18#defineOLED12864_DC_LGPIOA-BSRRH=18#defineOLED12864_DC_DATAOLED12864_DC_H#defineOLED12864_DC_CMDOLED12864_DC_L#defineOLED12864_RSTPAout(3)#defineOLED12864_CSPAout(4)#defineOLED12864_CS_HGPIOA-BSRRL=14#defineOLED12864_CS_LGPIOA-BSRRH=14#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写数据********///注意,没有片选,需
本文标题:12864的OLED简单显示程序=
链接地址:https://www.777doc.com/doc-4630706 .html