|
这是oled 源码哦,挺有用的 山外库很少的
源程序:
- /**********************************
- **日期:2017/1/20
- **作者:King
- **功能:驱动 128*64 OLED
- ***********************************/
- #include "codetab.h"
- #include "oled.h"
- #include "MK60_spi.h"
- #include "MK60_gpio.h"
- //#include "VCAN_camera.h"
- const uint8 F14x16_Idx[] =
- {
- "芜湖蓝宙电子为您服务"
- };
- const uint8 F14x16[] = {
- 0x0C,0xCC,0xCC,0xDE,0xDE,0xCC,0xCC,0xCC,0xDE,0xDE,0xCC,0xCC,0x0C,0x00,
- 0xC6,0xC6,0x66,0x36,0x1E,0x0F,0x07,0x7E,0xFE,0xC6,0xC6,0xC6,0xE6,0xE0,/*"芜",0*/
- 0x64,0xCC,0x18,0x30,0xFE,0xFE,0x30,0x30,0xFC,0x4C,0x4C,0xFC,0xFC,0x00,
- 0xF0,0x3C,0x00,0x3F,0x19,0x19,0x9F,0xC0,0x7F,0x04,0xC4,0xFF,0x7F,0x00,/*"湖",0*/
- 0x04,0x04,0xE4,0x04,0x0F,0xF4,0x04,0x04,0xF4,0x44,0xCF,0x44,0x44,0x44,0x04,0x00,
- 0x40,0x40,0x7D,0x44,0x44,0x7D,0x44,0x45,0x44,0x7C,0x44,0x45,0x7C,0x40,0x40,0x00,
- 0x10,0x0C,0xC4,0x44,0x44,0x44,0x45,0xF6,0x44,0x44,0x44,0x44,0xC4,0x14,0x0C,0x00,
- 0x00,0x00,0xFF,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,
- 0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
- 0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,
- 0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,
- 0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x60,0x60,0x64,0x7C,0x78,0xE0,0xFE,0x7E,0x60,0x60,0x60,0xE0,0xE0,0x00,
- 0xC0,0x60,0x30,0x18,0x0C,0x07,0x03,0x0C,0xD8,0xD0,0xC0,0x7F,0x3F,0x00,/*"为",0*/
- 0x30,0xF8,0xFE,0x06,0x30,0xB8,0x9E,0x1E,0xF8,0xF8,0x18,0xB8,0xB8,0x00,
- 0x60,0x73,0x03,0x78,0xF9,0xC1,0xC8,0xDB,0xD3,0xE1,0x60,0x18,0x31,0x21,/*"您",0*/
- 0xFE,0xFE,0x66,0xFE,0xFE,0x00,0xFE,0xFE,0x86,0xB6,0xB6,0xBE,0x9E,0x00,
- 0xFF,0x3F,0xC6,0xFF,0x7F,0x00,0xFF,0xFF,0x41,0x6F,0x31,0x7F,0xE7,0x40,/*"服",0*/
- 0x00,0x20,0x30,0x98,0xBE,0xEE,0xCC,0xCC,0xEC,0xBC,0x1C,0x00,0x00,0x00,
- 0xC3,0xC3,0xCF,0x6D,0x7D,0x3E,0x0E,0x0C,0xCD,0xFD,0x7F,0x03,0x03,0x01,/*"务",0*/
- };
-
- //******************************
- //功能说明:初始化GPIO
- //函数返回:无
- //修改时间:2017/1/20
- //备注:无
- //******************************
- void Init_gpio ()
- {
- gpio_init (PTD3, GPO, 1);
- gpio_init (PTD4, GPO, 1);
- }
- //********************************
- //功能说明:初始化SPI
- //函数返回:无
- //修改时间:2017/1/20
- //备注:无
- //********************************
- void Init_SPI ()
- {
- spi_init(SPI,SPI_CS, MASTER,40*1000*1000);
- }
- //******************************
- //功能说明:LCD写数据
- //参数说明:dat 写入八位数据
- //函数返回:无
- //修改时间:2017/1/20
- //备注:无
- //******************************
- void LCD_WrDat(uint8 dat)
- {
- uint8 buff;
-
- DC = 1;
- spi_mosi(SPI,SPI_CS,&dat,&buff,1);
- }
- //******************************
- //功能说明:LCD写命令
- //参数说明:dat 写入八位数据
- //函数返回:无
- //修改时间:2017/1/20
- //备注:无
- //******************************
- void LCD_WrCmd(uint8 cmd)
- {
- uint8 buff;
-
- DC = 0;
- spi_mosi(SPI,SPI_CS,&cmd,&buff,1);
- }
- //******************************
- //功能说明:LCD 设置坐标
- //参数说明:x 0~128
- // y 0~64
- //函数返回:无
- //修改时间:2014/6/12
- //备注:无
- //******************************
- void LCD_Set_Pos(uint8 x, uint8 y)
- {
- LCD_WrCmd(0xb0 + y);
- LCD_WrCmd(((x&0xf0)>>4)|0x10);
- LCD_WrCmd((x&0x0f)|0x01);
-
- }
- //******************************
- //功能说明:LCD 全屏
- //参数说明:
- //函数返回:无
- //修改时间:2014/6/12
- //备注:无
- //******************************
- void LCD_Fill(uint8 bmp_dat)
- {
- uint8 y,x;
- for(y=0;y<8;y++)
- {
- LCD_WrCmd(0xb0+y);
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=0;x<X_WIDTH;x++)
- LCD_WrDat(bmp_dat);
- }
- }
- //******************************
- //功能说明:LCD 复位
- //参数说明:无
- //函数返回:无
- //修改时间:2014/6/12
- //备注:无
- //******************************
- void LCD_CLS(void)
- {
- uint8 y,x;
- for(y=0;y<8;y++)
- {
- LCD_WrCmd(0xb0+y);
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=0;x<X_WIDTH;x++)
- LCD_WrDat(0);
- }
- }
- //******************************
- //功能说明:LCD 初始化
- //参数说明:无
- //函数返回:无
- //修改时间:2014/6/12
- //备注:无
- //******************************
- void LCD_Init(void)
- {
- Init_SPI();
- Init_gpio ();
- RST = 0; /* 产生一个让LCD复位的低电平脉冲 */
- systick_delay_ms(100);
- RST = 1;
- systick_delay_ms(50);
-
- LCD_WrCmd(0xae);//--turn off oled panel
- LCD_WrCmd(0x00);//---set low column address
- LCD_WrCmd(0x10);//---set high column address
- LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
- LCD_WrCmd(0x81);//--set contrast control register
- LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
- LCD_WrCmd(0xa0);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
- LCD_WrCmd(0xc0);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
- LCD_WrCmd(0xa6);//--set normal display
- LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
- LCD_WrCmd(0x3f);//--1/64 duty
- LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
- LCD_WrCmd(0x00);//-not offset
- LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
- LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
- LCD_WrCmd(0xd9);//--set pre-charge period
- LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- LCD_WrCmd(0xda);//--set com pins hardware configuration
- LCD_WrCmd(0x12);
- LCD_WrCmd(0xdb);//--set vcomh
- LCD_WrCmd(0x40);//Set VCOM Deselect Level
- LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
- LCD_WrCmd(0x02);//
- LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
- LCD_WrCmd(0x14);//--set(0x10) disable
- LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
- LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
- LCD_WrCmd(0xaf);//--turn on oled panel
- LCD_Fill(0x00); //初始清屏
- LCD_Set_Pos(0,0);
- }
- //******************************
- //功能说明:显示6*8一组标准ASCII字符串
- //参数说明:显示的坐标(x,y),y为页范围0~7
- //函数返回:无
- //修改时间:2014/6/21
- //备注:无
- //******************************
- void LCD_P6x8Str(uint8 x,uint8 y, uint8 ch[],uint8 set)
- {
- uint8 c = 0, i = 0, j = 0;
- while(ch[j]!='\0')
- {
- c = ch[j] - 32;
- if(x > 126)
- {
- x = 0;
- y++;
- }
- LCD_Set_Pos(x, y);
- for(i = 0;i < 6;i++)
- {
- if(set == 0) LCD_WrDat( F6x8[c][i]);
- else LCD_WrDat(~F6x8[c][i]);
- }
- x+=6;
- j++;
- }
- }
- //******************************
- //功能说明:显示8*16一组标准ASCII字符串
- //参数说明:显示的坐标(x,y),y为页范围0~7
- //函数返回:无
- //修改时间:2014/6/21
- //备注:无
- //******************************
- void LCD_P8x16Str(uint8 x,uint8 y, uint8 ch[], uint8 set)
- {
- uint8 c = 0, i = 0, j = 0;
- while(ch[j]!='\0')
- {
- c = ch[j] - 32;
- if(x > 126)
- {
- x = 0;
- y++;
- }
- LCD_Set_Pos(x, y);
- for(i = 0;i < 8;i++)
- {
- if(set == 0) LCD_WrDat( F8x16[i+c*16]);
- else LCD_WrDat(~F8x16[i+c*16]);
- }
- LCD_Set_Pos(x,y+1);
- for(i = 0;i < 8;i++)
- {
- if(set == 0) LCD_WrDat( F8x16[i+8+c*16]);
- else LCD_WrDat(~F8x16[i+8+c*16]);
- }
- x+=8;
- j++;
- }
- }
- //******************************
- //功能说明:显示16*16点阵
- //参数说明:显示的坐标(x,y),y为页范围0~7
- //函数返回:无
- //修改时间:2014/6/21
- //备注:无
- //******************************
- void LCD_P16x16Ch(uint8 x, uint8 y, uint8 N)
- {
- uint8 wm = 0;
- uint16 adder = 32*N;
- LCD_Set_Pos(x, y);
- for(wm = 0;wm < 16;wm++)
- {
- LCD_WrDat(F16x16[adder]);
- adder+=1;
- }
- LCD_Set_Pos(x, y+1);
- for(wm = 0;wm < 16;wm++)
- {
- LCD_WrDat(F16x16[adder]);
- adder+=1;
- }
- }
- //******************************
- //功能说明:显示显示BMP图片128×64起始点坐标(x,y)
- //参数说明:显示的坐标(x,y),y为页范围0~7
- //函数返回:无
- //修改时间:2014/6/21
- //备注:无
- //******************************
- void Draw_BMP(uint8 x0, uint8 y0,uint8 x1,uint8 y1,uint8 BMP[])
- {
- uint16 j = 0;
- uint8 x, y;
- if(y1%8 == 0)
- y = y1/8;
- else
- y = y1/8 + 1;
- for(y = y0;y < y1;y++)
- {
- LCD_Set_Pos(x0, y);
- for(x = x0;x < x1;x++)
- LCD_WrDat(BMP[j++]);
- }
- }
- /*void Draw_Logo(uint8 x0, uint8 y0,uint8 x1, uint8 y1,uint8 Logo[])
- {
- uint16 j=0;
- uint8 x,y;
-
- if(y1%8==0)
- y=y1/8;
- else
- y=y1/8+1;
- for(y=y0;y<y1;y++)
- {
- LCD_Set_Pos(x0,y);
- for(x=x0;x<x1;x++)
- {
- LCD_WrDat(~Logo[j++]);
- }
- }
- }
- void Draw_Info(uint8 x0, uint8 y0, uint8 *img)
- {
- uint16 j = 0;
- uint8 x, y;
- uint8 img_uint[CAMERA_H/8+1][CAMERA_W];
-
- for(j = 0; j < 7; j++)
- {
- for(uint8 i = 0; i < CAMERA_W; i++)
- {
- for(uint8 k = 0; k < 8; k++)
- {
- img_uint[j][i] >>= 1;
- if(*img != 0) img_uint[j][i] |= 0x80;
- img += 80;
- }
- img -= (80*8-1);
- }
- img += 7*80;
- }
-
- for(uint8 i = 0; i < CAMERA_W; i++)
- {
- for(uint8 k = 0; k < 4; k++)
- {
- img_uint[j][i] >>= 1;
- if(*img != 0) img_uint[j][i] |= 0x80;
- img += 80;
- }
- img_uint[j][i] >>= 4;
- img -= (80*4-1);
- }
-
- for(y = y0;y < y0+8;y++)
- {
- LCD_Set_Pos(x0, y);
- for(x = x0;x < x0+80;x++)
- LCD_WrDat(img_uint[y-y0][x-x0]);
- }
- }
- */
- /*void Draw_line(void)
- {
- char i = 0;
- LCD_Set_Pos(20, 3);
- for(i = 0;i < 14;i++)
- {
- LCD_WrDat(0x20);
- }
- LCD_WrDat(0x04);
- LCD_WrDat(0x88);
- LCD_WrDat(0x70);
- LCD_WrDat(0x20);
- LCD_Set_Pos(34, 4);
- LCD_WrDat(0x01);
- }*/
- void LCD_P14x16Str(uint8 x,uint8 y,uint8 ch[])
- {
- uint8 wm=0,ii = 0;
- uint16 adder=1;
-
- while(ch[ii] != '\0')
- {
- wm = 0;
- adder = 1;
- while(F14x16_Idx[wm] > 127)
- {
- if(F14x16_Idx[wm] == ch[ii])
- {
- if(F14x16_Idx[wm + 1] == ch[ii + 1])
- {
- adder = wm * 14;
- break;
- }
- }
- wm += 2;
- }
- if(x>118){x=0;y++;}
- LCD_Set_Pos(x , y);
- if(adder != 1)// 显示汉字
- {
- LCD_Set_Pos(x , y);
- for(wm = 0;wm < 14;wm++)
- {
- LCD_WrDat(F14x16[adder]);
- adder += 1;
- }
- LCD_Set_Pos(x,y + 1);
- for(wm = 0;wm < 14;wm++)
- {
- LCD_WrDat(F14x16[adder]);
- adder += 1;
- }
- }
- else //显示空白字符
- {
- ii += 1;
- LCD_Set_Pos(x,y);
- for(wm = 0;wm < 16;wm++)
- {
- LCD_WrDat(0);
- }
- LCD_Set_Pos(x,y + 1);
- for(wm = 0;wm < 16;wm++)
- {
- LCD_WrDat(0);
- }
- }
- x += 14;
- ii += 2;
- }
- }
- void LCD_Print(uint8 x, uint8 y, uint8 ch[])
- {
- uint8 ch2[3];
- uint8 ii=0;
- while(ch[ii] != '\0')
- {
- if(ch[ii] > 127)
- {
- ch2[0] = ch[ii];
- ch2[1] = ch[ii + 1];
- ch2[2] = '\0'; //汉字为两个字节
- LCD_P14x16Str(x , y, ch2); //显示汉字
- x += 14;
- ii += 2;
- }
- else
- {
- ch2[0] = ch[ii];
- ch2[1] = '\0'; //字母占一个字节
- LCD_P8x16Str(x , y , ch2,1); //显示字母
-
- x += 8;
- ii+= 1;
- }
-
- }
- }
- void Dis_Char(unsigned char y,unsigned char x,unsigned char asc)
- {
- unsigned char ch2[2];
- x=x*8;
- ch2[0] = asc;
- ch2[1] = '\0'; //字母占一个字节
- LCD_P6x8Str(x , y , ch2,1); //显示字母
- }
复制代码
|
|