标题:
IIC-OLED显示屏资料(SSD1306) 用51单片机和stm32 Arduino驱动oled的例程
[打印本页]
作者:
chengyu123456
时间:
2017-2-13 16:57
标题:
IIC-OLED显示屏资料(SSD1306) 用51单片机和stm32 Arduino驱动oled的例程
里面还有stm32的例程.
0.png
(35.74 KB, 下载次数: 190)
下载附件
2017-2-13 20:26 上传
0.png
(68.81 KB, 下载次数: 175)
下载附件
2017-2-13 20:26 上传
IIC方式的OLED显示屏资料(SSD1306),里面有 用51单片机和stm32单片机还有Arduino驱动oled的例程:
IIC-OLED显示屏资料(SSD1306).rar
(7.84 MB, 下载次数: 793)
2017-2-13 16:56 上传
点击文件名下载附件
下载积分: 黑币 -5
部分程序预览51的:
/************************************************************************************
* Copyright (c), 2013, HelTec Automatic Technology co.,LTD.
* All rights reserved.
* Email: cn.heltec@gmail.com
* WebShop: heltec.taobao.com
*
* File name: LQ12864.h
* Project : OLED
* Processor: STC89C52
* Compiler : Keil C51 Compiler
*
* Author : 小林
* Version: 1.00
* Date : 2013.8.8
* Email : hello14blog@gmail.com
* Modification: none
*
* Description:128*64点整OLED模块驱动文件
*
* Others: none;
*
* Function List:
*
* 1. void delay(unsigned int z) -- 延时函数,毫秒
* 2. void IIC_Start() -- 开启I2C总线
* 3. void IIC_Stop() -- 关闭I2C总线
* 4. void Write_IIC_Byte(unsigned char IIC_Byte) -- 通过I2C总线写一个byte的数据
* 5. void OLED_WrDat(unsigned char dat) -- 向OLED屏写数据
* 6. void OLED_WrCmd(unsigned char cmd) -- 向OLED屏写命令
* 7. void OLED_Set_Pos(unsigned char x, unsigned char y) -- 设置显示坐标
* 8. void OLED_Fill(unsigned char bmp_dat) -- 全屏显示(显示BMP图片时才会用到此功能)
* 9. void OLED_CLS(void) -- 复位/清屏
* 10. void OLED_Init(void) -- OLED屏初始化程序,此函数应在操作屏幕之前最先调用
* 11. void OLED_P6x8Str(unsigned char x, y,unsigned char ch[]) -- 6x8点整,用于显示ASCII码的最小阵列,不太清晰
* 12. void OLED_P8x16Str(unsigned char x, y,unsigned char ch[]) -- 8x16点整,用于显示ASCII码,非常清晰
* 13.void OLED_P16x16Ch(unsigned char x, y, N) -- 16x16点整,用于显示汉字的最小阵列,可设置各种字体、加粗、倾斜、下划线等
* 14.void Draw_BMP(unsigned char x0, y0,x1, y1,unsigned char BMP[]) -- 将128x64像素的BMP位图在取字软件中算出字表,然后复制到codetab中,此函数调用即可
*
* History: none;
*
*************************************************************************************/
#include "reg51.h"
// ------------------------------------------------------------
// IO口模拟I2C通信
// SCL接P1^3
// SDA接P1^2
// ------------------------------------------------------------
sbit SCL=P1^1; //串行时钟
sbit SDA=P1^0; //串行数据
#define high 1
#define low 0
#define Brightness 0xCF
#define X_WIDTH 128
#define Y_WIDTH 64
/*********************OLED驱动程序用的延时程序************************************/
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
SCL = high;
SDA = high;
SDA = low;
SCL = low;
}
/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
SCL = low;
SDA = low;
SCL = high;
SDA = high;
}
/**********************************************
// 通过I2C总线写一个字节
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(IIC_Byte & 0x80)
SDA=high;
else
SDA=low;
SCL=high;
SCL=low;
IIC_Byte<<=1;
}
SDA=1;
SCL=1;
SCL=0;
}
/*********************OLED写数据************************************/
void OLED_WrDat(unsigned char IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78);
Write_IIC_Byte(0x40); //write data
Write_IIC_Byte(IIC_Data);
IIC_Stop();
}
/*********************OLED写命令************************************/
void OLED_WrCmd(unsigned char IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78); //Slave address,SA0=0
Write_IIC_Byte(0x00); //write command
Write_IIC_Byte(IIC_Command);
IIC_Stop();
}
/*********************OLED 设置坐标************************************/
void OLED_Set_Pos(unsigned char x, unsigned char y)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(((x&0xf0)>>4)|0x10);
OLED_WrCmd((x&0x0f)|0x01);
}
/*********************OLED全屏************************************/
void OLED_Fill(unsigned char bmp_dat)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(0x01);
OLED_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
OLED_WrDat(bmp_dat);
}
}
/*********************OLED复位************************************/
void OLED_CLS(void)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(0x01);
OLED_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
OLED_WrDat(0);
}
}
/*********************OLED初始化************************************/
void OLED_Init(void)
{
delay(500);//初始化之前的延时很重要!
OLED_WrCmd(0xae);//--turn off oled panel
OLED_WrCmd(0x00);//---set low column address
OLED_WrCmd(0x10);//---set high column address
OLED_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
OLED_WrCmd(0x81);//--set contrast control register
OLED_WrCmd(Brightness); // Set SEG Output Current Brightness
OLED_WrCmd(0xa0);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
OLED_WrCmd(0xc0);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
OLED_WrCmd(0xa6);//--set normal display
OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
OLED_WrCmd(0x3f);//--1/64 duty
OLED_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
OLED_WrCmd(0x00);//-not offset
OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
OLED_WrCmd(0xd9);//--set pre-charge period
OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
OLED_WrCmd(0xda);//--set com pins hardware configuration
OLED_WrCmd(0x12);
OLED_WrCmd(0xdb);//--set vcomh
OLED_WrCmd(0x40);//Set VCOM Deselect Level
OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
OLED_WrCmd(0x02);//
OLED_WrCmd(0x8d);//--set Charge Pump enable/disable
OLED_WrCmd(0x14);//--set(0x10) disable
OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
OLED_WrCmd(0xaf);//--turn on oled panel
OLED_Fill(0x00); //初始清屏
OLED_Set_Pos(0,0);
}
/***************功能描述:显示6*8一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void OLED_P6x8Str(unsigned char x, y,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch[j]!='\0')
{
c =ch[j]-32;
if(x>126){x=0;y++;}
OLED_Set_Pos(x,y);
for(i=0;i<6;i++)
OLED_WrDat(F6x8[c][i]);
x+=6;
j++;
}
}
/*******************功能描述:显示8*16一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void OLED_P8x16Str(unsigned char x, y,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch[j]!='\0')
{
c =ch[j]-32;
if(x>120){x=0;y++;}
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WrDat(F8X16[c*16+i]);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WrDat(F8X16[c*16+i+8]);
x+=8;
j++;
}
}
/*****************功能描述:显示16*16点阵 显示的坐标(x,y),y为页范围0~7****************************/
void OLED_P16x16Ch(unsigned char x, y, N)
{
unsigned char wm=0;
unsigned int adder=32*N;
OLED_Set_Pos(x , y);
for(wm = 0;wm < 16;wm++)
{
OLED_WrDat(F16x16[adder]);
adder += 1;
}
OLED_Set_Pos(x,y + 1);
for(wm = 0;wm < 16;wm++)
{
OLED_WrDat(F16x16[adder]);
adder += 1;
}
}
/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
void Draw_BMP(unsigned char x0, y0,x1, y1,unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y;
if(y1%8==0) y=y1/8;
else y=y1/8+1;
for(y=y0;y<y1;y++)
{
OLED_Set_Pos(x0,y);
for(x=x0;x<x1;x++)
{
OLED_WrDat(BMP[j++]);
}
}
}
复制代码
作者:
猜猜me
时间:
2017-10-29 14:47
谢谢楼主分享
作者:
dulai
时间:
2018-1-28 08:52
想要学习,刚入门。看看怎么弄!!!!
作者:
後輪追前輪
时间:
2018-2-3 21:37
刚好需要学习下
作者:
rockze
时间:
2018-5-2 17:34
支持一下啦!!!
作者:
nb44444
时间:
2018-7-19 11:22
很好,来看看这屏幕
作者:
hahaqinyou
时间:
2018-7-22 16:19
谢谢楼主分享
作者:
拖拉机战士
时间:
2018-7-31 16:35
谢谢楼主分享
作者:
singasin
时间:
2018-10-29 23:27
xiexiefenxiang
作者:
mtk1625
时间:
2019-2-12 11:35
很棒的 谢谢
作者:
shijimiaopu
时间:
2019-3-4 20:49
分不够啊
作者:
asd2002061
时间:
2019-3-18 00:21
非常有用,谢谢分享
作者:
诚兴通讯电器
时间:
2019-3-18 14:48
谢谢分享
作者:
123wer烦
时间:
2019-3-28 14:07
1306怎么与51单片机连线呢
作者:
kangcy
时间:
2019-4-11 17:53
谢谢分享
作者:
lgspace
时间:
2019-5-16 17:01
这个好啊,很详细,厉害
作者:
azi197417
时间:
2019-6-3 18:35
这个要赞!
作者:
zhongzl728
时间:
2019-7-20 18:46
赞一个!
作者:
Lenv
时间:
2019-7-23 19:34
谢谢楼主分享
作者:
mobicity
时间:
2019-9-30 22:04
学习下,感谢
作者:
18982855587
时间:
2019-11-22 16:39
学习下,感谢
作者:
邰夏留
时间:
2019-11-23 23:33
刚好需要,感谢楼主
作者:
jovew
时间:
2019-12-8 14:45
好东西!值得学习。
作者:
917106794
时间:
2019-12-13 15:10
刚好需要,谢谢楼主分享
作者:
zmz_0312
时间:
2020-1-9 17:56
谢谢分享!正好需要这方面的资料!
作者:
lephuocthe
时间:
2020-2-21 04:41
thanks
作者:
小键
时间:
2020-3-1 17:54
主函数在哪个文件夹中?
作者:
nameYTG
时间:
2020-3-6 09:45
感谢感谢
作者:
w494143467
时间:
2020-4-1 13:37
学习学习,刚好出个产品
作者:
小键
时间:
2020-4-18 14:19
老哥在不?
作者:
欧阳云天
时间:
2021-3-8 22:07
正需要这个,初始化的指令太复杂了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1