欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: LCD1602字母顯示 [打印本頁]

作者: abc121212    時間: 2018-7-16 14:02
標題: LCD1602字母顯示
#include<reg52.h>
#define LCD1602_DB  P0      //data bus 數據總線

sbit LCD1602_RS = P2^6;
sbit LCD1602_RW = P2^5;
sbit LCD1602_EN = P2^7;  
void InitLcd1602();
void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str);

void main()
{
    unsigned char str[] = "Welcome To You";
    InitLcd1602();
    LcdShowStr(0,0,str);
    while(1);
}

void Read_Busy()           //忙檢測函數,判斷bit7是0,允許執行;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)   //寫數據
{
      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 LcdShowStr(unsigned char x,unsigned char y,unsigned char *str)     //顯示字符串
{
    LcdSetCursor(x,y);      //當前字符的坐標
    while(*str != '\0')
    {
        Lcd1602_Write_Data(*str++);
    }
}
void InitLcd1602()              //1602初始化
{
    Lcd1602_Write_Cmd(0x38);    //打開,5*8,8位數據
    Lcd1602_Write_Cmd(0x0c);
    Lcd1602_Write_Cmd(0x06);
    Lcd1602_Write_Cmd(0x01);    //清屏   
}






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