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

📄 text1.c

📁 家庭保安
💻 C
字号:
#include"reg51.h"  		//#include"AT89X51.H"
#include"intrins.h"
typedef unsigned char BYTE;				//自定义了数据类型 BYTE为unsigned char ;
tepedef bit BOOL;

sbit LCD_RS=P2^5;
sbit LCD_RW=P2^6;
sbit LCD_EP=P2^7;

sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;

sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
	sbit P2_7=P2^7;

BYTE codedis1[]={"A"};	   //使用了自己定义的数据类型;
BYTE codedis2[]={"B"};
BYTE codedis3[]={"C"};
BYTE codedis4[]={"D"};
BYTE codedis5[]={"1"};
BYTE codedis6[]={"2"};
BYTE codedis7[]={"3"};

//----------------------------------------------------------------------------
delay(int ms)
{
  while(1)
  {
		 for(i=0;i<250;i++)
		 {
		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();
		 }
  }
}

//-------------------------------------------------------------------------------
BOOL led_bz()
{
 BOOL result;
 LCD_RS=0;				//0表示选择指令寄存器;1表示选择数据寄存器。
 LCS_RW=1;	   			//选择写入数据操作;    读取忙信号???1忙
 LCD_EP=1;

		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();
result=(BOOL)(P0&0X80);
LCD_EP=0; 				//EN高电平到低电平,表示有效;
return result;
}

//------------------------------------------------------------------------------
lcd_wcmd(BYTE cmd)
{
while(lcd_bz());
LCD_RS=0;
LCD_RW=0;
LCD_EP=0;
		  _nop_();
		   _nop_();
P0=cmd;
		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();

LCD_EP=1;			  //下降沿有效 ,使能位工作
		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();

LCD_EP=0;
}

//-----------------------------------------------------------------------------
lcd_pos(BYTE pos)
{
 lcd_wcmd(pos|0x80);
}

lcd_wdat(BYTE dat)
{
 while(lcd_bz);
 LCD_RS=1;
 LCD_RW=0;
 LCD_EP=0;
 P0=dat;
		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();
 LCD_EP=1;
 		  _nop_();
		   _nop_();
		    _nop_();
			 _nop_();
 LCD_EP=0;
}

//--------------------------------------------------------------------------------------------
lcd_init()
{
 lcd_wcmd(0x38);
 delay(1);
 lcd_wcmd(0x0c);
 delay(1);
 lcd_wcmd(0x06);
 delay(1);
 lcd_wcmd(0x01);
 delay(!);
}

//-------------------------------------------------------------------------------------------
main()
{
 unsigned char shujv=0x00;
 BYTE i;
 lcd_init();
 delay(10);

 lcd_wcmd(0x06);

 lcd_pos(0);
 i=0;
 while(dis1[i]!='\0')
 {
  lcd_wdat(dis1[i]);
  i++;
  delay(30);
  }

  lcd_pos(0x40);
  i=0;
  while(dis2[i]='\0')
  {
   lcd_wdat(dis2[i]);
   i++;
   delay(30);
  }
  delay(800);

  lcd_wcmd(0x01);

  delay(1);
  lcd_wcmd(0x04);

  lcd_pos(15);
  i=0;
  while(dis3[]!='\0')
  {
   lcd_wdat(dis3[i]);
   i++;
   delay(30);
  }

  lcd_pos(0x4f);
  i=0;
  while(dis4[i]!='\0')
  {
   lcd_wdat(dis4[i]);
   i++;
   delay(30);
  }
delay(800);

lcd_wcmd(0x01);
delay(200);

	//---------------------------------------------------------------------------------------------------
while(1)  		//安防 主程序
{
P1=0X00;
//P2_0=1;
P2=0X1F;
P1=0X01;
	if(P2_0==1)
	{
	 shujv=P2;
	 shujv=shujv&0x1e;
	 shujv=shujv>>1;
	 P3_7=0;
	 lcd_wcmd(0x01);
	 lcd_pos(0x40);
	 i=0;
	 while(dis5[i]!='\0')
	 {
	  lcd_wdat(dis5[i]);
	  i++;
	  delay(30);
	 }
	}


delay(200);
//P2_0=0;
P1=0X02;
	if(P2_0==1)
	{
	 shujv=shujv&0x1e;
	 shujv=shujv>>1;
	 P3_7=0;
	 lcd_wcmd(0x01);
	 lcd_pos(0x40);
	 i=0;
	 while(dis6[i]!='\0')
		 {
			lcd_wdat(dis6[i]);
			i++;
			delay(30);
		 }
	
	 }
delay(200);

//P2_0=0;
P1=0X04;
	if(P2_0==1)
	{
	 shujv=shujv&0x1e;
	 shujv=shujv>>1;
	 P3_7=0;
	 lcd_wcmd(0x01);
	 lcd_pos(0x40);
	 i=0;
	 while(dis6[i]!='\0')
		 {
			lcd_wdat(dis6[i]);
			i++;
			delay(30);
		 }
	
	 }
delay(200);
 



}

}


 }

}












⌨️ 快捷键说明

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