找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1541|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

LCD顯示器靜態(tài)顯示字符

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:269935 發(fā)表于 2018-1-1 23:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>
#include<intrins.h>
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P2^5;
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
#define DataPort P0
void DelayUs2x (unsigned char t)
{
  while (--t);
}
void DelayMs (unsigned char t)
{
   while(t--)
  {
     DelayUs2x(245);
     DelayUs2x(245);
  }
}
bit LCD_Check_Busy (void)
{
  RS_CLR;
  RW_SET;
  EN_CLR;
  _nop_();
  EN_SET;
  return (bit)(DataPort & 0x80);
}
void LCD_Write_Com (unsigned char com)
{
  while (LCD_Check_Busy());
  RS_CLR;
  RW_CLR;
  EN_SET;
  DataPort= com;
  _nop_();
  EN_CLR;
}
void LCD_Write_Data (unsigned char Data)
{
  while (LCD_Check_Busy());
  RS_SET;
  RW_CLR;
  EN_SET;
  DataPort= Data;
  _nop_();
  EN_CLR;
}
void LCD_Clear (void)
{
  LCD_Write_Com(0x01);
  DelayMs (5);
}
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
  if(y == 0)
    {
     LCD_Write_Com (0x80 + x);
    }
  else
    {
     LCD_Write_Com (0xc0 + x);
    }
   while (*s)
      {
    LCD_Write_Data (*s);
    s ++;
      }
}
void LCD_Write_Char (unsigned char x,unsigned char y,unsigned char Data)
{
  if (y == 0)
    {
    LCD_Write_Com (0x80 + x);
    }
  else
    {
     LCD_Write_Com (0xc0 + x);
    }
    LCD_Write_Data (Data);
}
void LCD_Init (void)
{
LCD_Write_Com (0x38);
DelayMs (5);
LCD_Write_Com (0x38);
DelayMs (5);
LCD_Write_Com (0x38);
DelayMs (5);
LCD_Write_Com (0x38);
LCD_Write_Com (0x08);
LCD_Write_Com (0x01);
LCD_Write_Com (0x06);
DelayMs (5);
LCD_Write_Com (0x0C);
}
void main (void)
{
  LCD_Init();
  LCD_Clear();
  while (1)
  {
    LCD_Write_Char (7,0,'o');
    LCD_Write_Char (8,0,'k');
    LCD_Write_String (1,1,"hellow world");
  while (1);
}
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表