qdgd的个人空间 https://www.eechina.com/space-uid-161219.html [收藏] [复制] [RSS]

博客

宽温1602字符OLED显示模块的应用程序参考

已有 402 次阅读2019-8-9 10:48 |个人分类:显示应用| 宽温OLED, 1602OLED, OLED显示模块, 1602应用

   宽温1602字符OLED显示模块工作温度为-40~80℃,更适用于工业现场对温度要求较宽的场合,下面以HCS1625为例,介绍下应用参考(宽温零下40℃可以正常工作的OLED模块接口上有6800并口,SPI串口,I2C串口等等,下面的实例是以SPI串口为例的)。
电路图(采用了IO口模拟SPI时序):

应用程序:
#include<reg51.h>
#include <string.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int

sbit RS=P3^0;
sbit SCL =P3^1;
sbit SDA =P3^3;
sbit CS =P3^5;
sbit RST =P3^4;

uchar code tab1[]={"0123456789ABCDEFGHIJ"};
uchar code tab2[]={"TEL:13701081790  LCD  "};
uchar code CGR[]={
         0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,//全屏
         0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,//隔列1
         0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,//隔行1
         0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,//隔列2
         0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,//隔行2
         0xff};

/******************************************************************
      延时子程序  
*****************************************************************/

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
   for(y=124;y>0;y--);
}

void wr_com(uchar Command_byte) 
{
  uint i;
  CS=0;
  RS=0;  //write command
  SCL=1;

  for(i=0;i<8;i++)
   {
     if((Command_byte&0x80)==0x80)
      SDA=1;
     else
      SDA=0;
    
      SCL=0;
    
     if(i==0)
      {
       delay(1);
      }   
     Command_byte<<=1;  //左移1位
     SCL=1;
   }
 
  RS=1;
  //CS=1;
 }

void wr_data(uchar Data8_byte) 
{
  uint i;
  CS=0;
  RS=1;  //write data
  SCL=1;

  for(i=0;i<8;i++)
   {
     if((Data8_byte&0x80)==0x80)
       SDA=1;
     else
        SDA=0;

     SCL=0;

     if(i==0)
      {
    delay(1);
      }            
     Data8_byte<<=1;  //左移1位
     SCL=1;
       }
 
  RS=0;
  //CS=1;
}

/******************************************************************
   定位地址(一个地址对应5*8字符和)
   x--> 水平方向地址数(0~39)    ;y-->  垂直方向字符数(0~1);
*****************************************************************/

void  dot(uchar x,uchar y)
{
if(y) x|=0x40;
x|=0x80;
wr_com(x);
}
/******************************************************************
自定义字符形成;
*****************************************************************/
void CGR_SET(uchar code *s)
{
 uchar i=0;
 while(*s!=0xff)
  {
   wr_com(0x40+i);
   wr_data(*s);
   s++;
   i++;
  }
}   
/******************************************************************
  全屏;
*****************************************************************/
 void  fill(uchar z)                           
{
 uchar x,y ;
 for(y=0;y<2;y++)
    for(x=0;x<20;x++)
    {
    dot(x,y);
    wr_data(z);
    }
 }

/******************************************************************
  清屏;
*****************************************************************/

void clear(void)
{
wr_com(0x01);delay(5);
}

/******************************************************************
  字符的输入(5*8)
x--> 水平方向地址数(0~39)    ;y-->  垂直方向字符数(0~1);s-->字符代码首地址;
*****************************************************************/
void en_c_r(uchar x,uchar y,uchar code  * s)  
{
  dot(x,y);
  while(*s>0&&x<20)
   {
   wr_data(*s);
   s++;
   x++;
   }
}

/******************************************************************
  初始化设置;
*****************************************************************/
 void init(void)
{
  delay(15);
  RST =0;
  delay(5);
  RST =1;
  delay(15);

  wr_com(0x38);
  delay(5);
  wr_com(0x38);
  delay(5);
  wr_com(0x38);

  wr_com(0x38);
  wr_com(0x08);
  wr_com(0x01);
  wr_com(0x06);
  wr_com(0x0c);
}

/******************************************************************
  主程序;
*****************************************************************/
int main(void)
{
    init();
    CGR_SET(CGR);
    fill(0x00);delay(700); //全显示
    fill(0x01);delay(700);    //隔列
    fill(0x02);delay(700);
    fill(0x03);delay(700);
    fill(0x04);delay(700);
    fill(0x1f);    delay(500);
    fill(0x20);    //清屏
    clear();
    en_c_r(0,0,tab1);
    en_c_r(0,1,tab2);   
    while(1);
}





路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
返回顶部