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

📄 1602lcd.c

📁 1602液晶显示驱动程序
💻 C
字号:
#define EX_GLOBAL
#include "global.h"

const char   int2charLCD[]="0123456789 ";

void delay_us(unsigned char k) //当k=1时延迟19us
{ 

  while(k--)
  {
  }
}

void delay_ms(unsigned char k)
{ unsigned char i;
 while(k--)
{ for(i=0;i<256;i++);
}
}
bit lcd_bz()
	{                          // 测试LCD忙碌状态
	static bit result;
    RS=0;
	RW=1;
	E=1;
	TRISC = 0Xff;    
    delay_us(100);
	result = (bit)(PORTC&0x80);
	E=0;
	return result; 
	}
void write_LCD_command(unsigned command)		  //写指令
{
    while(lcd_bz());
	RW=0;
	RS=0;
	E=0;
	TRISC=0X00;
	PORTC=command;
    delay_us(100);
	E=1;
    delay_us(100);
	E=0;

}

void write_LCD_data(unsigned LCDdata)
{
    while(lcd_bz());
	RW=0;
	RS=1;
	E=1;
	TRISC=0X00;
	PORTC=LCDdata;
    delay_us(100);
	E=1;
    delay_us(100);
	E=0;
}
void init_LCD(void)
{
	write_LCD_command(0x38);
	delay_us(10);  	
	write_LCD_command(0x0d);
	delay_us(10); 
	write_LCD_command(0x06);
	delay_us(10); 


}
void clear_LCD()//清零、置位
{
    while(lcd_bz());
	RW=0;
	RS=0;
	E=0;
	TRISC=0X00;
	PORTC=0x01;
    delay_ms(256);
	E=1;
	E=0;

    while(lcd_bz());
	RW=0;
	RS=0;
	E=0;
	TRISC=0X00;
	PORTC=0x02;
    delay_us(100);
	E=1;
	E=0;	
} 
void gotoxy(unsigned x,unsigned y)
{
	if(x==1)  
		write_LCD_command(128+y);
	else
    	write_LCD_command(192+y);
}
void display_LCD_string(const char *p)
{
	while(*p)
	{
		write_LCD_data(*p);
		p++;
	delay_us(50); 
	}
}
void display_LCD_number(long int number)
{   char i=0;
    unsigned char temp[8];   
    for(i=0;i<7;i++)
{									
  temp[i]=10;
}
  i=0;
	while(number/10)
{
	temp[i]=number%10;
	number=number/10;
	i++;
}
  	temp[i]=number;
i=i+1;
	while(i--)
{
	write_LCD_data(int2charLCD[temp[i]]);

}
}

⌨️ 快捷键说明

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