这里将我写的STC12C5A60S2单片机控制OLED12864显示屏的程序共享一下,如有不足,敬请指出!
实验视频:
单片机控制OLED12864显示屏实验效果
代码结构图:
程序下载链接:https://download.csdn.net/download/yagnruinihao/16746777点击下载
测试程序:OLED12864测试.c
#include "OLED12864.h"
#include "OLED12864WordCode.h"
#include "common.h"
void DisplayLogoTest(void);
void DisplayAsciiTest(void) ;
void DisplayScrollTest(void);
void DisplayGrid(void);
void DisplayBmp(void);
void main(void)
{
unsigned char i=0;
unsigned char j=0 ;
OLED12864_Init(); //OLED初始化
while(1)
{
DisplayAsciiTest();//ASCII显示实验
OLED12864_CleanAll();
DisplayScrollTest();//滚动屏显示实验
OLED12864_CleanAll();
DisplayGrid();//画棋盘实验
OLED12864_CleanAll();
DisplayBmp();//图片显示实验
}
}
void DisplayLogoTest(void)
{
unsigned char i ;
//"微创电子"
OLED12864_WriteFont16x16(0,8,0);
OLED12864_WriteFont16x16(0,24,1);
OLED12864_WriteFont16x16(0,40,2);
OLED12864_WriteFont16x16(0,56,3);
OLED12864_WriteFont16x16(0,72,29);
OLED12864_WriteFont16x16(0,88,30);
OLED12864_WriteFont16x16(0,104,31);
//横线
for(i=0 ; i<16 ; i++)
OLED12864_WriteFont16x08(2,i*8,13);
}
void DisplayAsciiTest(void)
{
unsigned char i ;
unsigned char bai,shi,ge ;
//"微创电子工作室"+横线
DisplayLogoTest();
//"ASCII"
OLED12864_WriteFont16x08(4,0,33) ;
OLED12864_WriteFont16x08(4,8,51) ;
OLED12864_WriteFont16x08(4,16,35) ;
OLED12864_WriteFont16x08(4,24,41) ;
OLED12864_WriteFont16x08(4,32,41) ;
//"值演示实验"
OLED12864_WriteFont16x16(4,48,4);
OLED12864_WriteFont16x16(4,64,5);
OLED12864_WriteFont16x16(4,80,6);
OLED12864_WriteFont16x16(4,96,7);
OLED12864_WriteFont16x16(4,112,8);
//"For:""Value="
OLED12864_WriteFont16x08(6,0,38);//F
OLED12864_WriteFont16x08(6,8,79);//o
OLED12864_WriteFont16x08(6,16,82);//r
OLED12864_WriteFont16x08(6,24,26);//:
OLED12864_WriteFont16x08(6,56,54);//V
OLED12864_WriteFont16x08(6,64,65);//a
OLED12864_WriteFont16x08(6,72,76);//l
OLED12864_WriteFont16x08(6,80,85);//u
OLED12864_WriteFont16x08(6,88,69);//e
OLED12864_WriteFont16x08(6,96,29);//=
//ASCII字符及其数值
for(i=0 ; i<95 ; i++)
{
OLED12864_WriteFont16x08(6,32,i);
bai = (i+32)%1000/100 ;
shi = (i+32)%100/10 ;
ge = (i+32)%10 ;
if(bai)
OLED12864_WriteFont16x08(6,104,bai+16);
else
OLED12864_WriteFont16x08(6,104,0);
OLED12864_WriteFont16x08(6,112,shi+16);
OLED12864_WriteFont16x08(6,120,ge+16);
Delay_SomeNop(10000);
}
}
void DisplayScrollTest(void)
{
unsigned char i ;
DisplayLogoTest();
//"滚屏显示实验"
OLED12864_WriteFont16x16(4,16,9);
OLED12864_WriteFont16x16(4,32,10);
OLED12864_WriteFont16x16(4,48,11);
OLED12864_WriteFont16x16(4,64,12);
OLED12864_WriteFont16x16(4,80,13);
OLED12864_WriteFont16x16(4,96,14);
//"倒计时:"
OLED12864_WriteFont16x16(6,32,23);
OLED12864_WriteFont16x16(6,48,24);
OLED12864_WriteFont16x16(6,64,25);
OLED12864_WriteFont16x08(6,80,26);
for(i=0 ; i<=3 ; i++)
{
OLED12864_WriteFont16x08(6,88,3-i+16);
Delay_SomeNop(40000);
}
//清除最后一行汉字
for(i=0 ; i <16 ; i++)
{
OLED12864_WriteFont16x08(6,i*8,0);
}
//开始横向滚屏
OLED12864_HorizontalScrollDisplay(OLED12864_HORIZONTAL_SCROLL_LEFT,OLED12864_PAGE2, OLED12864_PAGE5, OLED12864_INTERVAL_2_FRAMES);
Delay_SomeNop(120000);
OLED12864_HorizontalScrollDisplay(OLED12864_HORIZONTAL_SCROLL_RIGHT,OLED12864_PAGE2, OLED12864_PAGE5, OLED12864_INTERVAL_2_FRAMES);
Delay_SomeNop(120000);
OLED12864_HorizontalScrollDisplay(OLED12864_HORIZONTAL_SCROLL_RIGHT,OLED12864_PAGE2, OLED12864_PAGE5, OLED12864_INTERVAL_2_FRAMES);
Delay_SomeNop(120000);
OLED12864_HorizontalScrollDisplay(OLED12864_HORIZONTAL_SCROLL_LEFT,OLED12864_PAGE2, OLED12864_PAGE5, OLED12864_INTERVAL_2_FRAMES);
Delay_SomeNop(120000);
OLED12864_StopScroll();
Delay_SomeNop(120000);
//开始纵向滚屏
OLED12864_VerticalScrollArea(32,32);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE7,OLED12864_PAGE7, OLED12864_INTERVAL_2_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE7,OLED12864_PAGE7, OLED12864_INTERVAL_2_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_StopScroll();
Delay_SomeNop(120000);
//开始斜向滚屏
OLED12864_VerticalScrollArea(0,64);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_StopScroll();
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE4,OLED12864_PAGE7, OLED12864_INTERVAL_2_FRAMES, 0x01);
Delay_SomeNop(200000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE4,OLED12864_PAGE7, OLED12864_INTERVAL_2_FRAMES, 0x01);
Delay_SomeNop(200000);
OLED12864_StopScroll();
Delay_SomeNop(200000);
}
void DisplayGrid(void)
{
unsigned char i,j,k;
OLED12864_Fill(0x0f);
OLED12864_Fill(0xf0);
for(k=0;k<8;k++)
{
for(i=0 ; i<8;i++)
{
for(j=0;j<8;j++)
{
OLED12864_SetPosition(i , j+k*16);
OLED12864_WriteData(0xff);
}
}
}
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_INVERSE_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_NORMAL_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_INVERSE_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_NORMAL_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_INVERSE_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_NORMAL_DISPLAY);
}
void DisplayBmp(void)
{
OLED12864_DrawBmp(0, 0,7,127 ,BMP1);
OLED12864_VerticalScrollArea(0,64);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_StopScroll();
OLED12864_CleanAll();
OLED12864_DrawBmp(0, 0,7,127 ,BMP2);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_INVERSE_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_NORMAL_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_INVERSE_DISPLAY);
Delay_SomeNop(120000);
OLED12864_DisplayNormalOrInverse(OLED12864_SET_NORMAL_DISPLAY);
Delay_SomeNop(120000);
OLED12864_CleanAll();
OLED12864_DrawBmp(0, 0,7,127 ,BMP4);
Delay_SomeNop(120000);
OLED12864_VerticalScrollArea(0,64);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_RIGHT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x3f);
Delay_SomeNop(120000);
OLED12864_VHScrollDisplay(OLED12864_V_H_SCROLL_LEFT,OLED12864_PAGE0,OLED12864_PAGE7, OLED12864_INTERVAL_3_FRAMES, 0x01);
Delay_SomeNop(120000);
OLED12864_StopScroll();
OLED12864_CleanAll();
OLED12864_DrawBmp(0, 0,7,127 ,BMP3);
Delay_SomeNop(120000);
OLED12864_CleanAll() ;
}
/*################OLED12864.h################*/
#ifndef __OLED12864_H__
#define __OLED12864_H__
#include "common.h"
#define X_WIDTH 128
#define Y_WIDTH 64
//OLED12864的IIC接口硬件地址,可以通过修改硬件后面的0Ω电阻位置修改其硬件地址,在IIC模式下D/C引脚作为从机地址的SA0位
//在SSD1306手册中:In I2C mode, this pin acts as SA0 for slave address selection.
#define OLED12864_DEVICE_ADDRESS1 0x7a//地址一, 0x78 | 0x02
#define OLED12864_DEVICE_ADDRESS2 0x78//地址二,0x78 | 0x00
/*设置默认的硬件地址:OLED12864_DEVICE_ADDRESS1或OLED12864_DEVICE_ADDRESS2即0x78或者0x7a,和硬件电路保持一致*/
#define OLED12864_DEFAULT_DEVICE_ADDRESS OLED12864_DEVICE_ADDRESS2
//读、写操作标志位
#define OLED12864_DEVICE_READ 0x01//读操作
#define OLED12864_DEVICE_WRITE (0x01& (~(0x01<<0)))//写操作
//D/C位选择(数据或命令)
#define OLED12864_DATA_OPERATION 1//数据
#define OLED12864_COMMAND_OPERATION 0//命令
//control byte两种情况基值,表示下一个字节内容是数据还是命令
#define OLED12864_NEXT_BYTE_DATA 0x40 //下一个字节内容为数据
#define OLED12864_NEXT_BYTE_COMMAND (0X04 & (~(0x01<<2)))//下一个字节内容为命令
//OLED12864纵向分为了8个Page,注意编号从0开始
#define OLED12864_PAGE0 0//第一页
#define OLED12864_PAGE1 1//第二页
#define OLED12864_PAGE2 2//第三页
#define OLED12864_PAGE3 3//第四页
#define OLED12864_PAGE4 4//第五页
#define OLED12864_PAGE5 5//第六页
#define OLED12864_PAGE6 6//第七页
#define OLED12864_PAGE7 7//第八页
//OLED12864内存地址设置模式
#define OLED12864_HORIZONTAL_ADDRESS_MODE 0x00//水平地址模式
#define OLED12864_VERTICAL_ADDRESS_MODE 0x01//垂直地址模式
#define OLED12864_PAGE_ADDRESS_MODE 0x02//页地址模式(复位后默认值)
#define OLED12864_INVAILD 0x03//无效设置,不能识别,预留
//VCOMH电源倍率选择
#define OLED12864_VCOMH_DESELECT_LEVEL0 0x00//0.65 X Vcc
#define OLED12864_VCOMH_DESELECT_LEVEL1 0x01//~0.77 X Vcc(复位默认值)
#define OLED12864_VCOMH_DESELECT_LEVEL2 0x02//~0.83 X Vcc
/*--------------------------SSD1306基础命令--------------------------*/
#define OLED12864_SET_CONTRAST_CONTROL 0x81//对比对设置,取值范围1~255,复位值为0x7f
#define OLED12864_ENTIRE_DISPLAY_ON_GDDRAM 0xA4//全局显示关闭,即根据GDDRAM内容显示
#define OLED12864_ENTIRE_DISPLAY_ON_FORCE 0xA5//全局显示开启,即不论GDDRAM内容,而强制所有像素点点亮
#define OLED12864_SET_NORMAL_DISPLAY 0xA6//正常显示,给GDDRAM则0为熄灭像素,1为点亮像素
#define OLED12864_SET_INVERSE_DISPLAY 0xA7//逆显示,反转显示。给GDDRAM则1为熄灭像素,0为点亮像素
#define OLED12864_SET_DISPLAY_OFF 0xAE//关显示,睡眠模式,复位后默认值
#define OLED12864_SET_DISPLAY_ON 0xAF//开显示,普通模式
/*--------------------------SSD1306滚动屏命令--------------------------*/
//SSD1306水平滚动显示命令
#define OLED12864_HORIZONTAL_SCROLL_RIGHT 0x26//设置屏幕持续向右滚动显示
#define OLED12864_HORIZONTAL_SCROLL_LEFT 0x27//设置屏幕持续向左滚动显示
//OLED12864滚动显示间隔(间隔的帧数值越小滚动越快,例如这里间隔2帧时最快,256帧最慢)
#define OLED12864_INTERVAL_5_FRAMES 0//间隔5帧
#define OLED12864_INTERVAL_64_FRAMES 1//间隔64帧
#define OLED12864_INTERVAL_128_FRAMES 2//间隔128帧
#define OLED12864_INTERVAL_256_FRAMES 3//间隔256帧
#define OLED12864_INTERVAL_3_FRAMES 4//间隔3帧
#define OLED12864_INTERVAL_4_FRAMES 5//间隔4帧
#define OLED12864_INTERVAL_25_FRAMES 6//间隔25帧
#define OLED12864_INTERVAL_2_FRAMES 7//间隔2帧
//SSD1306水平和垂直同时滚动显示命令
#define OLED12864_V_H_SCROLL_RIGHT 0x29//持续的垂直、水平向右滚动
#define OLED12864_V_H_SCROLL_LEFT 0x2A//持续的垂直、水平向左滚动
//SSD1306禁止滚动显示、使能滚动显示命令
#define OLED12864_DEACTIVATE_SCROLL 0x2E//禁止滚动显示
#define OLED12864_ATCIVATE_SCROLL 0x2F//使能滚动显示
//设置垂直滚动区域命令
#define OLED12864_SET_VERTICAL_SCROLL_AREA 0xA3//设置垂直滚动范围命令
/*--------------------------SSD1306地址设置命令--------------------------*/
//在页地址模式下,设置起始列地址的命令基值(命令=基值 | 参数值)
#define OLED12864_LOWER_COLUMN_START_ADDRESS_BASE 0x00//页地址模式下设置起始列地址的低半字节的基值(仅用于页地址模式下)
#define OLED12864_HIGHER_COLUMN_START_ADDRESS_BASE 0x10//页地址模式小设置起始列地址的高半字节的基值(仅用于页地址模式下)
//SSD1306寻址设置命令地址
#define OLED12864_SET_MEMORY_ADDRESS_MODE 0x20//设置内存地址模式(复位默认页地址模式)
#define OLED12864_SET_COLUMN_ADDRESS 0x21//设置列起止地址和终止地址(仅用于水平地址模式和垂直地址模式下)
#define OLED12864_SET_PAGE_ADDRESS 0x22//设置页起始地址而后终止地址(仅用于水平地址模式和垂直地址模式下)
/*--------------------------SSD1306硬件配置命令--------------------------*/
#define OLED12864_SET_DISPLAY_START_LINE_BASE 0x40//设置显示起始行命令基值,命令=基值 | 开始行位置
#define OLED12864_SET_SEGMENT_REMAP_NORMAL 0xA0//设置段重映射,列0映射到段0处,即左右正常显示效果
#define OLED12864_SET_SEGMENT_REMAP_FLIP 0xA1//设置段重映射,列127映射到段0处,即左右翻转显示鲜果
#define OLED12864_SET_MULTIPLEX_RATIO 0xA8//设置多路复用率N
#define OLED12864_SET_COM_OUTPUT_SCAN_DIRECTION_NORMAL 0xC0//普通模式,从COM[0]扫描到COM[N-1],即上下正常显示效果
#define OLED12864_SET_COM_OUTPUT_SCAN_DIRECTION_FLIP 0xC8//重新绘制模式,从COM[N-1]扫描到CO0M,即上下翻转显示效果
#define OLED12864_SET_DISPLAY_OFFSET 0xD3//设置垂直移动COM,范围0~63,复位默认值为0
#define OLED12864_SET_COM_PIN_HARDWARE_CONFIGURATION 0xDA//设置COM引脚硬件配置
/*--------------------------SSD1306时序和驱动命令--------------------------*/
#define OLED12864_SET_DISPLAY_CLOCK_DIV_AND_FREQUENCY 0xD5//设置时钟分频因子和频率
#define OLED12864_SET_PRE_CHARGE_PERIOD 0xD9//设置预充电周期
#define OLED12864_SET_VCOMH_DESELECT_LEVEL 0xDB//设置VCOMH电源倍率
#define OLED12864_NOP 0xE3//空操作命令,无任何操作
/*--------------------------SSD1306时序和驱动命令--------------------------*/
#define OLED12864_CHARGE_PUMP_SETING 0x8d//电荷泵的设置
/*--------------------------一些默认设置----------------------------------*/
//默认显示模式:正常显示OLED12864_SET_NORMAL_DISPLAY或者逆显示OLED12864_SET_INVERSE_DISPLAY
#define OLED12864_DEFAULT_DISPLAY_MODE OLED12864_SET_NORMAL_DISPLAY/*默认正常显示*/
//默认是否开启OLED显示功能:OLED12864_SET_DISPLAY_ON或者OLED12864_SET_DISPLAY_OFF
#define OLED12864_DEFAULT_DISPLAY_ON_OR_OFF OLED12864_SET_DISPLAY_ON/*默认开启显示功能*/
//默认驱动路数:全部
#define OLED12864_DEFAULT_MULTIPLEX_RATIO 0x3f/*默认设置驱动路数为63+1(公式为N+1)*/
//默认对比度:0xff最亮
#define OLED12864_DEFAULT_DISPLAY_CONTRAST 0xff
//上、下、左、右翻转显示设置,这里默认上下翻转、左右翻转(这个和看液晶屏方向有关,相对概念,可适当修改)
#define OLED12864_DEFAULT_COM_SCAN_DIRECTION OLED12864_SET_COM_OUTPUT_SCAN_DIRECTION_FLIP
#define OLED12864_DEFAULT_SEGMENT_DIRECTION OLED12864_SET_SEGMENT_REMAP_FLIP
/*****************外部接口函数******************/
//写数据
extern void OLED12864_WriteData(unsigned char DataValue) ;
//写命令
extern void OLED12864_WriteCommand(unsigned char CommandValue) ;
//设置书写位置
extern char OLED12864_SetPosition(unsigned char Page, unsigned char Column) ;
//写16x16的字体(高为16,即两页 ; 宽为16,即16列)
extern char OLED12864_WriteFont16x16(unsigned char Page, unsigned char Column,unsigned char SerialNumber);
//写16x8的字体(高为16,即两页 ; 宽为8,即8列)
extern char OLED12864_WriteFont16x08(unsigned char Page,unsigned char Column,unsigned char SerialNumber);
//OLED12864全屏写入某数据
extern void OLED12864_Fill(unsigned char DataValue) ;
//OLED12864初始化
extern void OLED12864_Init(void) ;
//OLED12864清屏
extern void OLED12864_CleanAll(void) ;
//OLED1864画图
extern char OLED12864_DrawBmp(unsigned char StartPage,unsigned char StartColumn,unsigned char EndPage,unsigned char EndColumn,unsigned char BMP[]);
//OLED12864开始滚动屏幕
extern void OLED12864_StartScroll(void) ;
//OLED12864结束滚动屏幕
extern void OLED12864_StopScroll(void) ;
//水平滚动屏幕显示
extern char OLED12864_HorizontalScrollDisplay(unsigned char LeftOrRight, unsigned char StartPage,
unsigned char EndPage, unsigned char Interval);
//斜方向滚动显示
extern char OLED12864_VHScrollDisplay(unsigned char VHL_or_VHR,unsigned char StartPage,unsigned char EndPage,unsigned char Interval,unsigned char V_offset) ;
//设置垂直滚屏区域
extern char OLED12864_VerticalScrollArea(unsigned char TopRow , unsigned char ScrollRowNumber) ;
//开启全局显示,OLED12864根据GDDRAM内容显示(恢复OLED12864正常显示)
extern void OLED12864_EntireDisplayOnGDDRAM(void) ;
//关闭全局显示,强制点亮所有像素点(不论GDDRAM内容是什么)
extern void OLED12864_EntireDisplayOnForce(void) ;
//设置正常显示或者逆显示(决定高电平亮还是低电平亮)
extern char OLED12864_DisplayNormalOrInverse(unsigned char NormalOrInverse) ;
//开始OLED12864显示
extern void OLED12864_SetDisplayOn(void) ;
//关闭OLED12864显示
extern void OLED12864_SetDisplayOff(void) ;
//设置对比度
extern void OLED12864_SetDisplayContrast(unsigned char Contraset) ;
//设置水平左右是否镜面效果(仅影响后续数据,对GDDRAM内部数据不能产生左右镜面效果)
extern char OLED12864_HorizontalFlip(unsigned char LeftOrRight) ;
//设置垂直上下是否镜面效果(立刻显示效果)
extern char OLED12864_VerticalFlip(unsigned char UpOrDown) ;
#endif /*__OLED12864_H__*/
/*################OLED12864.c部分代码分析################*/
这里重点分析书写16×16中文汉字的四种算法(逐行式、逐列式、列行式、行列式)【具体算法分析,请参考文章:浅谈LCD、OLED、TFT取模及其程序开发的算法取舍】
算法一:逐行式
/*逐列式,已实验成功,注意这里需要配合取模软件和OLED12864WordCode中数组*/
for(j=0;j<16; j++)
{
OLED12864_SetPosition(Page,Column+j);
OLED12864_WriteData(Font16x16[addr++]);
OLED12864_SetPosition(Page + 1 , Column+j);
OLED12864_WriteData(Font16x16[addr++]);
}
算法二:逐列式
/*逐行式(为了便于理解,未优化),已实验成功,注意这里需要配合取模软件和OLED12864WordCode中数组*/
unsigned char temp ;
OLED12864_SetPosition(Page,Column);
for(j=0;j<8 ;j++)
{
temp =(((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+2]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+4]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+8]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+10]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+12]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+14]&(0x01<<j))>>j)<<7) ;
OLED12864_WriteData(temp);
}
++addr;
for(j=0;j<8 ;j++)
{
temp =(((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+2]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+4]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+8]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+10]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+12]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+14]&(0x01<<j))>>j)<<7) ;
OLED12864_WriteData(temp);
}
addr += 15;
OLED12864_SetPosition(Page+1,Column);
for(j=0;j<8 ;j++)
{
temp =(((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+2]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+4]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+8]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+10]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+12]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+14]&(0x01<<j))>>j)<<7) ;
OLED12864_WriteData(temp);
}
++addr;
for(j=0;j<8 ;j++)
{
temp =(((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+2]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+4]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+8]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+10]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+12]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+14]&(0x01<<j))>>j)<<7) ;
OLED12864_WriteData(temp);
}
算法三:列行式(作者最后采用的方式)
/*列行式,已实验成功,注意这里需要配合取模软件和OLED12864WordCode中数组*/
OLED12864_SetPosition(Page,Column);
for(j=0;j<16; j++)
OLED12864_WriteData(Font16x16[addr++]);//写字上半部分
OLED12864_SetPosition(Page+1,Column);
for(j=0;j<16; j++)
OLED12864_WriteData(Font16x16[addr++]);//写字下半部分
算法四:行列式
/*行列式(为了便于理解,未优化,已实验成功),注意这里需要配合取模软件和OLED12864WordCode中数组*/
unsigned char temp ;
OLED12864_SetPosition(Page,Column);
for(j=0;j<8; j++)
{
temp = (((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+1]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+2]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+3]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+4]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+5]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+7]&(0x01<<j))>>j)<<7);
OLED12864_WriteData(temp) ;
}
OLED12864_SetPosition(Page+1,Column);
addr +=8 ;
for(j=0;j<8; j++)
{
temp = (((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+1]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+2]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+3]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+4]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+5]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+7]&(0x01<<j))>>j)<<7);
OLED12864_WriteData(temp) ;
}
addr +=8 ;
OLED12864_SetPosition(Page,Column+8);
for(j=0;j<8; j++)
{
temp = (((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+1]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+2]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+3]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+4]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+5]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+7]&(0x01<<j))>>j)<<7);
OLED12864_WriteData(temp) ;
}
addr +=8 ;
OLED12864_SetPosition(Page+1,Column+8);
for(j=0;j<8; j++)
{
temp = (((Font16x16[addr+0]&(0x01<<j))>>j)<<0) | (((Font16x16[addr+1]&(0x01<<j))>>j)<<1) |(((Font16x16[addr+2]&(0x01<<j))>>j)<<2) | \
(((Font16x16[addr+3]&(0x01<<j))>>j)<<3) | (((Font16x16[addr+4]&(0x01<<j))>>j)<<4) |(((Font16x16[addr+5]&(0x01<<j))>>j)<<5) | \
(((Font16x16[addr+6]&(0x01<<j))>>j)<<6) | (((Font16x16[addr+7]&(0x01<<j))>>j)<<7);
OLED12864_WriteData(temp) ;
}
【注意】这里采用那种算法,需要和取模软件相配套。
今天的文章单片机控制OLED12864显示屏之模块化编程分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/5441.html