1、 oled12864_wr_cmd(0x10); for(x=0;xX_WIDTH;x+) /oled12864_delay(10000); oled12864_wr_data(bmp_dat); OLED12864_CS = 1;/*LCD复位*/void oled12864_cls(void) oled12864_wr_cmd(0);/*LCD初始化*/void oled12864_init(void) /manual_spi_init(); /MAN_SPI_SCL=1; /MAN_SPI_SDA = 1; OLED12864_DC = 1; OLED12864_RST = 0; ole
2、d12864_delay(400000); OLED12864_RST = 1; /从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 oled12864_wr_cmd(0xae);/-turn off oled panel oled12864_wr_cmd(0x00);/-set low column address/-set high column address oled12864_wr_cmd(0x3f);/-set start line address Set Mapping RAM Display Start Line (0x000x3F) oled12864_wr_cmd(
3、0x81);/-set contrast control register oled12864_wr_cmd(0xcf); / Set SEG Output Current Brightness oled12864_wr_cmd(0xa0);/-Set SEG/Column Mapping 0xa0左右反置 0xa1正常 oled12864_wr_cmd(0xc0);/Set COM/Row Scan Direction 0xc0上下反置 0xc8正常 oled12864_wr_cmd(0xa6);/-set normal display oled12864_wr_cmd(0xa8);/-se
4、t multiplex ratio(1 to 64)/-1/64 duty oled12864_wr_cmd(0xd3);/-set display offset Shift Mapping RAM Counter (0x000x3F)/-not offset oled12864_wr_cmd(0xd5);/-set display clock divide ratio/oscillator frequency oled12864_wr_cmd(0x80);/-set divide ratio, Set Clock as 100 Frames/Sec oled12864_wr_cmd(0xd9
5、);/-set pre-charge period oled12864_wr_cmd(0xf1);/Set Pre-Charge as 15 Clocks & Discharge as 1 Clock oled12864_wr_cmd(0xda);/-set com pins hardware configuration oled12864_wr_cmd(0x12); oled12864_wr_cmd(0xdb);/-set vcomh oled12864_wr_cmd(0x40);/Set VCOM Deselect Level oled12864_wr_cmd(0x20);/-Set Pa
6、ge Addressing Mode (0x00/0x01/0x02) oled12864_wr_cmd(0x02);/ oled12864_wr_cmd(0x8d);/-set Charge Pump enable/disable oled12864_wr_cmd(0x14);/-set(0x10) disable oled12864_wr_cmd(0xa4);/ Disable Entire Display On (0xa4/0xa5)/ Disable Inverse Display On (0xa6/a7) oled12864_wr_cmd(0xaf);/-turn on oled p
7、anel oled12864_fill_full(0x02); /初始清屏 oled12864_set_pos(0,0); default_prt_nowrow = DEFAULT_PRT_START_ROW;/无x,y值审查/white为1,black为0void oled12864_draw_point(u8 x, u8 y, u8 white_black) u8 tmp1,tmp2; static u8 pre_x,pre_y; tmp2 = (y%8); tmp2 = 1 = 3; if(white_black) tmp1 = oled_bufyx;/取得当前值 tmp1 |= tmp
8、2; else tmp1 &= (!tmp2); oled_bufyx = tmp1;/放一个86字符串/注意column是0128,row是07void oled12864_put_86char(char column6, char row ,char *ch) char ncount = 0; char c; char max_ncount = (X_WIDTH - column6) / 6; while(chncount != 0 & ncount DEFAULT_PRT_END_ROW) oled12864_put_86char(0,default_prt_nowrow,-);/ole
9、d内容按oled_buf刷新void oled12864_refresh(void) u16 u16Tmp; int nCount; oled12864_set_pos(0, y); OLED12864_DC_DATA; u16Tmp = oled_bufyx; /while( SPI1-SR & 0x0080 );/等待BSY变成0 for(nCount=0;nCountDR = u16Tmp; /oled12864_wr_data( oled_bufyx );/*_OLED12864.h_*/#ifndef _OLED12864_H_#define _OLED12864_H_stm32f4
10、_bitband.hmanual_SPI.h#define OLED12864_DC PAout(8)#define OLED12864_DC_H GPIOA-BSRRL = 1BSRRH = 14#define OLED12864_CS_L GPIOA-#define OLED_SPI /用手动SPI方式#define OLED_HIGH 1#define OLED_LOW 0#define OLED_DC_C 0#define OLED_DC_D 1#define XLevelL 0x00#define XLevelH 0x10#define XLevel (XLevelH&0x0F)*1
11、6+XLevelL)#define Max_Column 128#define Max_Row 64#define Brightness 0xCF #define X_WIDTH 128#define Y_WIDTH 64#define OLED_BLACK_POINT 0#define OLED_WHITE_POINT 1 #define OLED_COLUMN6(x) (x*6)void oled12864_delay( int n_count );/*oled写数据*/注意,没有片选,需要在调用函数中片选#ifdef OLED_8080#define OLED12864_WR PAout
12、(6)#define OLED12864_WR_H GPIOA-6#define OLED12864_WR_L GPIOA-#define OLED12864_RD PAout(7)#define OLED12864_RD_H GPIOA-7#define OLED12864_RD_L GPIOA-#define OLED12864_8080_DATA GPIOB-ODRvoid _inline oled12864_wr_data( u8 data ) OLED12864_8080_DATA = data; OLED12864_DC_H;/写数据信号 /OLED12864_CS = 0; OL
13、ED12864_WR_L;/写信号 OLED12864_WR_H; /OLED12864_CS = 1;/*OLED写命令*/void _inline oled12864_wr_cmd( u8 data ) OLED12864_DC_L;/写命令信号#endif#ifdef OLED_MANUAL_SPI OLED12864_CS_L;/拉低CS OLED12864_DC = OLED_HIGH; manual_spi_sendbyte( data ); OLED12864_DC = OLED_LOW; OLED12864_CS_H;#ifdef OLED_SPI int n;DR = dat
14、a; /while(SPI1- 0x0080); for(n=0;n 4) | 0x10 ); oled12864_wr_cmd( x & 0x0f );void oled12864_fill_full(unsigned char bmp_dat);void oled12864_cls(void);void oled12864_init(void);/*画点,无x,y值审查*/void oled12864_draw_point(u8 x, u8 y, u8 white_black);void oled12864_put_86char(char column6, char row ,char *
15、ch);void oled12864_printf(char *ch);void oled12864_refresh(void);/*_codetab.h_*/#ifndef _CODETAB_H_#define _CODETAB_H_/*6*8的点阵*/const unsigned char F6x86 = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/ sp0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,/ !0x00, 0x00, 0x07, 0x00, 0x07, 0x00,/ 0x00, 0x14, 0x7f, 0x14, 0x7f,
16、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, 0x0
17、8, 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,/ 00x00, 0x00, 0x42, 0x7F, 0x40, 0x00,/ 10x00, 0x42, 0x61, 0x51, 0x49, 0x46,/ 20x00, 0x21, 0x41, 0x45,
18、 0x4B, 0x31,/ 30x00, 0x18, 0x14, 0x12, 0x7F, 0x10,/ 40x00, 0x27, 0x45, 0x45, 0x45, 0x39,/ 50x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,/ 60x00, 0x01, 0x71, 0x09, 0x05, 0x03,/ 70x00, 0x36, 0x49, 0x49, 0x49, 0x36,/ 80x00, 0x06, 0x49, 0x49, 0x29, 0x1E,/ 90x00, 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,