久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
OLED 3.12寸 256*64 SSD132的stm32f103單片機驅動程序
[打印本頁]
作者:
cici8718
時間:
2018-8-9 17:37
標題:
OLED 3.12寸 256*64 SSD132的stm32f103單片機驅動程序
OLED 3.12寸 256*64 驅動程序 stm32f103
0.png
(213.19 KB, 下載次數: 83)
下載附件
2018-8-9 23:52 上傳
0.png
(51.65 KB, 下載次數: 71)
下載附件
2018-8-9 23:53 上傳
單片機源程序如下:
/*
MOD:25664 (dots:256*64)
IC : SSD1322 (加入圖片測試功能)
MCU: W78E516D 12MHZ
//============================
說明:6800:BS0=1,BS1=1;
8080:BS0=0,BS1=1; (默認)
3-SPI:BS0=1,BS1=0;
4-SPI:BS0=0,BS1=0;
*/
/* 接口定義:
1. VSS--------------GND
2. VDD--------------+3.3V
3. NC
4. DB0--------------P1.0
5. DB1--------------P1.1
6. DB2--------------P1.2
7. DB3--------------P1.3
8. DB4--------------P1.4
9. DB5--------------P1.5
10. DB6--------------P1.6
11. DB7--------------P1.7
12. RD/E-------------P3.4
13. WR---------------P3.3
14. DC/A0------------P3.2
15. RST--------------P3.1
16. CS---------------P3.0
*/
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define xData P1
#define Shift 0x1C
uchar data_4byte[4];
void delayus(uchar m);
void delayms(uchar m);
void change (uchar dat);
void Fill_RAM(unsigned char Data) ;
void send_2bit(unsigned char two_bit_data);
unsigned char code bmp25664_0[];
unsigned char code bmp25664_1[];
void display_graphic_256x64_0();
void display_graphic_256x64_1();
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Global Variables
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#define Shift 0x1C
#define Max_Column 0x3F // 256/4-1
#define Max_Row 0x3F // 64-1
#define Brightness 0x0F
//#define SPI
#define I80
//#define M68
sbit REST=P3^1; // Reset
sbit CS=P3^0; // Chip Select
sbit DC=P3^2; // Data/Command Control
/*
//6800
sbit RW=P3^3; // Write Signal
sbit E=P3^4; // E Signal
*/
//8080
sbit _WR=P3^3; //80
sbit _RD=P3^4; //80
/*
//SPI
sbit SCLK=P1^0; //spi
sbit SDIN=P1^1; //spi
*/
uchar code tab88[]={
0x0e,0x11,0x13,0x15,0x19,0x11,0x0e,0x00,// 0 代碼"10"
0x04,0x0c,0x04,0x04,0x04,0x04,0x0e,0x00,//1 代碼"11"
0x0e,0x11,0x01,0x02,0x04,0x08,0x1f,0x00,//2 代碼"12"
0x1f,0x02,0x04,0x02,0x01,0x11,0x0e,0x00,// 3 代碼"13"
0x02,0x06,0x0a,0x12,0x1f,0x02,0x02,0x00,// 4 代碼"14"
0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e,0x00,// 5 代碼"15"
0x06,0x08,0x10,0x1e,0x11,0x11,0x0e,0x00,// 6 代碼"16"
0x1f,0x01,0x02,0x04,0x04,0x04,0x04,0x00,// 7 代碼"17"
0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e,0x00,// 8 代碼"18"
0x0e,0x11,0x11,0x0e,0x01,0x02,0x0c,0x00,// 9 代碼"19"
0x0e,0x11,0x11,0x11,0x1f,0x11,0x11,0x00,// A 代碼"21"
0x11,0x11,0x11,0x1f,0x11,0x11,0x11,0x00,// H 代碼"28"
0x0e,0x04,0x04,0x04,0x04,0x04,0x0e,0x00,// I 代碼"29"
0x07,0x02,0x02,0x02,0x02,0x12,0x0c,0x00,// J 代碼"2A"
0x11,0x12,0x14,0x18,0x14,0x12,0x11,0x00,// K 代碼"2B"
0x10,0x10,0x10,0x10,0x10,0x10,0x1f,0x00,// L 代碼"2C"
0x11,0x1b,0x15,0x11,0x11,0x11,0x11,0x00,// M 代碼"2D"
0x11,0x19,0x19,0x15,0x13,0x13,0x11,0x00,// N 代碼"2E"
0x0e,0x11,0x11,0x11,0x11,0x11,0x0e,0x00,// O 代碼"2F"
0x1e,0x11,0x11,0x1e,0x10,0x10,0x10,0x00,// P 代碼"30"
0x0e,0x11,0x11,0x11,0x15,0x12,0x0b,0x00,// Q 代碼"31"
0x1e,0x11,0x11,0x1e,0x14,0x12,0x11,0x00,//R 代碼"32"
0x0e,0x11,0x10,0x0e,0x01,0x11,0x0e,0x00,// S 代碼"33"
0x1f,0x04,0x04,0x04,0x04,0x04,0x04,0x00,// T 代碼"34"
0x11,0x11,0x11,0x11,0x11,0x11,0x0e,0x00,// U 代碼"35"
0x11,0x11,0x11,0x11,0x11,0x0a,0x04,0x00,// V 代碼"36"
0x11,0x11,0x11,0x15,0x15,0x1b,0x11,0x00,// W 代碼"37"
0x11,0x11,0x0a,0x04,0x0a,0x11,0x11,0x00,// X 代碼"38"
0x11,0x11,0x11,0x0a,0x04,0x04,0x04,0x00,// Y 代碼"39"
0x1f,0x01,0x02,0x04,0x08,0x10,0x1f,0x00,// Z 代碼"3A"
0x0e,0x08,0x08,0x08,0x08,0x08,0x0e,0x00,// [ 代碼"3B"
0x00,0x10,0x08,0x04,0x02,0x01,0x00,0x00,// \ 代碼"3C"
0x0e,0x02,0x02,0x02,0x02,0x02,0x0e,0x00,// ] 代碼"3D"
0x04,0x0a,0x11,0x00,0x00,0x00,0x00,0x00,// ^ 代碼"3E"
0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,// _ 代碼"3F"
0x10,0x08,0x04,0x00,0x00,0x00,0x00,0x00,// ` 代碼"40"
0x00,0x00,0x0e,0x01,0x0f,0x11,0x0f,0x00,// a 代碼"41"
0x10,0x10,0x16,0x19,0x11,0x11,0x1e,0x00,// b 代碼"42"
0x00,0x00,0x0e,0x11,0x10,0x11,0x0e,0x00,// c 代碼"43"
0x01,0x01,0x0d,0x13,0x11,0x11,0x0f,0x00,// d 代碼"44"
0x00,0x00,0x0e,0x11,0x1f,0x10,0x0e,0x00,// e 代碼"45"
0x02,0x05,0x04,0x0e,0x04,0x04,0x04,0x00,// f 代碼"46"
0x00,0x0d,0x13,0x13,0x0d,0x01,0x0e,0x00,// g 代碼"47"
0x10,0x10,0x16,0x19,0x11,0x11,0x11,0x00,// h 代碼"48"
0x04,0x00,0x0c,0x04,0x04,0x04,0x0e,0x00,// i 代碼"49"
0x02,0x00,0x06,0x02,0x02,0x12,0x0c,0x00,// j 代碼"4A"
0x08,0x08,0x09,0x0a,0x0c,0x0a,0x09,0x00,//k 代碼"4B"
0x0c,0x04,0x04,0x04,0x04,0x04,0x0e,0x00,// l 代碼"4C"
0x00,0x00,0x1a,0x15,0x15,0x15,0x15,0x00,// m 代碼"4D"
0x00,0x00,0x16,0x19,0x11,0x11,0x11,0x00,// n 代碼"4E"
0x00,0x00,0x0e,0x11,0x11,0x11,0x0e,0x00,// o 代碼"4F"
0x00,0x16,0x19,0x19,0x16,0x10,0x10,0x00,// p 代碼"50"
0x00,0x0d,0x13,0x13,0x0d,0x01,0x01,0x00,// q 代碼"51"
0x00,0x00,0x16,0x19,0x10,0x10,0x10,0x00,// r 代碼"52"
0x00,0x00,0x0f,0x10,0x1e,0x01,0x1f,0x00,// s 代碼"53"
0x08,0x08,0x1c,0x08,0x08,0x09,0x06,0x00,// t 代碼"54"
0x00,0x00,0x12,0x12,0x12,0x12,0x0d,0x00,// u 代碼"55"
0x00,0x00,0x11,0x11,0x11,0x0a,0x04,0x00,// v 代碼"56"
0x00,0x00,0x11,0x11,0x15,0x15,0x0a,0x00,// w 代碼"57"
0x00,0x00,0x11,0x0a,0x04,0x0a,0x11,0x00,// x 代碼"58"
0x00,0x00,0x11,0x11,0x13,0x0d,0x01,0x0e,// y 代碼"59"
};
uchar code tab816[160]={
/*-- 文字: Q --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,
/*-- 文字: T --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,
/*-- 文字: S --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00,
/*-- 文字: 2 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,
/*-- 文字: 5 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
/*-- 文字: 6 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: X --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00,
/*-- 文字: 6 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: 4 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,
/*-- 文字: 1 --*/
/*-- Times New Roman12; 此字體下對應的點陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
};
uchar code tab1616[]={
/* 點陣:16x16
提取點陣方向:橫向取模(先左->右, 再上->下)
字節掉轉:否
字節方式:C語言 */
//===================================
/*-- 文字: 深 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x00,0x7F,0xFC,0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0x44,0x44,0x24,0x44,
0x24,0x48,0x14,0x48,0x14,0x50,0x04,0x40,0x04,0x40,0x04,0x40,0xFF,0xFE,0x00,0x00,
/*-- 文字: 圳 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x10,0x20,0x14,0x11,0xD2,0x00,0x12,0xFC,0x10,0x0B,0xFE,0x08,0x10,0x48,0x90,
0x28,0x90,0x12,0xD0,0x12,0x90,0x2A,0x90,0x2A,0x8A,0x4A,0xEA,0x87,0x06,0x02,0x02,
/*-- 文字: 秦 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x0A,0x01,0x02,0x01,0x02,0x00,0xFE,
/*-- 文字: 唐 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x00,0x7F,0xF8,0x00,0x10,0x00,0x20,0x00,0x40,0x01,0x80,0x01,0x00,0xFF,0xFE,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,
/*-- 文字: 科 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x08,0x10,0x1D,0x10,0xF0,0x90,0x10,0x90,0x10,0x10,0xFD,0x10,0x10,0x90,0x38,0x90,
0x34,0x10,0x50,0x1E,0x53,0xF0,0x90,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
/*-- 文字: 技 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x10,0x20,0x10,0x20,0x10,0x20,0x13,0xFE,0xFC,0x20,0x10,0x20,0x10,0x20,0x15,0xFC,
0x18,0x84,0x30,0x88,0xD0,0x48,0x10,0x50,0x10,0x20,0x10,0x50,0x51,0x88,0x26,0x06,
/*-- 文字: 有 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x02,0x00,0x02,0x00,0xFF,0xFE,0x04,0x00,0x04,0x00,0x0F,0xF0,0x08,0x10,0x18,0x10,
0x2F,0xF0,0x48,0x10,0x88,0x10,0x0F,0xF0,0x08,0x10,0x08,0x10,0x08,0x50,0x08,0x20,
/*-- 文字: 限 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x00,0x7B,0xF8,0x4A,0x08,0x52,0x08,0x53,0xF8,0x62,0x08,0x52,0x08,0x4B,0xF8,
0x4A,0x44,0x4A,0x48,0x6A,0x30,0x52,0x20,0x42,0x10,0x42,0x88,0x43,0x06,0x42,0x00,
/*-- 文字: 公 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x80,0x04,0x80,0x04,0x80,0x08,0x40,0x08,0x40,0x10,0x20,0x20,0x10,0x42,0x08,
0x82,0x06,0x04,0x00,0x04,0x40,0x08,0x20,0x10,0x20,0x3F,0xF0,0x10,0x10,0x00,0x00,
/*-- 文字: 司 --*/
/*-- 宋體12; 此字體下對應的點陣為:寬x高=16x16 --*/
0x00,0x00,0x3F,0xF8,0x00,0x08,0x00,0x08,0x7F,0xE8,0x00,0x08,0x00,0x08,0x1F,0x88,
0x10,0x88,0x10,0x88,0x10,0x88,0x10,0x88,0x1F,0x88,0x10,0x88,0x00,0x28,0x00,0x10,
};
/*********************
延時子程序
********************/
void delayus(uchar m)
{
while(--m);
}
void delayms(uchar m)
{
uchar i,j;
for(i=0;i<102;i++)
for(j=0;j<m;j++)
delayus(1);
}
void delay(uchar m)
{
uchar i,j;
for(i=0;i<100;i++)
for(j=0;j<m;j++)
delayms(1);
}
#ifdef M68
void Write_cmd(unsigned char Data) //68XX方式寫指令子程序
{ DC=0;
CS=0;
RW=0;
xData=Data;
E=1;
_nop_();
_nop_();
E=0;
RW=1;
CS=1;
DC=1;
}
void Write_dat(unsigned char Data) //68XX方式寫數據子程序
{ DC=1;
CS=0;
RW=0;
xData=Data;
E=1;
_nop_();
_nop_();
E=0;
RW=1;
CS=1;
DC=1;
}
#endif
#ifdef I80 // 8-bit 80XX Parallel
void Write_cmd(unsigned char Data)
{
DC=0;
CS=0;
_WR=0;
xData=Data;
_WR=1;
CS=1;
DC=1;
}
void Write_dat(unsigned char Data)
{
DC=1;
CS=0;
_WR=0;
xData=Data;
_WR=1;
CS=1;
DC=1;
}
#endif
#ifdef SPI // 4-wire SPI
void Write_cmd(unsigned char Data)
{
unsigned char i;
CS=0;
DC=0;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
void Write_dat(unsigned char Data)
{
unsigned char i;
CS=0;
DC=1;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
#endif
/********************************************
行,列,起始地址設定,寫入命令定義 一個像素對應4位
********************************************/
void Set_Column_Address(unsigned char a, unsigned char b)
{
Write_cmd(0x15); // Set Column Address
Write_dat(a); // Default => 0x00
Write_dat(b); // Default => 0x77
}
void Set_Row_Address(unsigned char a, unsigned char b)
{
Write_cmd(0x75); // Set Row Address
Write_dat(a); // Default => 0x00
Write_dat(b); // Default => 0x7F
}
void Set_Write_RAM()
{
Write_cmd(0x5C); // Enable MCU to Write into RAM
}
void Set_Remap_Format(unsigned char d)
{
Write_cmd(0xA0); // Set Re-Map / Dual COM Line Mode
Write_dat(d); // Default => 0x40
Write_dat(0x11); // Default => 0x01 (Disable Dual COM Mode)
}
/* ***********************************
//初始化程序
***************************************/
void Initial (void)
{
Write_cmd(0xFD);
Write_dat(0x12); //打開MCU通信
Set_Column_Address(0x1c,0x5b); //256列
Set_Row_Address(0x00,0x3f); //64行
Write_cmd(0xAE); //開休眠
Write_cmd(0xB3); ///驅動和振蕩時鐘
Write_dat(0x91);
Write_cmd(0xCA); ///設定MUX占空比
Write_dat(0x3F);
Write_cmd(0xA2);
Write_dat(0x00); //卷動地址
Write_cmd(0xA1);
Write_dat(0x00); //起始行
Write_cmd(0xA6); //正常顯示
Write_cmd(0xA0);
Write_dat(0x14);
Write_dat(0x11); //掃描方向
Write_cmd(0xB5); ///set gpio
Write_dat(0x00);
Write_cmd(0xAB);
Write_dat(0x01); //內部調節電壓
Write_cmd(0xB4); ///加深顯示Display Enhancement a
Write_dat(0xA0);
Write_dat(0xfd); //0xb5
Write_cmd(0xC1); ///Set Contrast Current
Write_dat(0xaf); //9f
Write_cmd(0xC7); //Master Contrast Current Control
Write_dat(0x0F);
Write_cmd(0xb8); //灰模
Write_dat(0x0c);
Write_dat(0x18);
Write_dat(0x24);
Write_dat(0x30);
Write_dat(0x3c);
Write_dat(0x48);
Write_dat(0x54);
Write_dat(0x60);
Write_dat(0x6c);
Write_dat(0x78);
Write_dat(0x84);
Write_dat(0x90);
Write_dat(0x9c);
Write_dat(0xa8);
Write_dat(0xb4);
Write_cmd(0x00);
Write_cmd(0xB1); //Set Phase Length
Write_dat(0xE2);
Write_cmd(0xD1); //Display Enhancement B
Write_dat(0xa2);
Write_dat(0x20);//反顯
Write_cmd(0xBB);
Write_dat(0x1F);
Write_cmd(0xB6);
Write_dat(0x08);
Write_cmd(0xBE);
Write_dat(0x07);//0.86VCC
Write_cmd(0xA6);//正常顯示
Write_cmd(0xA9);//退部分顯示
Write_cmd(0x5c);
Fill_RAM(0x00);
Write_cmd(0xAF); //關休眠
}
/***************************************
全和間隔列顯示
**************************************/
void Fill_RAM(unsigned char Data)
{
unsigned char i,j;
Set_Column_Address(0x1c,0x5b);
Set_Row_Address(0x00,0x3f);
Set_Write_RAM();
for(i=0;i<64;i++)
{
for(j=0;j<64;j++)
{
Write_dat(Data);
Write_dat(Data);
}
}
}
/*************************Fill Data**************************/
void fill(unsigned char dat1,unsigned char dat2)
{
unsigned char x,y;
Write_cmd(0x15); /*Set Column Address*/
Write_dat(0x00); /*Start Address,start at SEG0*/
Write_dat(0x77); /*End Address,end at SEG479*/
Write_cmd(0x75); /*Set Row address*/
Write_dat(0x00); /*Start Address,start at row0*/
Write_dat(0x7f); /*End Address,end at row127*/
Write_cmd(0x5c); /*Write RAM Command*/
for(y=0;y<128;y++)
{
for(x=0;x<120;x++)
Write_dat(dat1);
Write_dat(dat2);
}
// delay(1);
}
//=========圖形
void display_graphic_256x64_0()
{
unsigned char x,y;
unsigned int i=0;
Write_cmd(0x15);
Write_dat(0x1c); //
Write_dat(0x5b); //91 91-28=63
Write_cmd(0x75);
Write_dat(0x00); //0
Write_dat(0x3f); //63 63-0=63
Write_cmd(0x5C);
for(y=0;y<64;y++)
{
for(x=0;x<32;x++)
{
unsigned char code_buf,code_buf2;
code_buf=bmp25664_0[i++];
code_buf2=code_buf&0xc0;
send_2bit(code_buf2);
code_buf2=code_buf&0x30;
code_buf2<<=2;
send_2bit(code_buf2);
code_buf2=code_buf&0x0c;
code_buf2<<=4;
send_2bit(code_buf2);
code_buf2=code_buf&0x03;
code_buf2<<=6;
send_2bit(code_buf2);
}
}
}
//=========圖形
void display_graphic_256x64_1()
{
unsigned char x,y;
unsigned int i=0;
Write_cmd(0x15);
Write_dat(0x1c); //
Write_dat(0x5b); //91 91-28=63
Write_cmd(0x75);
Write_dat(0x00); //0
Write_dat(0x3f); //63 63-0=63
Write_cmd(0x5C);
for(y=0;y<64;y++)
{
for(x=0;x<32;x++)
{
unsigned char code_buf,code_buf2;
code_buf=bmp25664_1[i++];
code_buf2=code_buf&0xc0;
send_2bit(code_buf2);
code_buf2=code_buf&0x30;
code_buf2<<=2;
send_2bit(code_buf2);
code_buf2=code_buf&0x0c;
code_buf2<<=4;
send_2bit(code_buf2);
code_buf2=code_buf&0x03;
code_buf2<<=6;
send_2bit(code_buf2);
}
}
}
void send_2bit(unsigned char two_bit_data)
{
if(two_bit_data==0x00)
Write_dat(0x00);
else if(two_bit_data==0x40)
Write_dat(0x0f);
else if(two_bit_data==0x80)
Write_dat(0xf0);
else
Write_dat(0xff);
}
/***************************************
間隔行顯示
**************************************/
void hang(unsigned char Data)
{
unsigned char i,j;
Set_Column_Address(0x1c,0x5b);
Set_Row_Address(0x00,0x3f);
Set_Write_RAM();
for(i=0;i<32;i++)
{
for(j=0;j<64;j++)
{
Write_dat(Data);
Write_dat(Data);
}
for(j=0;j<64;j++)
{
Write_dat(~Data);
Write_dat(~Data);
}
}
}
/***************************************
間隔點顯示
**************************************/
void gedot(uchar m)
{
unsigned char i,j;
Set_Column_Address(0x1c,0x5b); //256列
Set_Row_Address(0x00,0x3f); //128行
Set_Write_RAM();
for(i=0;i<32;i++)
{
for(j=0;j<64;j++)
{
if(m==0xf0)
{
Write_dat(0xf0);
Write_dat(0xf0);
}
else
{
Write_dat(0x0f);
Write_dat(0x0f);
}
}
for(j=0;j<64;j++)
{
if(m==0xf0)
{
Write_dat(0x0f);
Write_dat(0x0f);
}
else
{
Write_dat(0xf0);
Write_dat(0xf0);
}
}
}
}
/*****************************************************
矩形邊框
*********************************************************/
void biank()
{
unsigned char i; // unsigned char i,j;
Set_Remap_Format(0x14);
Write_cmd(0x15);
Write_dat(0x1c);
Write_dat(0x5b);
Write_cmd(0x75);
Write_dat(0x00);
Write_dat(0x00);
Write_cmd(0x5c);
for(i=0;i<64;i++)
{
Write_dat(0xff);
Write_dat(0xff);
}
Write_cmd(0x75);
Write_dat(0x3f);
Write_dat(0x3f);
Write_cmd(0x5c);
for(i=0;i<64;i++)
{
Write_dat(0xff);
Write_dat(0xff);
}
Set_Remap_Format(0x15);
Write_cmd(0x15);
Write_dat(0x1c);
Write_dat(0x1c);
Write_cmd(0x75);
Write_dat(0x01);
Write_dat(0x3e);
Write_cmd(0x5c);
for(i=0;i<64;i++)
{
Write_dat(0xf0);
Write_dat(0x00);
}
Write_cmd(0x15);
Write_dat(0x5b);
Write_dat(0x5b);
Write_cmd(0x5c);
for(i=0;i<64;i++)
{
Write_dat(0x00);
Write_dat(0x0f);
}
Set_Remap_Format(0x14);
}
/************************************************
轉換函數,D7=1,一位轉換成四位
************************************************/
void change (uchar m)
{
uchar k;
uchar kk,kkk;
kk=m;
for(k=0;k<4;k++) // 一兩位的方式寫入 2*4=8位
{
kkk=kk&0xc0; //當K=0時 為D7,D6位 當K=1時 為D5,D4位
/****出現4種可能,16階色素,一個地址兩個像素,一個像素對應4位***/
switch(kkk)
{
case 0x00:
data_4byte[k]=0x00;
break;
case 0x40:
data_4byte[k]=0x0f;
break;
case 0x80:
data_4byte[k]=0xf0;
break;
case 0xc0:
data_4byte[k]=0xff;
break;
default:
break;
}
kk=kk<<2; //左移兩位
Write_dat(data_4byte[k]); /* 8 column a nibble of command is a dot*/
}
}
/**********************************************************
在顯示屏上寫一個8*16的數字
// 用字模表tab816(1維數組),
//在坐標(x坐標)(y坐標)位置顯示一行字(左上腳坐標),
//其中x坐標必須為偶數。
//字占row行,一行col點。
//以上定義都是unsigned char全局變量,
************************************************************/
void write_oled(uchar x,uchar y,uchar coder)
{
uchar dat;
uchar i;
Set_Remap_Format(0x14); //定義2個地址,1個字節
Write_cmd(0x15);
Write_dat(0x1c+x);
Write_dat(0x1d+x);
Write_cmd(0x75); //16行
Write_dat(0x00+y);
Write_dat(0x10+y);
Write_cmd(0x5c);
for(i=0;i<16;i++)
{
dat=tab816[i+16*coder];
change(dat);
}
}
/*********************************************************
寫入一行8*16的數字
****************************************************/
void string816(uchar x,uchar y,uchar m)
{
uchar i;
for(i=0;i<m;i++)
{
write_oled(x,y,i);
x=x+4; //delay(2); 取消延時,消除顯示停頓
} }
/*********************************************************
寫入一行8*8的數字
****************************************************/
void write_oled8(uchar x,uchar y,uchar coder)
{
uchar dat;
uchar i;
Set_Remap_Format(0x14); //定義2個地址,1個字節
Write_cmd(0x15);
Write_dat(0x1c+x);
Write_dat(0x1d+x);
Write_cmd(0x75); //16行
Write_dat(0x00+y);
Write_dat(0x08+y);
Write_cmd(0x5c);
for(i=0;i<8;i++)
{
dat=tab88[i+8*coder];
change(dat);
}
}
/*********************************************************
寫入一行8*8的數字
****************************************************/
void string88(uchar x,uchar y,uchar m)
{
uchar i;
for(i=0;i<m;i++)
{
write_oled8(x,y,i);
x=x+2;
} }
/**********************************************************
在顯示屏上寫一個16*16的漢字
// 用字模表tab1616(1維數組),
//在坐標(x坐標)(y坐標)位置顯示一行字(左上腳坐標),
//其中x坐標必須為偶數。
//字占row行,一行col點。
//以上定義都是unsigned char全局變量,coder為代碼值
************************************************************/
void hzwrite_oled(uchar x,uchar y,uchar coder)
{
uchar dat;
uchar i;
Set_Remap_Format(0x14); //定義4個地址,2個字節
Write_cmd(0x15);
Write_dat(0x1c+x);
Write_dat(0x1f+x);
Write_cmd(0x75); //16行
Write_dat(0x00+y);
Write_dat(0x10+y);
Write_cmd(0x5c);
for(i=0;i<32;i++)
{
dat=tab1616[i+32*coder];
change(dat);
}
}
//***********************************************
// 寫入一行漢字
/**********************************************/
void stinghz(uchar x,uchar y,uchar m)
{
uchar i;
for(i=0;i<m;i++)
{
hzwrite_oled(x,y,i);
x=x+6; delay(2);
}
}
/*********************************************
卷動程序
**********************************************/
void Set_Partial_Display(unsigned char a, unsigned char b, unsigned char c)
{
Write_cmd(0xA8|a);
// Default => 0x8F
// Select Internal Booster at Display On
if(a == 0x00)
{
Write_dat(b);
Write_dat(c);
}
}
/*****************************************
顯示偏移量
********************************************/
void Set_Display_Offset(unsigned char d)
{
Write_cmd(0xA2); // Set Vertical Scroll by Row
Write_dat(d); // Default => 0x00
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Vertical Scrolling (Full Screen)
//
// a: Scrolling Direction
// "0x00" (Upward)
// "0x01" (Downward)
// b: Set Numbers of Row Scroll per Step
// c: Set Time Interval between Each Scroll Step
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Vertical_Scroll(unsigned char a, unsigned char b, unsigned char c)
{
unsigned int i,j;
Set_Partial_Display(0x00,0x00,Max_Row);
switch(a)
{
case 0:
for(i=0;i<(Max_Row+1);i+=b)
{
Set_Display_Offset(i+1);
for(j=0;j<c;j++)
{
delayus(100);
}
}
break;
case 1:
for(i=0;i<(Max_Row+1);i+=b)
{
Set_Display_Offset(Max_Row-i);
for(j=0;j<c;j++)
{
delayus(100);
}
}
break;
}
Set_Partial_Display(0x01,0x00,0x00);
}
/*********************************
起始行
**********************************/
void Set_Start_Line(unsigned char d)
{
Write_cmd(0xA1); // Set Vertical Scroll by RAM
Write_dat(d); // Default => 0x00
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Vertical Fade Scrolling (Full Screen)
//
// a: Scrolling Direction
// "0x00" (Upward - In)
// "0x01" (Downward - In)
// "0x02" (Upward - Out)
// "0x03" (Downward - Out)
// b: Set Numbers of Row Scroll per Step
// c: Set Time Interval between Each Scroll Step
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fade_Scroll(unsigned char a, unsigned char b, unsigned char c)
{
unsigned int i,j;
Set_Partial_Display(0x00,0x00,Max_Row);
switch(a)
{
case 0:
for(i=(Max_Row+1);i<128;i+=b)
{
Set_Start_Line(i);
for(j=0;j<c;j++)
{
delayus(100);
}
}
Set_Start_Line(0x00);
for(j=0;j<c;j++)
{
delayus(100);
}
break;
case 1:
for(i=0;i<(Max_Row+1);i+=b)
{
Set_Start_Line(Max_Row-i);
for(j=0;j<c;j++)
{
delayus(100);
}
}
break;
case 2:
for(i=0;i<(Max_Row+1);i+=b)
{
Set_Start_Line(i+1);
for(j=0;j<c;j++)
{
delayus(100);
}
}
break;
case 3:
for(i=127;i>Max_Row;i-=b)
{
Set_Start_Line(i);
for(j=0;j<c;j++)
{
delayus(100);
}
}
break;
}
Set_Partial_Display(0x01,0x00,0x00);
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Regular Pattern (Partial or Full Screen)
//
// a: Column Address of Start
// b: Column Address of End (Total Columns Devided by 4)
// c: Row Address of Start
// d: Row Address of End
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fill_Block(unsigned char Data, unsigned char a, unsigned char b, unsigned char c, unsigned char d)
{
unsigned char i,j;
Set_Column_Address(Shift+a,Shift+b);
Set_Row_Address(c,d);
Set_Write_RAM();
for(i=0;i<(d-c+1);i++)
{
for(j=0;j<(b-a+1);j++)
{
Write_dat(Data);
Write_dat(Data);
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Gray Scale Bar (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Grayscale()
{
// Level 16 => Column 1~16
Fill_Block(0xFF,0x00,0x03,0x00,Max_Row);
// Level 15 => Column 17~32
Fill_Block(0xEE,0x04,0x07,0x00,Max_Row);
// Level 14 => Column 33~48
Fill_Block(0xDD,0x08,0x0B,0x00,Max_Row);
// Level 13 => Column 49~64
Fill_Block(0xCC,0x0C,0x0F,0x00,Max_Row);
// Level 12 => Column 65~80
Fill_Block(0xBB,0x10,0x13,0x00,Max_Row);
// Level 11 => Column 81~96
Fill_Block(0xAA,0x14,0x17,0x00,Max_Row);
// Level 10 => Column 97~112
Fill_Block(0x99,0x18,0x1B,0x00,Max_Row);
// Level 9 => Column 113~128
Fill_Block(0x88,0x1C,0x1F,0x00,Max_Row);
// Level 8 => Column 129~144
Fill_Block(0x77,0x20,0x23,0x00,Max_Row);
// Level 7 => Column 145~160
Fill_Block(0x66,0x24,0x27,0x00,Max_Row);
// Level 6 => Column 161~176
Fill_Block(0x55,0x28,0x2B,0x00,Max_Row);
// Level 5 => Column 177~192
Fill_Block(0x44,0x2C,0x2F,0x00,Max_Row);
// Level 4 => Column 193~208
Fill_Block(0x33,0x30,0x33,0x00,Max_Row);
// Level 3 => Column 209~224
Fill_Block(0x22,0x34,0x37,0x00,Max_Row);
// Level 2 => Column 225~240
Fill_Block(0x11,0x38,0x3B,0x00,Max_Row);
// Level 1 => Column 241~256
Fill_Block(0x00,0x3C,Max_Column,0x00,Max_Row);
}
/***************************************
主函數
**************************************/
void main(void)
{
REST=0;
delayms(100);
REST=1;
delayms(50); //100
Initial();
while(1)
{
Fill_RAM(0xff); //全顯示
delay(2);
Fill_RAM(0xf0); //豎線
delay(2);
Fill_RAM(0x0f); //豎線
delay(2);
hang(0xff); //顯示行
delay(2);
hang(0x00); //顯示行
delay(2);
gedot(0xf0); //顯示點
delay(2);
gedot(0x0f); //顯示點
delay(2);
Fill_RAM(0x00); // Clear Screen
/*
write_oled(0,0,0x00);
write_oled(4,0,0x01);
biank(); //矩形框
delay(10);
*/
hzwrite_oled(14,0,0x00);
hzwrite_oled(22,0,0x01);
hzwrite_oled(30,0,0x02);
hzwrite_oled(38,0,0x03);
string88(0,17,32);
stinghz(4,25,10) ;
string816(14,45,10);
delay(10);
Grayscale(); //顯示灰階
delay(10);
Fill_RAM(0x00); // Clear Screen
// delay(10);
// fill(0xff,0xff);
display_graphic_256x64_0();
delay(10);
Fill_RAM(0x00); // Clear Screen
display_graphic_256x64_1();
delay(10);
Fill_RAM(0x00); // Clear Screen
}
}
unsigned char code bmp25664_0[]=
{
/*-- 調入了一幅圖像:E:\LCD小工具\程序圖片\25664.bmp --*/
/*-- 寬度x高度=256x64 --*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
3.12寸OLED模組(1).zip
(7.63 MB, 下載次數: 87)
2018-8-9 17:36 上傳
點擊文件名下載附件
stm32
下載積分: 黑幣 -5
作者:
wuxishun
時間:
2018-8-10 06:45
這是51程序嗎?
作者:
r276135502
時間:
2019-4-10 09:23
剛好可以學習一下
作者:
zshxiong
時間:
2019-5-18 18:08
正在研究OLED,學習一下。
作者:
violet701
時間:
2020-5-9 08:55
剛好可以學習一下 謝謝
作者:
han_chen
時間:
2020-7-8 13:59
請教一下0xa0 寄存器,能否設置x y 翻轉90度
作者:
billaj
時間:
2020-8-14 14:19
收下,萬分感謝,樓主萬歲萬萬歲
作者:
billaj
時間:
2020-12-19 10:38
感謝分享,謝謝,51黑有你更精彩
作者:
madfish
時間:
2022-5-23 08:25
感謝分享,謝謝,51黑有你更精彩
作者:
mick32
時間:
2022-5-23 21:56
OLED 3.12 inch 256*64 driver for XX51 cpu
Thank you
歡迎光臨 (http://m.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
亚洲www啪成人一区二区麻豆
|
亚洲午夜在线观看
|
a视频在线免费观看
|
精品国产91
|
一区二区三区四区在线播放
|
黄色综合
|
欧美黑人性猛交
|
久久精品毛片
|
欧美成人精品一区二区三区在线看
|
av网址在线播放
|
91精品国产综合久久久蜜臀
|
欧美日韩少妇
|
校园春色综合网
|
亚洲视频网
|
一区二区三区视频
|
麻豆成人免费视频
|
91蝌蚪少妇偷拍
|
毛片网站免费观看
|
91蜜桃视频
|
免费成人黄色
|
一区视频
|
又色又爽又黄18网站
|
日韩欧美精品
|
在线观看视频一区二区三区
|
精品一区二区三区四区五区
|
懂色av一区二区夜夜嗨
|
丁香午夜
|
日韩高清一区
|
美女久久久
|
免费在线观看www
|
色综合av
|
久草福利在线观看
|
色爱综合网
|
欧美一区二区视频在线观看
|
欧美日韩毛片
|
亚洲专区一区
|
中文字幕免费观看视频
|
日韩二三区
|
久久亚洲欧美
|
www.一区
|
av网站在线免费观看
|