[应用相关] stm32驱动 LCD1602

[复制链接]
1872|17
 楼主| 初级工程渣 发表于 2021-7-30 21:08 | 显示全部楼层 |阅读模式
一、LCD1602简介
LCD1602液晶显示器是广泛使用的一种字符型液晶显示模块。它是由字符型液晶显示屏(LCD)、控制驱动主电路HD44780及其扩展驱动电路HD44100,以及少量电阻、电容元件和结构件等装配在PCB板上而组成。

LCD1602应用很广泛,无论是各大电子公司的产品上还是各大高校电赛的比赛作品上都能看到它的身影,下面来细说一下怎么驱动这块1602液晶屏。

 楼主| 初级工程渣 发表于 2021-7-30 21:08 | 显示全部楼层
二、LCD1602引脚
716656103f9e0cc2fc.png
 楼主| 初级工程渣 发表于 2021-7-30 21:09 | 显示全部楼层
图1:引脚说明
124336103fa1e753bb.png
 楼主| 初级工程渣 发表于 2021-7-30 21:10 | 显示全部楼层
一、我们重点关注几个引脚:

液晶显示偏压:VL对应原理图V0引脚,作用是调整1602的显示对比度,可外接电位器进行调节对比度,上图原理图接地引脚电压为0这时候对比度最高。
数据/命令选择端:RS对应原理图RES引脚,引脚高电平:进行数据字节传输,引脚低电平:进行命令字节传输。
读/写选择端:R/W对应原理图R/W引脚,引脚高电平:对1602进行读数据,引脚低电平:对1602进行写数据,一般应用都是直接拉低只进行写数据。
使能信号:E对应原理图E引脚,该引脚上升沿代表对1602开始数据传输,下降沿代表数据传输结束。
背光控制:原理图K+引脚,该引脚高电平:背光关闭,引脚低电平:背光打开。
 楼主| 初级工程渣 发表于 2021-7-30 21:10 | 显示全部楼层
二、我们只需要写数据给1602显示,只看写操作时序:

2写指令跟4写数据对比可看出RW读写引脚为低电平,E为高电平,D0~D7为传输的数据是命令/数据,RS数据/命令选择端(高:数据 , 低:命令)。

 楼主| 初级工程渣 发表于 2021-7-30 21:12 | 显示全部楼层
 楼主| 初级工程渣 发表于 2021-7-30 21:13 | 显示全部楼层
三、常用的写指令如下,其他指令可去查1602的datasheet:
639886103fad371e47.png
 楼主| 初级工程渣 发表于 2021-7-30 21:14 | 显示全部楼层
四、数据写入CGRAM指令:

此指令可以自定义显示一个字符,我们写地址的丝毫应该是0x40+Address

64216103fb114506c.png
 楼主| 初级工程渣 发表于 2021-7-30 21:14 | 显示全部楼层
三、LCD1602驱动(11脚)
51单片机跟STM32单片机的驱动基本一致主要是引脚的配置不怎么一样,特别注意STM32驱动写指令/数据GPIO_Write(GPIOA,(GPIO_ReadOutputData(GPIOA) & 0xff00) | cmd/data)为对电平的读取再写数据,其他均与51驱动一致。
 楼主| 初级工程渣 发表于 2021-7-30 21:15 | 显示全部楼层
1、51单片机:LCD1602.h
  1. #ifndef __LCD1602_H
  2. #define __LCD1602_H

  3. #define LCD1602_BKL_ON  0 //背光开
  4. #define LCD1602_BKL_OFF  1 //背光关

  5. #define LCD1602_DB P2   //数据端口  D0~D7
  6. sbit LCD_RES = P4^1;   //1602的数据/指令选择控制线
  7. sbit LCD_EN = P4^2;    //1602的使能控制线
  8. sbit Lcd1602_light = P0^2;      //背光引脚

  9. /*****************************************************************************/
  10. void LCD1602_Init();
  11. void LCD1602_Clear();

  12. void LCD1602_write_cmd(unsigned char cmd);
  13. void LCD1602_write_data(unsigned char date);
  14. void LCD1602_wtire_CGRAM();

  15. void LCD1602_SetCursor(unsigned char x,unsigned char y);
  16. void LCD1602_ShowChar(unsigned char xpos,unsigned char ypos,unsigned char xsz);
  17. void LCD1602_ShowStr(unsigned char xpos,unsigned char ypos,char *p);
  18. void LCD1602_ShowNum(char x, char y, unsigned int num);

  19. void LCD1602_BKLSet(unsigned char val);
  20. unsigned char LCD1602_BKLGet();

  21. void Delay_ms(unsigned int nms);
  22. #endif
 楼主| 初级工程渣 发表于 2021-7-30 21:16 | 显示全部楼层
2、51单片机:LCD1602.h
  1. #include "LCD1602.h"

  2. /******************************************************************************
  3. * 函数名称:void Delay_ms(unsigned int nms)           *
  4. * 函数功能:写命令函数                     *
  5. * 输入参数: //nms为要延时的ms数                *
  6. * 返回值  :无                         *
  7. * 其他说明:                         *
  8. ******************************************************************************/
  9. void Delay_ms(unsigned int nms)  //@11.0592MHz{
  10. unsigned char i, j; //用单片机小工具根据自己的单片机类型及晶振直接生成对应的延时函数即可
  11. while(nms--)
  12. {
  13.   i = 15;
  14.   j = 90;
  15.   do
  16.   {
  17.    while (--j);
  18.   } while (--i);
  19. }
  20. }
  21. /******************************************************************************
  22. * 函数名称:void LCD1602_write_cmd(unsigned char cmd)           *
  23. * 函数功能:写命令函数                     *
  24. * 输入参数: cmd 命令                 *
  25. * 返回值  :无                         *
  26. * 其他说明:                         *
  27. ******************************************************************************/
  28. void LCD1602_write_cmd(unsigned char cmd) {
  29. LCD1602_DB=cmd;
  30. LCD_RES=0;
  31. LCD_EN=1;
  32. Delay_ms(10);
  33. LCD_EN=0;
  34. }
  35. /******************************************************************************
  36. * 函数名称:void LCD1602_write_data(unsigned char date)            *
  37. * 函数功能:写数据函数                     *
  38. * 输入参数: date 数据                   *
  39. * 返回值  :无                        *
  40. * 其他说明:                         *
  41. ******************************************************************************/

  42. void LCD1602_write_data(unsigned char date) {
  43. LCD1602_DB=date;
  44. LCD_RES=1;
  45. LCD_EN=1;
  46. Delay_ms(10);
  47. LCD_EN=0;
  48. }
  49. /******************************************************************************
  50. * 函数名称:void LCD1602_Init(void)                           *
  51. * 函数功能:1602初始化函数                   *
  52. * 输入参数: 无                     *
  53. * 返回值  :无                        *
  54. * 其他说明:                         *
  55. ******************************************************************************/

  56. void LCD1602_Init() {
  57. LCD1602_BKLSet(LCD1602_BKL_ON); //背光开启
  58. LCD1602_write_cmd(0x01);  //显示清屏
  59. LCD1602_write_cmd(0x38); //显示模式设置
  60. LCD1602_write_cmd(0x0C); //显示开及光标设置
  61. LCD1602_write_cmd(0x06); //显示光标移动位置
  62. }
  63. /******************************************************************************
  64. * 函数名称:void LCD1602_Clear(void)                         *
  65. * 函数功能:1602清屏函数                   *
  66. * 输入参数: 无                    *
  67. * 返回值  :无                        *
  68. * 其他说明:                         *
  69. ******************************************************************************/
  70. void LCD1602_Clear(){
  71. LCD1602_write_cmd(0x01);
  72. }

  73. /******************************************************************************
  74. * 函数名称:void LCD1602_BKLSet(unsigned char val)                  *
  75. * 函数功能:打开1602背光函数                   *
  76. * 输入参数: LCD1602_BKL_ON 开LCD1602_BKL_OFF 关       *   
  77. * 返回值  :无                        *
  78. * 其他说明:                         *
  79. ******************************************************************************/
  80. void LCD1602_BKLSet(unsigned char val){
  81. Lcd1602_light = val;
  82. }
  83. /******************************************************************************
  84. * 函数名称:unsigned char LCD1602_BKLGet()                        *
  85. * 函数功能:获取1602背光函数                   *
  86. * 输入参数:无                      *
  87. * 返回值  : 0 开1 关               *
  88. * 其他说明:                         *
  89. ******************************************************************************/
  90. unsigned char LCD1602_BKLGet(){
  91. return Lcd1602_light;
  92. }
  93. /******************************************************************************
  94. * 函数名称:void LCD1602_SetCursor(unsigned char x,unsigned char y)   *
  95. * 函数功能:设置1602位置函数                   *
  96. * 输入参数:x 横坐标 y 纵坐标                   *
  97. * 返回值  : 无                        *
  98. * 其他说明:                         *
  99. ******************************************************************************/
  100. void LCD1602_SetCursor(unsigned char x,unsigned char y){
  101. unsigned char addr;
  102. if(y==0)
  103.   addr=0x00+x;
  104. else
  105.   addr=0x40+x;
  106. LCD1602_write_cmd(addr | 0x80);
  107. }
  108. /******************************************************************************
  109. * 函数名称:void LCD1602_ShowNum(char x, char y, unsigned int num)    *
  110. * 函数功能:指定位置显示数字函数                   *
  111. * 输入参数:x 横坐标 y 纵坐标  num 数字             *
  112. * 返回值  : 无                        *
  113. * 其他说明:                     *
  114. ******************************************************************************/
  115. void LCD1602_ShowNum(char x, char y, unsigned int num){
  116. unsigned int i,j,k,l,n;
  117. i=num/10000;
  118. j=(num-10000*i)/1000;
  119. k=(num-10000*i-1000*j)/100;
  120. l=(num-10000*i-1000*j-100*k)/10;
  121. n=num%10;
  122. LCD1602_SetCursor(x,y);
  123. if(i!=0)LCD1602_write_data(i+0x30);
  124. if((i!=0)||(j!=0))LCD1602_write_data(j+0x30);
  125. if((i!=0)||(j!=0)||(k!=0))LCD1602_write_data(k+0x30);
  126. if((i!=0)||(j!=0)||(k!=0)||(l!=0))LCD1602_write_data(l+0x30);
  127. LCD1602_write_data(n+0x30);
  128. }
  129. /******************************************************************************
  130. * 函数名称:void LCD1602_ShowChar(unsigned char xpos,unsigned char ypos,char xsz)  *
  131. * 函数功能:指定位置显示字符函数                   *
  132. * 输入参数:xpos 横坐标 ypos 纵坐标  xsz 字符             *
  133. * 返回值  : 无                        *
  134. * 其他说明:                     *
  135. ******************************************************************************/
  136. void LCD1602_ShowChar(unsigned char xpos,unsigned char ypos,char xsz) {
  137. ypos%=2;
  138. if(ypos==0)
  139. {
  140.   LCD1602_write_cmd(0x80+xpos);
  141. }
  142. else
  143. {
  144.   LCD1602_write_cmd(0x80+0x40+xpos);
  145. }
  146. LCD1602_write_data(xsz);
  147. }
  148. /******************************************************************************
  149. * 函数名称:void LCD1602_ShowStr(unsigned char xpos,unsigned char ypos,char *p) *
  150. * 函数功能:指定位置显示字符串函数                   *
  151. * 输入参数:xpos 横坐标 ypos 纵坐标  *p 字符串             *
  152. * 返回值  : 无                        *
  153. * 其他说明:                     *
  154. ******************************************************************************/
  155. void LCD1602_ShowStr(unsigned char xpos,unsigned char ypos,char *p){
  156. if(ypos>1)return;
  157. while(*p!='\0')
  158. {
  159.   LCD1602_ShowChar(xpos++,ypos,*p++);
  160.   if(*p=='\n')
  161.   {
  162.    xpos=0;
  163.    ypos++;
  164.    p++;
  165.   }
  166. }
  167. }
  168. unsigned char code code_Y[8]={0x11,0x0A,0x04,0x04,0x04,0x04,0x04,0x00};//类似Y的字模
  169. /******************************************************************************
  170. * 函数名称:void LCD1602_wtire_CGRAM(void) *
  171. * 函数功能:自定义显示字符函数                   *
  172. * 输入参数:   无             *
  173. * 返回值  : 无                        *
  174. * 其他说明:                     *
  175. ******************************************************************************/
  176. void LCD1602_wtire_CGRAM(){
  177.     unsigned char num;
  178.     LCD1602_write_cmd(0x40);    //对CGRAM第一个自定义字符操作,若是第二个则为0x48,
  179.            //其次类推(上面有对顶的关系)
  180.     for(num=0;num<8;num++)
  181.     {
  182.        LCD1602_write_data(code_Y[num]);
  183.     }
  184.     LCD1602_write_cmd(0x80);    //规定显示在第一行第一个位置
  185.     LCD1602_write_data(0x00);   //显示第一个自定义字符 (0x40对应第一个:0x00)

  186. }
  187. /********************************************************************/
 楼主| 初级工程渣 发表于 2021-7-30 21:16 | 显示全部楼层
3、STM32:LCD1602.h
  1. #ifndef __LCD1602_H
  2. #define __LCD1602_H

  3. /***************************根据自己的硬件引脚做修改*****************************/
  4. #define LCD_RS_Set() GPIO_SetBits( GPIOB, GPIO_Pin_12 )//1602的数据/指令选择控制线
  5. #define LCD_RS_Clr() GPIO_ResetBits( GPIOB, GPIO_Pin_12 )

  6. #define LCD_RW_Set() GPIO_SetBits( GPIOB, GPIO_Pin_13 )//1602的读写控制线
  7. #define LCD_RW_Clr() GPIO_ResetBits( GPIOB, GPIO_Pin_13 )

  8. #define LCD_EN_Set() GPIO_SetBits( GPIOB, GPIO_Pin_14 )//1602的使能控制线
  9. #define LCD_EN_Clr() GPIO_ResetBits( GPIOB, GPIO_Pin_14 )

  10. #define DATAOUT( x ) GPIO_Write( GPIOA, x ) //1602的8条数据控制线

  11. void GPIO_Configuration();

  12. void LCD1602_Init();

  13. void LCD1602_Wait_Ready();

  14. void LCD1602_Write_Cmd( u8 cmd );

  15. void LCD1602_Write_Dat( u8 data );

  16. void LCD1602_ClearScreen();

  17. void LCD1602_Set_Cursor( u8 x, u8 y );

  18. void LCD1602_Show_Str( u8 x, u8 y, u8 *str );

  19. #endif
 楼主| 初级工程渣 发表于 2021-7-30 21:30 | 显示全部楼层
4、STM32:LCD1602.c
#include  "LCD1602.h"
/******************************************************************************
* 函数名称:void GPIO_Configuration()            *
* 函数功能:LCD1602引脚初始化                    *
* 输入参数:无                  *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
/*******************根据自己的硬件引脚做修改*****************************************/
void GPIO_Configuration(){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//选择工作频率
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//设置工作模式
GPIO_Init( GPIOB, &GPIO_InitStructure );

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |            GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//设置工作模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//选择工作频率
GPIO_Init( GPIOA, &GPIO_InitStructure );
}
/******************************************************************************
* 函数名称:void LCD1602_Init()            *
* 函数功能:LCD1602初始化                    *
* 输入参数:无                  *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
void LCD1602_Init(){
GPIO_Configuration();   //初始化引脚

LCD1602_Write_Cmd( 0x38 );      //显示模式设置
delay_ms( 5 );
LCD1602_Write_Cmd( 0x0c );      //显示开及光标设置
delay_ms( 5 );
LCD1602_Write_Cmd( 0x06 );      //显示光标移动位置
delay_ms( 5 );
LCD1602_Write_Cmd( 0x01 );      //显示清屏
delay_ms( 5 );
}
/******************************************************************************
* 函数名称:void LCD1602_Write_Cmd(u8 cmd)            *
* 函数功能:写命令函数                     *
* 输入参数: cmd 命令                   *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
void LCD1602_Write_Cmd( u8 cmd ){
LCD_RS_Clr();
LCD_RW_Clr();
LCD_EN_Set();

GPIO_Write( GPIOA, (GPIO_ReadOutputData( GPIOA ) & 0xff00) | cmd );//对电平的读取

DATAOUT( cmd );
delay_ms( 5 );
LCD_EN_Clr();
}

/******************************************************************************
* 函数名称:void LCD1602_Write_Dat(u8 date)            *
* 函数功能:写数据函数                     *
* 输入参数: date 数据                   *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
void LCD1602_Write_Dat( u8 data ){
LCD_RS_Set();
LCD_RW_Clr();
LCD_EN_Set();

GPIO_Write( GPIOA, (GPIO_ReadOutputData( GPIOA ) & 0xff00) | data );//对电平的读取

delay_ms( 5 );
LCD_EN_Clr();
}

/******************************************************************************
* 函数名称:void LCD1602_ClearScreen()            *
* 函数功能:1602清屏函数                     *
* 输入参数:无                   *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
void LCD1602_ClearScreen(){
LCD1602_Write_Cmd( 0x01 );
}

/******************************************************************************
* 函数名称:void LCD1602_Set_Cursor(u8 x, u8 y)            *
* 函数功能:设置1602位置函数                   *
* 输入参数:x 横坐标 y 纵坐标                   *
* 返回值  :无                        *
* 其他说明:                         *
******************************************************************************/
void LCD1602_Set_Cursor( u8 x, u8 y ){
u8 addr;

if ( y == 0 )
  addr = 0x00 + x;
else
  addr = 0x40 + x;
LCD1602_Write_Cmd( addr | 0x80 );
}

/******************************************************************************
* 函数名称:void LCD1602_Show_Str( u8 x, u8 y, u8 *str )            *
* 函数功能:指定位置显示字符串函数                   *
* 输入参数:x 横坐标 y 纵坐标  *str 字符串             *
* 返回值  : 无                       *
* 其他说明:                         *
******************************************************************************/
void LCD1602_Show_Str( u8 x, u8 y, u8 *str ){
LCD1602_Set_Cursor( x, y );
while ( *str != '\0' )
{
  LCD1602_Write_Dat( *str++ );
}
}
 楼主| 初级工程渣 发表于 2021-7-30 21:37 | 显示全部楼层
四、LCD1602 STM32驱动(6线)
LCD1602 的接口形式是并行的,它有 8 条数据线、3 条控制线。这样就需要 11 条线来控制它的正常工作。虽然它还可以工作在 4 位数据线的形式,最精简的形式是 6 条线。

我们可以用74HC595 进行串-并转换,74HC595 是“串入并出”的移位寄存器芯片,它需要用 3 条线控制数据的输入,才能正常的输出 8 位数据,总共6条线即可进行LCD1602的控制。
 楼主| 初级工程渣 发表于 2021-7-30 21:37 | 显示全部楼层
这里多用了一块芯片但是省了5个IO口,对于某些项目单片机引脚不够用的情况下可以应用上。

原理图如下: 714536104009e44330.png
 楼主| 初级工程渣 发表于 2021-7-30 21:39 | 显示全部楼层
 楼主| 初级工程渣 发表于 2021-7-30 22:21 | 显示全部楼层
1、STM32:LCD1602.h
  1. #ifndef __LCD1602_H
  2. #define __LCD1602_H  
  3.   
  4. //1602液晶指令/数据或选择引脚
  5. #define LCD_RS_PORT    GPIOB
  6. #define LCD_RS_PIN   GPIO_Pin_10

  7. #define  LCD_RS_0    GPIO_ResetBits(LCD_RS_PORT, LCD_RS_PIN)
  8. #define  LCD_RS_1    GPIO_SetBits(LCD_RS_PORT, LCD_RS_PIN)


  9. //1602液晶使能引脚
  10. #define LCD_EN_PORT    GPIOB
  11. #define LCD_EN_PIN   GPIO_Pin_11     //PB11

  12. #define  LCD_EN_0    GPIO_ResetBits(LCD_EN_PORT, LCD_EN_PIN)
  13. #define  LCD_EN_1    GPIO_SetBits(LCD_EN_PORT, LCD_EN_PIN)

  14. //1602液晶数据端口
  15. #define MOSIO PBout(0)
  16. #define R_CLK PCout(5)
  17. #define S_CLK PCout(4)

  18. /*********************函数声明*****************/
  19. void LCD1602_Init(void);
  20. void LCD1602_Clear(void);
  21. void LCD1602_ShowStr(unsigned char xpos,unsigned char ypos,char *p);
  22. void LCD1602_BKLSet(unsigned char on);
  23. unsigned char LCD1602_BKLGet(void);
  24. void LCD1602_ShowLineStr(unsigned char xpos,unsigned char ypos,char *p);
  25. void LCD1602_ShowState(unsigned char Signal, unsigned char GprsState);
  26. /**********************************************/
  27. #endif  
 楼主| 初级工程渣 发表于 2021-7-30 22:22 | 显示全部楼层
2、STM32:LCD1602.c
  1. #include "LCD1602.h"
  2. #include "delay.h"//程序中的延时函数根据自己32单片机来就行

  3. void hc595SendData(unsigned char sendVal){
  4.     unsigned char i;
  5.     //从CPU中向595一位一位发送,595一位一位接收
  6.     for(i = 0; i 8; i++)
  7.     {
  8.         if((sendVal <0x80)
  9.             MOSIO = 1;
  10.         else MOSIO = 0;
  11.         S_CLK = 0;
  12.         S_CLK = 1;

  13.     }
  14.     //CPU发送完后,R_CLK将数据并行输出,
  15.     //实现了只占用CPU一个输出口就可以输出8bit数据
  16.     R_CLK = 0;
  17.     R_CLK = 1;

  18. }

  19. void LCD1602_write_com(unsigned char com) {
  20. hc595SendData(com);
  21. LCD_RS_0;
  22. LCD_EN_0;
  23. delay_ms(10);
  24. LCD_EN_1;
  25. }

  26. void LCD1602_write_data(unsigned char date) {
  27. hc595SendData(date);
  28. LCD_RS_1;
  29. LCD_EN_0;
  30. delay_ms(10);
  31. LCD_EN_1;
  32. }

  33. void LCD1602_Init(void) {
  34.   GPIO_InitTypeDef  GPIO_InitStructure;

  35. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE );

  36. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;  //推挽输出
  37. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  38. GPIO_InitStructure.GPIO_Pin =  LCD_RS_PIN | LCD_EN_PIN | GPIO_Pin_0;
  39. GPIO_Init(GPIOB, &GPIO_InitStructure);

  40. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;  //推挽输出
  41. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  42. GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_4 | GPIO_Pin_5;        
  43. GPIO_Init(GPIOC, &GPIO_InitStructure);

  44. LCD1602_write_com(0x01);
  45. LCD1602_write_com(0x38);
  46. LCD1602_write_com(0x0C);//开显示,不需要光标
  47. LCD1602_write_com(0x06);
  48. }

  49. void LCD1602_Clear(void){
  50. LCD1602_write_com(0x01);
  51. }

  52. void LCD1602_ShowChar(unsigned char xpos,unsigned char ypos,char xsz) {
  53. ypos%=2;
  54. if(ypos==0)
  55. {
  56.   LCD1602_write_com(0x80+xpos);
  57. }
  58. else
  59. {
  60.   LCD1602_write_com(0x80+0x40+xpos);
  61. }
  62. LCD1602_write_data(xsz);
  63. }

  64. void LCD1602_ShowLineStr(unsigned char xpos,unsigned char ypos,char *p){
  65. unsigned char i=0;
  66. if(ypos>1 || xpos>=16)return;
  67. while(*p!='\0' && i<16 && xpos<16)
  68. {
  69.   i++;
  70.   LCD1602_ShowChar(xpos++,ypos,*p++);
  71.   delay_us(500);
  72. }
  73. }

  74. void LCD1602_ShowStr(unsigned char xpos,unsigned char ypos,char *p){
  75. if(ypos>1)return;
  76. while(*p!='\0')
  77. {
  78.   LCD1602_ShowChar(xpos++,ypos,*p++);
  79.   if(*p=='\n')//当检测到换行符时,进行换行检测
  80.   {
  81.    xpos=0;
  82.    ypos++;
  83.    p++;
  84.   }
  85. }
  86. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

77

主题

821

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部