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

📄 text1.c

📁 经典的1602液晶程序C51 初次接触液晶显示的朋友可以看看
💻 C
字号:
#include<reg52.h>
#include"Key_scan.h"
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="LENGTH:";
//uchar code table1[]="WWW.TXMCU.COM";
sbit lcden=P3^4;
sbit lcdrs=P3^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar num,temp;
uchar scan(void);

void delay(uint z)
{
	uint x,y;
	for(x=z;x>0;x--)
		for(y=110;y>0;y--);
}
void write_com(uchar com)
{
	lcdrs=0;
	P0=com;
	delay(5);
	lcden=1;
	delay(5);
	lcden=0;
}

void write_data(uchar date)
{
	lcdrs=1;
	P0=date;
	delay(5);
	lcden=1;
	delay(5);
	lcden=0;
}
void init()
{
	dula=0;
	wela=0;
	lcden=0;
	write_com(0x38);
	write_com(0x0e);
	write_com(0x06);
	write_com(0x01);
	write_com(0x80+0x10);
}
void main()
{
	init();
	temp=key;
	for(num=0;num<8;num++)
	{
		write_data(table[num]);
		delay(20);
	}
//	write_com(1);
//	write_com(0x80+0x53);
//	for(num=0;num<13;num++)
//	{
//		write_data(table1[num]);
//		delay(20);
//	}
//	for(num=0;num<16;num++)
//	{
//		write_com(0x18);
//		delay(20);
//	}
//	while(1);
	switch (temp);
		case ox11;write_data('1');break;
		case 0x21;write//第2个键按下显示2
		case 0x41;  //第3个键按下显示3
		case 0x81)  //第4个键按下显示4
		case 0x12)  //   5		   5
		case 0x22)  //	6		    6
		case 0x42)  //	 7			 7
		case 0x82)  //	  8			  8
		case 0x14)  //	   9		   9
		case 0x24)  //		 0		    0
		case 0x44)  //   设置
		case 0x84)  //	确定
		case 0x18)  //	 长度
		case 0x28)  //	  数量
		case 0x48)  //	  加速
		case 0x88)	// 	   减速
		delay(1);
}
uchar scan(void)
{
	uchar h,l;//定义行号和列号
	P1=0xf0; //P1口二极管显示初始值
	if((P1&0xf0)!=0xf0)		//P1口状态改变
	{
		delay(10);				 //延时10ms消除抖动
		if((P1&0xf0)!=0xf0)		 //有键按下
		{
			h=0xfe;				//开始扫描键盘 (行扫描)
			while((h&0x10)!=0)
			{
				P1=h;
				h=(P1&0x0f)|0xf0; //得到行号
				if((P1&0xf0)!=0xf0)
				{	
					l=(P1&0xf0)|0x0f;//得到列号
					P1=h;
					while((P1&h)!=h){}	  //等待按键弹起
					return((~h)+(~l)); 	 //有键按下时返回键盘码
				}
				else 
				h=(h<<1)|0x01;		   //改变行扫描位置
			}
			
		}
	
	}	 
 return(0);		//无键盘按下时返回0
}

⌨️ 快捷键说明

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