完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
LCD1602介绍 LCD1602(Liquid Crystal Display)液晶显示屏是一种字符型液晶显示模块,可以显示ASCLL码的标准字符和其他的一些内置特殊符号,还可以有8个自定义中文信息。 显示容量:16×2,即最多只能显示32个字符,每个字符为5*7点阵。 引脚及应用电路 [tr]引脚功能[/tr]
存储器结构 DDRAM(数据显示区) CGRAM+CGROM(字模库) 拿A举例,纵向0100横向0001 合起来就是0100 0001 时序结构 RS:设置指令/数据 , 数据 - 高,指令 - 低 R/W:读写 , 写 - 低 ,读 - 高 E:使能高电平有效 DB0~DB7:数据 读操作时序 写操作时序 LCD1602显示模块控制指令 LCD1602操作流程
1.字符:根据一定规则建立的数字到字符的映射(ASCII码表) 例如:0x21 = ‘!’,0x41 = ‘A’,0x00 = ‘ ’ 定义方法:char x = ‘A’;(等效于char x = 0x41;) 2.字符数组:存储字符变量非一个数组 定义方法:char y[] = {‘A’,‘B’,‘C’};(等效于char y[] = {0x41,0x42,0x43};) 3.字符串:在字符数组后加一个字符串结束标志,本质上是字符数组 定义方法:char z[] = “ABC”;(等效于char z[] = {‘A’,‘B’,‘C’,’ ’};) LCD显示字符 LCD1602.h #ifndef _LCD1602_H_ #define _LCD1602_H_ void LCD_WriteCommand(unsigned char Command); void LCD_WriteDate(unsigned char Date); void LCD_Init(void); void LCD_Showchar(unsigned char Line,unsigned char Columu,unsigned char Char); #endif LCD1602.c #include #include "LCD1602.h" #include ***it LCD_RS = P2^6; ***it LCD_RW = P2^5; ***it LCD_E = P2^7; #define LCD_DataPort P0 /** *¹¦ÄÜ£ºÑÓʱ1ms *²ÎÊý£ºvoid *·µ»ØÖµ£ºvoid */ void LCD_Delay1ms(void) //@11.0592MHz { unsigned char i, j; _nop_(); i = 2; j = 199; do { while (--j); } while (--i); } /** *¹¦ÄÜ£ºÐ´Ö¸ÁÊý *²ÎÊý£ºCommand Ö¸Áî *·µ»ØÖµ£ºvoid *²ÎÕÕ£ºÐ´²Ù×÷ʱÐòͼ */ void LCD_WriteCommand(unsigned char Command) { LCD_RS = 0; //ÉèÖÃÖ¸Áîģʽ LCD_RW = 0; //ÉèÖÃдģʽ LCD_DataPort = Command; //дָÁî LCD_E = 1; LCD_Delay1ms(); LCD_E = 0; LCD_Delay1ms(); } /** *¹¦ÄÜ£ºÐ´Êý¾Ýº¯Êý *²ÎÊý£ºDate Êý¾Ý *·µ»ØÖµ£ºvoid *²ÎÕÕ£ºÐ´²Ù×÷ʱÐòͼ */ void LCD_WriteDate(unsigned char Date) { LCD_RS = 1; //ÉèÖÃÊý¾Ýģʽ LCD_RW = 0; //ÉèÖÃдģʽ LCD_DataPort = Date; //дָÁî LCD_E = 1; LCD_Delay1ms(); LCD_E = 0; LCD_Delay1ms(); } /** *¹¦ÄÜ£ºLCD³õʼ»¯º¯Êý *²ÎÊý£ºvoid *·µ»ØÖµ£ºvoid */ void LCD_Init(void) { LCD_WriteCommand(0x38);//ÅäÖðËλÊý¾Ý½Ó¿Ú LCD_WriteCommand(0X0c);//ÏÔʾ¿ª£¬¹â±ê¹Ø£¬ÉÁ˸¿ª LCD_WriteCommand(0X06);//¹â±ê+1£¬»Ãæ²»¶¯ LCD_WriteCommand(0X01);//ÇåÆÁ } /** *¹¦ÄÜ£ºÏÔʾ×Ö·ûº¯Êý *²ÎÊý£ºLine ÐÐ £¬Columu ÁÐ £¬Char ÒªÏÔʾµÄ×Ö·û *·µ»ØÖµ£ºvoid */ void LCD_Showchar(unsigned char Line,unsigned char Columu,unsigned char Char) { if(Line == 1){ //µÚÒ»ÐеØÖ· LCD_WriteCommand(0x80 | (Columu - 1)); }else{ //µÚ¶þÐеØÖ· LCD_WriteCommand(0x80 | (Columu - 1) + 0x40); } LCD_WriteDate(Char); } main.c #include #include #include "Timer0.h" #include "uart.h" #include "LCD1602.h" /** *¹¦ÄÜ£ºÑÓʱ500ms *²ÎÊý£ºvoid *·µ»ØÖµ£ºvoid */ void Delay500ms(void) //@11.0592MHz { unsigned char i, j, k; _nop_(); _nop_(); i = 22; j = 3; k = 227; do { do { while (--k); } while (--j); } while (--i); } int main() { LCD_Init(); LCD_Showchar(1,2,'A'); while(1) { } } LCD显示字符串和数字 为什么LCD1602.c中有个for循环用的char,如果定义个变量只是为了循环,char和int的效果一样,并且char占一个字节,int占4个字节。 LCD1602.h #ifndef _LCD1602_H_ #define _LCD1602_H_ void LCD_WriteCommand(unsigned char Command); void LCD_WriteDate(unsigned char Date); void LCD_Init(void); void LCD_SetCursor(unsigned char Line,unsigned char Columu); void LCD_Showchar(unsigned char Line,unsigned char Columu,unsigned char Char); void LCD_ShowString(unsigned char Line,unsigned char Columu,unsigned char *String); int LCD_Pow(int x,int y); int LCD_getNumberSize(int Number); void LCD_ShowNumber(unsigned char Line,unsigned char Columu,unsigned int Number); #endif LCD1602.c #include #include "LCD1602.h" #include ***it LCD_RS = P2^6; ***it LCD_RW = P2^5; ***it LCD_E = P2^7; #define LCD_DataPort P0 /** *¹¦ÄÜ£ºÑÓʱ1ms *²ÎÊý£ºvoid *·µ»ØÖµ£ºvoid */ void LCD_Delay1ms(void) //@11.0592MHz { unsigned char i, j; _nop_(); i = 2; j = 199; do { while (--j); } while (--i); } /** *¹¦ÄÜ£ºÐ´Ö¸ÁÊý *²ÎÊý£ºCommand Ö¸Áî *·µ»ØÖµ£ºvoid *²ÎÕÕ£ºÐ´²Ù×÷ʱÐòͼ */ void LCD_WriteCommand(unsigned char Command) { LCD_RS = 0; //ÉèÖÃÖ¸Áîģʽ LCD_RW = 0; //ÉèÖÃдģʽ LCD_DataPort = Command; //дָÁî LCD_E = 1; LCD_Delay1ms(); LCD_E = 0; LCD_Delay1ms(); } /** *¹¦ÄÜ£ºÐ´Êý¾Ýº¯Êý *²ÎÊý£ºDate Êý¾Ý *·µ»ØÖµ£ºvoid *²ÎÕÕ£ºÐ´²Ù×÷ʱÐòͼ */ void LCD_WriteDate(unsigned char Date) { LCD_RS = 1; //ÉèÖÃÊý¾Ýģʽ LCD_RW = 0; //ÉèÖÃдģʽ LCD_DataPort = Date; //дָÁî LCD_E = 1; LCD_Delay1ms(); LCD_E = 0; LCD_Delay1ms(); } /** *¹¦ÄÜ£ºLCD³õʼ»¯º¯Êý *²ÎÊý£ºvoid *·µ»ØÖµ£ºvoid */ void LCD_Init(void) { LCD_WriteCommand(0x38);//ÅäÖðËλÊý¾Ý½Ó¿Ú LCD_WriteCommand(0X0c);//ÏÔʾ¿ª£¬¹â±ê¹Ø£¬ÉÁ˸¿ª LCD_WriteCommand(0X06);//¹â±ê+1£¬»Ãæ²»¶¯ LCD_WriteCommand(0X01);//ÇåÆÁ } /** *¹¦ÄÜ£ºÏÔʾ¹â±ê *²ÎÊý£ºLine ÐÐ £¬Columu ÁÐ *·µ»ØÖµ£ºvoid */ void LCD_SetCursor(unsigned char Line,unsigned char Columu) { if(Line == 1){ //µÚÒ»ÐеØÖ· LCD_WriteCommand(0x80 | (Columu - 1)); }else{ //µÚ¶þÐеØÖ· LCD_WriteCommand(0x80 | (Columu - 1) + 0x40); } } /** *¹¦ÄÜ£ºÏÔʾ×Ö·ûº¯Êý *²ÎÊý£ºLine ÐÐ £¬Columu ÁÐ £¬Char ÒªÏÔʾµÄ×Ö·û *·µ»ØÖµ£ºvoid */ void LCD_Showchar(unsigned char Line,unsigned char Columu,unsigned char Char) { LCD_SetCursor(Line,Columu); LCD_WriteDate(Char); } /** *¹¦ÄÜ£ºÏÔʾ×Ö·û´®º¯Êý *²ÎÊý£ºLine ÐÐ £¬Columu ÁÐ £¬String ÒªÏÔʾµÄ×Ö·û´® *·µ»ØÖµ£ºvoid */ void LCD_ShowString(unsigned char Line,unsigned char Columu,unsigned char *String) { unsigned char i; LCD_SetCursor(Line,Columu); for(i=0;String!=' |