⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1602b_lcd.c

📁 与C51相关模块LCD,24CXX,等的源代码程序
💻 C
字号:
/**********************************************************
TC1602B LCD DISPLAY WITH 4 BITS MODE
建立时间:2004年12月10号
修改日期:2005年1月12号
LCD第一行显示寄存器地址:0X80-0X8F
LCD第二行显示寄存器地址:0XC0-0XCF
**********************************************************/
#include <At89x51.h>
#include "1602B_LCD.h"
//--------------------------------------------------------
#define LCD_DATA_PORT P3
sbit 	LCD_EN=P3^4;
sbit 	LCD_RS=P3^5;
//--------------------------------------------------------
typedef unsigned char uchar;
code char Numtable[]="0123456789ABCDEF ";
//--------------------------------------------------------
void delay_nms(char i){for(;i>0;i--);}
//--------------------------------------------------------
void LCD_WR4bits(unsigned char c){
	//c<<=4;
	//unsigned char i=0x01,j=0x80,k=0;
	//for(;i<0x10;i<<=1,j>>=1){
	//	if(c&i)k|=j;
	//}
	LCD_EN=1;
	//LCD_DATA_PORT&=0x0f;
	LCD_DATA_PORT&=0xf0;
	LCD_DATA_PORT|=c;
	//LCD_DATA_PORT|=k;
	LCD_EN=0;
}
//--------------------------------------------------------
void LCD_init(void){
/*	delay_nms(50);
	LCD_RS=0;					//command
	LCD_WR4bits(0x03);			//set 8 bits
	delay_nms(10);
	LCD_WR4bits(0x03);			//set 8 bits
	delay_nms(10);
	LCD_WR4bits(0x03);			//set 8 bits
	delay_nms(10);
	LCD_WR4bits(0x02);			//set 4 bits
	LCD_WR4bits(0x08);
	delay_nms(2);
	LCD_WR4bits(0x00);			//显示开
	LCD_WR4bits(0x0c);
	delay_nms(2);
	LCD_WR4bits(0x00);			//光标设定
	LCD_WR4bits(0x06);
	delay_nms(2);
	LCD_RS=1;					//data
	delay_nms(10);
*/
	delay_nms(250);
	LCD_RS=0;					//command
	LCD_WR4bits(0x02);			//set 4 bits
	delay_nms(50);

	LCD_WR4bits(0x08);			//2 Lines,disp off 
	delay_nms(50);
	LCD_WR4bits(0x00);			//显示开
	LCD_WR4bits(0x0c);			//cursor off,blink off
	delay_nms(50);
	LCD_WR4bits(0x00);			//clean all
	LCD_WR4bits(0x01);
	delay_nms(5);
	LCD_WR4bits(0x00);			//inc mode,shift off
	LCD_WR4bits(0x06);

	LCD_RS=1;					//data
}
/*--------------------------------------------------------
LCD_set_xy        : 设置LCD显示的起始位置

输入参数:x、y    : 显示字符串的位置,X:0-15,Y:0-1
--------------------------------------------------------*/
void LCD_set_xy( uchar x, uchar y ){
    x=(y==0)?0x80+x:0xc0+x;
	LCD_RS=0;
	LCD_WR4bits(x>>4);
	LCD_WR4bits(x);
	LCD_RS=1;
}
//----------------------------------------------------
void LCD_char(uchar c){
	LCD_WR4bits(c>>4);
	LCD_WR4bits(c);
	delay_nms(2);
}
/*----------------------------------------------------
LCD_write_string  : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置		
----------------------------------------------------*/
void LCD_write_string(uchar X,uchar Y,uchar *s){
	LCD_set_xy( X, Y );
	while(*s)LCD_char(*s++);
}
//----------------------------------------------------
void LCD_digtal(uchar c){
	LCD_WR4bits(Numtable[c]>>4);
	LCD_WR4bits(Numtable[c]);
	delay_nms(2);
}
//----------------------------------------------------
void LCD_clear(void){
	LCD_RS=0;
  	delay_nms(2);
	LCD_WR4bits(0x00);
	LCD_WR4bits(0x01);
	delay_nms(2);
	LCD_RS=1;
	delay_nms(10);
}
//----------------------------------------------------
void LCD_home(void){
	LCD_RS=0;
  	delay_nms(2);
	LCD_WR4bits(0x00);
	LCD_WR4bits(0x02);
	delay_nms(2);
	LCD_RS=1;
	delay_nms(10);
}
//----------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -