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

📄 lcd和定时.txt

📁 4线接法lcd1602的程序。已通过调试
💻 TXT
字号:
//文件包含
#include <reg51.h>
#include <string.h>
#include <intrins.h>
#include<absacc.h>
#include<math.h>
//宏定义数据类型
#define 	INT8U		unsigned char
#define 	INT16U		unsigned int
#define     uchar       unsigned char
#define     uint        unsigned int
#define 	ulong   	unsigned long
//引脚定义
#define  LCD_Data  P0
sbit LCD1602_RS = P0^0;
sbit LCD1602_RW = P0^1;
sbit LCD1602_EN = P0^2;
sbit dac0832_cs = P2^3;
//全局变量定义
uchar code ASCII[]={"0123456789ABCDEFnnnnnnnnnnnn"};
uchar testnum=0;


/*************************************液晶显示*******************************************
*******************************************************************************************
******************************************************************************************/
 void delay_nms(unsigned int n)
{
    unsigned int i=0,j=0;
    for (i=n;i>0;i--)
     for (j=0;j<1140;j++);
}
void Delayms(void)
{
 uchar TempCycA =5;//10
 uint TempCycB;
 while(TempCycA--)
 {
  TempCycB=6269;
  while(TempCycB--);
 };
}

/******************** LCD PART *************************************/
void LCD_delay(void)
{
  unsigned char i;
  for(i=40;i>0;i--)
    ;
}

void LCD_en_command(unsigned char command)
{

  LCD1602_RS=0;
  LCD1602_RW=0;
  LCD1602_EN=0;

  LCD_Data |=(command & 0xf0);
  LCD_Data &=(command & 0xf0) | 0x0f;

  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;

  LCD_Data |=(command & 0x0f)<<4;
  LCD_Data &=(command & 0x0f)<<4 | 0x0f;
  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{

  LCD1602_RS=1;
  LCD1602_RW=0;
  LCD1602_EN=0;
  LCD_Data |=(dat & 0xf0);
  LCD_Data &=(dat & 0xf0) | 0x0f;

  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;

  LCD_Data |=(dat & 0x0f)<<4;
  LCD_Data &=(dat & 0x0f)<<4 | 0x0f;
  LCD1602_EN=1;

  LCD_delay();
  LCD1602_EN=0;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
  unsigned char address;
  if (y ==0)
      address = 0x80 + x;
  else
      address = 0xC0 + x;
  LCD_en_command(address);
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
  LCD_set_xy( x, y );
  LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
    LCD_set_xy( X, Y );             //set address
    while (*s)                      // write character
    {
      //LCDIO=*s;                   //严重错误!!!
      LCD_en_dat(*s);
      s ++;
    }
}
/********************************************************************/
void LCD_init(void)
{
  LCD_en_command(0x01);
  delay_nms(5);
  LCD_en_command(0x01);
  delay_nms(5);
  LCD_en_command(0x28);
  delay_nms(5);
  LCD_en_command(0x28);
  delay_nms(5);
  LCD_en_command(0x28);
  delay_nms(5);
  LCD_en_command(0x0C);
  delay_nms(5);
  LCD_en_command(0x80);
  delay_nms(5);
  LCD_en_command(0x01);
  delay_nms(5);
}
/******************************************************************/



/******************************************中断********************************************
*******************************************************************************************
******************************************************************************************/
void steepdelay(void) interrupt 1
{
   TH0=0x00;

 TL0=0x00;

 TR0=1;

   testnum++;
   

}
/******************************************中断_结束********************************************
*******************************************************************************************
**************************************************************************************/


//定时器初始化
void interruptInit(void)
{
	  TMOD=0x01;
	  TH0=0x00;
	  TL0=0x00;
	  TR0=1;
	  ET0=1;
	  EA=1;
}
/****************************************主程序*******************************************
*******************************************************************************************
*****************************************************************************************/
void main(void)
{
          interruptInit();
	  LCD_init(); //LCM初始化
           LCD_write_string(0,0 ,"       ");
	  Delayms();
          Delayms();
	  LCD_write_string(0,0 ,"waiting      ");
	  Delayms();
          Delayms();
           LCD_write_string(0,0 ,"       ");
	  Delayms();
          Delayms();
          LCD_write_string(0,0 ,"welcoming      ");
	  Delayms();
          Delayms();
           LCD_write_string(0,0 ,"               ");
	  Delayms(); LCD_init(); //LCM初始化
	  while(1)
	  {
		            LCD_write_string(0,0 ,"Motor      ");
                             LCD_write_string(0,2 ,"zhaosdfjj       ");
                             LCD_write_char(9,1,ASCII[testnum]);




	   }

}

⌨️ 快捷键说明

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