文章详情

清达光电SPI液晶模块与8051单片机应用实例

日期:2024-04-23 19:10
浏览次数:2024
摘要:

清达光电SPI液晶模块与8051单片机应用实例

1SPI液晶时序介绍:

    SPI是一种时序,液晶模块时序是指对LCD显示模块进行读写时电路的时序要求和状态。

主要分为以下几种时序:8080并口,6800并口,SPI串口,I2C串口,UART串口,RS232串口,USB等几种类型。

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

 

 

 

 

2SPI液晶HC1624主要参数:

HC1624为清达光电生产的16*2字符液晶模块(资料参考http://www.chinalcdmodule.com/character-lcm-hc1624.html

 

尺寸规格

 

 

 

 

 

 

原理结构图

 

 

模块外形图

 

 

接口定义:

编号  符号 电平 功能 

1 VSS 0V 接地 

2 VDD +5.0V 逻辑电压 

3 V0 - LCD驱动电压 

4 RS H/L H: 数据  L: 指令 

5~11 NC - 空脚位 

12 /CS L 低片选有效 

13 SCLK H/L 串行时钟输入 

14 SID H/L 串行数据输入 

15 LEDA +5.0V 16 LEDK 0V LED背光源输入电压

 

 

 

3, SPI液晶模块HC1624控制器介绍

 


西文字库表

 


4SPI液晶模块与8051单片机硬件及软件应用实例

 

硬件接口图

 

 

软件应用实例:

#include<reg51.h> 

#include<string.h>

 #include<stdio.h> 

#include <intrins.h> 

#define uchar unsigned char

 #define uint unsigned int  

sbit SID=P3^4; 

sbit SCK=P3^3; 

sbit CS=P3^1; 

sbit RS=P3^0; 

 

/*********************

延时子程序

********************/

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 SendByte(unsigned char Dbyte)

{

     unsigned char i ;

    // CS = 0;

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

     {

           SCK = 0 ;

           delayus(1);

           Dbyte=Dbyte<< 1 ;      //左移一位

           delayus(1);

           SID = CY ;            //移出的位给SID

           delayus(1);

           SCK = 1 ;

           SCK = 0 ;

     }

}

void WriteCommand( unsigned char Cbyte )

{

       CS = 0;

     delayus(1);

     SendByte(Cbyte) ;

     delayus(1);

}

 

void WriteData( unsigned char Dbyte)

{

         CS = 0;

     WriteCommand(0x3c);

     SendByte(0x80) ;

     SendByte(Dbyte) ;

}

/***********************

液晶屏初始化

************************/

void lcd_init()

{

 RES=0;

 delayus(10);

 RES=1;

 delayus(10);

 delayms(60);

 WriteCommand(0x38);//8位数,2行显示,外部功能关

  delayms(60);

 WriteCommand(0x38);//8位数,2行显示,外部功能关

  delayms(60);

 WriteCommand(0x38);//8位数,2行显示,外部功能关

  delayus(60);

 WriteCommand(0x0e); //开显示,光标,2行显示

  delayus(60);

 WriteCommand(0x01); //**

  delayus(60);

 WriteCommand(0x02); //归零

   delayus(60);

 WriteCommand(0x14); //光标右移

 WriteCommand(0x06); //模式进入

}

void goto_lcd(uchar x,uchar y)

{

  WriteCommand(0x38);

  WriteCommand(0x80+x+y*0x40);

}

void write_string(uchar x,uchar y,uchar *s)

{

  goto_lcd(x,y);

  while(*s>0)

  {WriteData(*s); s++;}

}

void ringt_lcd()

{

uchar i;

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

{WriteCommand(0x1c);delayms(4000); };

}

void left_lcd()

{

uchar i;

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

{WriteCommand(0x18);delayms(4000); };

}

int main(void)

{

uchar i;

lcd_init();

write_string(0,0,"012456789ABCDEFG");

write_string(4,1,"Tsingtek");

while(1);

}