標題: 溫度濕度監(jiān)測 [打印本頁]

作者: 洛臻么么噠    時間: 2017-11-24 22:48
標題: 溫度濕度監(jiān)測
#include"lcd.h"


void Read_Busy()           //忙檢測函數(shù),判斷bit7是0,允許執(zhí)行;1禁止
{
    unsigned char sta;      //
    LCD1602_DB = 0xff;
    LCD1602_RS = 0;
    LCD1602_RW = 1;
    do
    {
        LCD1602_EN = 1;
        sta = LCD1602_DB;
        LCD1602_EN = 0;    //使能,用完就拉低,釋放總線
    }while(sta & 0x80);
}

void Lcd1602_Write_Cmd(unsigned char cmd)     //寫命令
{
    Read_Busy();
    LCD1602_RS = 0;
    LCD1602_RW = 0;
    LCD1602_DB = cmd;
    LCD1602_EN = 1;
    LCD1602_EN = 0;   
}

void Lcd1602_Write_Data(unsigned char dat)   //寫數(shù)據(jù)
{
      Read_Busy();
      LCD1602_RS = 1;
      LCD1602_RW = 0;
      LCD1602_DB = dat;
      LCD1602_EN = 1;
      LCD1602_EN = 0;
}

void LcdSetCursor(unsigned char x,unsigned char y)  //坐標顯示
{
    unsigned char addr;
    if(y == 0)
        addr = 0x00 + x;
    else
        addr = 0x40 + x;

    Lcd1602_Write_Cmd(addr|0x80);
}

//按指定位置顯示一個字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
        Y &= 0x1;
        X &= 0xF; //限制X不能大于15,Y不能大于1
        if (Y) X |= 0x40; //當(dāng)要顯示第二行時地址碼+0x40;
        X |= 0x80; //算出指令碼
        Lcd1602_Write_Cmd(X); //發(fā)命令字
        Lcd1602_Write_Data(DData); //發(fā)數(shù)據(jù)
}


void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str)     //顯示字符串
{
    LcdSetCursor(x,y);      //當(dāng)前字符的坐標
    while(*str != '\0')
    {
        Lcd1602_Write_Data(*str++);
    }
}

void InitLcd1602()              //1602初始化
{
    Lcd1602_Write_Cmd(0x38);    //打開,5*8,8位數(shù)據(jù)
    Lcd1602_Write_Cmd(0x0c);
    Lcd1602_Write_Cmd(0x06);
    Lcd1602_Write_Cmd(0x01);    //清屏   
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1