当前位置:文档之家› 8051单片机控制字符I2C液晶模块应用实例

8051单片机控制字符I2C液晶模块应用实例

8051单片机控制字符I2C液晶模块应用实例

摘要:本文介绍了通用型8051单片机控制清达光电字符型I2C液晶模块HC1624-I2C,同时介绍了HC1624的主要参数以及特点。

1,8051单片机控制HC1624-I2C液晶模块硬件以及软件应用

示例程序

#include

#include

#include

#include

#define uchar unsigned char

#define uint unsigned int

#define IIC

sbit SDA=P1^6;//connect to DB6

sbit SCL=P1^7;//connect to DB7

#define clear0x01/*Clear Display*/

#define home0x02/*Return Home*/

#define enmode0x06/*Enter Mode Set*/

#define off0x08/*Display on/off Set*/

#define on0x0e/*Display on/off Set*/

#define shift0x14/*Cursor or Display Shift*/

#define reset0x30/*reset*/

#define function0x38/*Function Set*/

#define cgram0x40/*Set CGRAM Address*/

#define ddram10x80/*Set DDRAM Line1Address*/

#define ddram20xC0/*Set DDRAM Line2Address*/

#define time1000/*1000延时1.03895500s*/

uchar code string1[]={"Jia Xian Ke Ji"};uchar code string2[]={"https://www.doczj.com/doc/6c341486.html,"};

uchar code string3[]={"Tel:137********"};

uchar code string4[]={"abcdefghijklmnopqrstuvwxyz"};uchar code string5[]={"Thank You!"}; uchar code string6[]={'2','0','1','2',0x06,'1','0',0x07,'\0'};

/*********自定义字符库*********/uchar code

CGF[8][8]={0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,/*隔行00H*/

0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,/*01H*/

0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,/*隔列02H*/

0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,/*03H*/

0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,/*隔点04H*/

0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,/*05H*/

0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02,/*"年"06H*/

0x0f,0x09,0x0f,0x09,0x0f,0x09,0x11,0x00,/*"月"07H*/};

/*********时间延时函数*********/

void delay(uint t)/*1.02500ms*/

{uint i,j;for(i=t;i>0;i--)for(j=125;j>0;j--);}

#ifdef IIC//============================================

void start()

{SDA=1;

_nop_();

SCL=1;

_nop_();

_nop_();

SDA=0;

_nop_();

_nop_();

SCL=0;}

//============================================

void stop(){SDA=0;_nop_();SCL=1;_nop_();_nop_();SDA=1;

_nop_();_nop_();}

//============================================

void sendbyte(uint temp)

{int i,j;for(i=0;i<8;i++)

{SCL=0;if(temp&0x80)SDA=1;else SDA=0;_nop_();_nop_();SCL=1; _nop_();_nop_();SCL=0;temp=temp<<1;}

_nop_();_nop_();SCL=1;_nop_();_nop_();SCL=0;_nop_();_nop_();}

//============================================

{start();sendbyte(0x78);//slave address sendbyte(0x00);//command sendbyte(para);stop();}

//============================================

void write_data(uint para)

{start();sendbyte(0x78);//RW1033slave address

sendbyte(0x40);//data sendbyte(para);

stop();}

#endif

/******建立自定义字符函数*******/

void CGFUNTION(uchar array[8][8])

{uchar i,j;write_com(cgram);/*写“指令”CGRAM地址*/

for(i=0;i<8;i++)for(j=0;j<8;j++)write_data(array[i][j]);/*写“数据”*/}

/*********字符全屏显示函数*********/

void char_fill_disp(uchar dat)

{uchar i,j,temp=0;

for(i=0;i<2;i++)

for(j=0;j<16;j++)

{if(i==1)temp=j|ddram2;/*DDRAM第二行地址*/

else temp=j|ddram1;/*DDRAM第一行地址*/

write_com(temp);/*写“指令”*/

write_data(dat);/*写“数据”*/}}

/*********字符串显示函数*********/

/***********可选行显示**********/

void string_disp(uchar x,uchar y,uchar*str)

{uchar i,j,temp=0;

for(i=x,j=y;j<16&&*s!='\0';j++)/*字符串结束标志*/

{if(i==0)temp=j|ddram1;/*DDRAM第一行地址*/

else temp=j|ddram2;/*DDRAM第二行地址*/

write_com(temp);

write_data(*s++);}}

/*********设置参数函数*********/

void set(void)

{delay(15);/*延时15.20800ms*/

write_com(0x38);//Function set N=1(2line),F=0(5*8dot)

delay(5);

write_com(0x0C);//display on

delay(5);

write_com(0x01);//clear display

delay(10);

delay(5);}

/*********主函数*********/

void main()/*子程序里有延时1s*/

{set();/*设置参数*/

write_com(clear);/*清屏*/

while(1){char_fill_disp(0xff);/*全屏*/

write_com(clear);/*清屏*/

string_disp(0,1,string1);/*第一行显示字符串string1*/

string_disp(1,0,string2);/*第二行显示字符串string2*/

write_com(clear);/*清屏*/

char_fill_disp(0x31);/*显示“1”*/

CGFUNTION(CGF);/*建立自定义字符*/

write_com(clear);/*清屏*/

char_fill_disp(0x00);/*显示“隔行”*/

char_fill_disp(0x02);/*显示“隔列”*/

char_fill_disp(0x04);/*显示“隔点”*/

char_fill_disp(0xff);/*全屏*/

write_com(clear);/*清屏*/

string_disp(0,0,string3);/*第一行显示字符串string3*/

string_disp(1,0,string4);/*第二行显示字符串string4*/

write_com(clear);/*清屏*/

string_disp(0,2,string5);/*第一行显示字符串string5:*/

string_disp(1,8,string6);/*第二行显示字符串string6:2012年10月*/

delay(time);}}

2.HC1624-I2C介绍

1)I2C液晶时序介绍:

I2C是一种时序,液晶模块时序是指对LCD显示模块进行读写时电路的时序要求和状态。主要分为以下几种时序:8080并口,6800并口,SPI串口,I2C串口,UART串口,RS232

串口,USB等几种类型。

清达光电I2C液晶模块HC1624时序图如下:

2)HC1624-I2C液晶模块主要参数:

HC1624为清达光电生产的16*2字符液晶模块(资料参考https://www.doczj.com/doc/6c341486.html,/character-lcm-hc1624.html)

尺寸规格

模块外形图

接口定义:

编号符号电平功能

1VSS0V接地2VDD+5.0V逻辑电压

3V0-LCD驱动电压4~6NC-空脚

7~8VSS0V逻辑地9~11NC-空脚

12VSS0V逻辑地13SDA H/L I2C接口数据输入

14SCL H/L I2C接口时钟输入

15LEDA+3.3V16LEDK0V LED背光源输入电压3)HC1624-I2C液晶模块控制器介绍

西文字库表

相关主题
文本预览
相关文档 最新文档