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

📄 stc12c5a60s2-pdip40+ds18b20+lcd1602ʦ

📁 基于8051仿真 STC12C5A60S2-PDIP40+DS18B20+LCD1602
💻
字号:
/*------------------------------------------------------------------------------*/
//File:	LCD1602_8.H
//Note:	LCD1602 Mini Driver. 
/*------------------------------------------------------------------------------*/
#include <intrins.h>

/*------------------------------------------------------------------------------*/
//LCD接口定义					
sfr		 IO	= 0x80;				//P0-0x80,P1-0x90,P2-0xA0,P3-0xB0;
sbit	 RS = P2^0;				//LCD数据/命令选择端(H/L)
sbit	 RW = P2^1;				//LCD读/写选择端(H/L)
sbit	 E  = P2^2;				//LCD使能控制
sbit     bz = IO^7;				//LCD忙标志位



/*------------------------------------------------------------------------------*/
//数据定义
#define uchar unsigned char
#define uint unsigned int

uchar lcdcounter;
uchar  m;


/*------------------------------------------------------------------------------*/
//函数声明		
void lcd_busy(void);					//测试LCD忙碌状态程序
void lcd_wcmd(unsigned char cmd);		//写入指令到LCD程序
void lcd_wdat(unsigned char dat);		//写入数据到LCD程序
void lcd_pos (unsigned char x, bit y);	//LCD数据指针位置程序
//void printc(unsigned char CHAR);		//显示字符
void prints(unsigned char *string);		//显示字符串
void lcd_init(void);					//LCD初始化设定程序
//void lcd_moveto(unsigned char position);//LCD光标移动到指定位



/*------------------------------------------------------------------------------*/
//测试LCD忙碌状态
void lcd_busy(void)
{	
	do
	{
		  E = 0;
		  _nop_();
		  _nop_();
		  RS = 0;		//指令
		  _nop_();
		  _nop_();
		  RW = 1;		//读出
		  _nop_();
		  _nop_();
		  IO = 0xff;
		  _nop_();
		  _nop_();
		  E = 1;
		  _nop_();
		  _nop_();
	}while(bz);		//bz=1表示忙,bz=0表示空闲
	E = 0;
	_nop_();
    _nop_();		
}




/*------------------------------------------------------------------------------*/
//写入指令到LCD
void lcd_wcmd(unsigned char cmd)
{							
	lcd_busy();	//检测忙
	RS = 0;		//指令
	_nop_();
    _nop_();
	RW = 0;		//写入
	_nop_();
    _nop_();
	E = 1;
	_nop_();
    _nop_();	
	IO = cmd;	//指令
	E = 0;		//下降沿有效
	_nop_();
    _nop_();	
}




/*------------------------------------------------------------------------------*/
//写入数据函数
void lcd_wdat(unsigned char Data)
{
	lcd_busy();  //检测忙
	RS = 1;		 //数据
	_nop_();
    _nop_();
	RW = 0;		 //写入
	_nop_();
    _nop_();
	E = 1;
	_nop_();
    _nop_();
	IO = Data;	 //数据
	E = 0;		 //下降沿有效
	_nop_();
    _nop_();
}




/*------------------------------------------------------------------------------*/
//LCD数据指针位置程序
void lcd_pos(unsigned char x, bit y)
{
    lcdcounter=x;						
	if(y)
	   lcd_wcmd(x|0xc0);	//y=1,第二行显示;y=0,第一行显示		0<=x<16
	else 
	   lcd_wcmd(x|0x80);	//数据指针=80+地址码(00H~27H,40H~67H)
}




/*------------------------------------------------------------------------------*/
//显示字符
/*
void printc(unsigned char CHAR)
{
	lcd_wdat(CHAR);
}
*/



/*------------------------------------------------------------------------------*/
//显示字符串
void prints(unsigned char *string)
{
	unsigned char i;
//	do{lcd_wdat(string[i]);i++;}while(string[i]!='\0');//生成代码比for循环大
	for(i=0;string[i]!='\0';i++)
	    lcd_wdat(string[i]);//有时用for循环也好
}



/*------------------------------------------------------------------------------*/
//LCD初始化设定
void lcd_init()
{						
	lcd_wcmd(0x38);		//设置LCD为16X2显示,5X7点阵,八位数据接口
	lcd_wcmd(0x06);		//LCD显示光标移动设置(光标地址指针加1,整屏显示不移动)
	lcd_wcmd(0x0c);		//LCD开显示及光标设置(光标不闪烁,不显示"_")
	lcd_wcmd(0x01);		//清除LCD的显示内容
}



///*------------------------------------------------------------------------------*/
//LCD光标移动到指定位
//void lcd_moveto(unsigned char position)
//{
//    lcd_wcmd(0x01);
//	register cmd=0x80;
//    lcdcounter=position;
//    if (position > 59)
//        position += 0x18;
//    else
//    {   
//	    if (position > 39)
//		    position -= 0x14;
//        else
//        {       
//			if (positIOn > 19)
//				positIOn += 0x2c;
//        }
//    }
//    cmd=cmd|position;
//    lcd_wcmd(cmd);
//}

⌨️ 快捷键说明

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