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

📄 lcdforadc.h

📁 ds1820在msp430实测
💻 H
字号:
#include <msp430x22x4.h>

unsigned char number[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};

void WriteCommandLCM(unsigned char lcmcmd,unsigned char busy);//写指令
void WriteDataLCM(unsigned char lcmdata);//写数据
void ReadStatusLCM();//读状态字
//=============================================
void Delay(int v)
  {
   while(v!=0)v--;
  }
//=============================================
void LcmCls()//清屏
  {
    WriteCommandLCM(0x01,1);
  }
//=============================================
void WriteCommandLCM(unsigned char lcmcmd,unsigned char busy)//写指令
  {
    if(busy) ReadStatusLCM(); //根据需要检测忙
    P3DIR|=0x3c;
    P4OUT&=~BIT0;//RS=0
    P4OUT&=~BIT1;//RW=0
    P3OUT&=0xc3;//清高四位
    P3OUT|=(lcmcmd>>2)&0x3c;//输出高四位
    P4OUT|=BIT2;//E=1
    P4OUT&=~BIT2;//E=0
    P3OUT&=0xc3;
    P3OUT|=(lcmcmd<<2)&0x3c;//输出低四位
    P4OUT|=BIT2;//E=1
    P4OUT&=~BIT2;//E=0
  }
//=============================================
void WriteDataLCM(unsigned char lcmdata)//写数据
  {   
    ReadStatusLCM();
    P3DIR|=0x3c;
    P4OUT|=BIT0;//RS=1
    P4OUT&=~BIT1;//RW=0
    P3OUT&=0xc3;
    P3OUT|=(lcmdata>>2)&0x3c;//输出高四位
    P4OUT|=BIT2;//E=1
    P4OUT&=~BIT2;//E=0
    P3OUT&=0xc3;
    P3OUT|=(lcmdata<<2)&0x3c;//输出低四位
    P4OUT|=BIT2;//E=1
    P4OUT&=~BIT2;//E=0
  }
//=============================================
void ReadStatusLCM()//读状态字
  {
    unsigned char LCMStatus;
    P3DIR&=0xc3;
    P4OUT&=~BIT0;//RS=0
    P4OUT|=BIT1;//RW=1
    P4OUT|=BIT2;//E=1
    do{LCMStatus=P3IN&0x20;}
    while(LCMStatus);//检测忙信号
    P3DIR|=0x3c;
    P3OUT&=0xc3;
    P4OUT&=~BIT2;//E=0
  }
//=============================================
//按指定位置显示一个字符
void DisplayOneChar(unsigned char x, unsigned char y, unsigned char DData)
  {
    y&=0x1;
    x&=0xf;//限制x不能大于15,y不能大于1
    if(y) x|=0x40;//当要显示第二行时地址码+0x40;
    x|=0x80;//算出指令码
    WriteCommandLCM(x,1);//发命令字,定位光标
    WriteDataLCM(DData);//发数据
  }
//=============================================
//按指定位置显示一串字符
void DisplayListChar(unsigned char x, unsigned char y, unsigned char *DData)
  {
    unsigned char ListLength=0;
    y&=0x1;
    x&=0xf; //限制x不能大于15,y不能大于1
    while (DData[ListLength]>0x19) //若到达字串尾则退出
    {
      if(x<=0xf)
      {
        DisplayOneChar(x,y,DData[ListLength]); //显示单个字符
        x++;        
      }
      ListLength++;
    }
  }
//=============================================
void InitLcd()//初始化lcd
  {
    P3DIR|=0x3c;//P3为LCD输出
    P4DIR|=0x07;//RS=p4.0,RW=P4.1,E=P4.2
    P3OUT&=0xc3;
    Delay(3000);
    WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
    Delay(300);
    WriteCommandLCM(0x38,0);
    Delay(300);
    WriteCommandLCM(0x28,0);
    Delay(300);
    WriteCommandLCM(0x28,1); //显示模式设置,开始要求每次检测忙信号
    WriteCommandLCM(0x01,1); //显示清屏
    WriteCommandLCM(0x06,1); //显示光标移动设置
    WriteCommandLCM(0x0c,1); //显示开及光标设置
  }

⌨️ 快捷键说明

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