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

📄 lcd1602.c

📁 msp320F247单片机的AD采样及液晶1602显示
💻 C
字号:
 #include  <msp430x24x.h>
#include "All_functions.h"
//****************************--

#define RS_SET (P5OUT|=BIT2);
#define RS_CLR (P5OUT&=~BIT2);
#define RW_SET (P5OUT|=BIT1);
#define RW_CLR (P5OUT&=~BIT1);
#define E_SET P5OUT|=BIT0;
#define E_CLR P5OUT&=~BIT0;
#define DataPort_in P4IN;

//*****************************
//延时子程序
void delay(unsigned int t)
{
    unsigned int i,j;
    for(i=0;i<t;i++)
      for(j=0;j<20;j++); //t*15 us
}

//***************************************
//检测忙标志
//***************************************
void busy()
{ unsigned char temp;
do{
   RS_CLR;    //RS=0;
   RW_SET;     //RW=1;
   E_CLR;     //E=0;
   delay(100);
   E_SET;      //E=1;
   P4OUT=0xff;
   
   P4DIR=0x00;      //LCD数据端口为输入状态
   delay(50);
   temp=DataPort_in;
   E_CLR;    //E=0;
   }while(temp&0x80);  //Lcd_Bus&0x80 
}

//***************************************
//写指令代码
//***************************************
void WriteCommand(unsigned char Command)
{
   E_CLR;         //E=0;
   RW_SET;         //RW=1;
   busy();
   RW_CLR;        //RW=0;
   RS_CLR;        //RS=0;
   P4DIR=0xff;           //设置为输出
   delay(100);   
   P4OUT=Command;    //写指令
   delay(20);
   E_SET;          //E=1;
   delay(20);
   E_CLR;         //E=0;
 }

//***************************************
//写显示数据
//***************************************
void WriteData(unsigned char LCDData)
{
   E_CLR;       //E=0;
   RS_CLR;      //RS=0;
   RW_SET;       //RW=1;
   busy();
   RS_SET;       //RS=1;
   delay(20);
   RW_CLR;      //RW=0;
   P4DIR=0xff;         //设置为输出
   delay(100);
   P4OUT=LCDData;
   E_SET;        //E=1;
   delay(20);
   E_CLR;       //E=0;
 }
 
//***************************************
//初始化程序
//***************************************
void LCD_Init()
{
  P4DIR|=0XFF;
  P5DIR=BIT0+BIT1+BIT2;
 WriteCommand(0x38);	//设置接口DB宽度(8位)和LCM显示行数(2行)
 WriteCommand(0x08);	//
 WriteCommand(0x01);	//执行清屏操作
 WriteCommand(0x06);	//设置光标为加1模式
 WriteCommand(0x0c);	//设置光标为移位模式
}
//*******************************************************

//LCD显示电压值

//*****************************************************
void LCD_display(unsigned char address,unsigned char data)
{
  WriteCommand(address);
  WriteData(data);
}

⌨️ 快捷键说明

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