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

📄 lcd_zb成功2.c

📁 这个程序可以在LCD显示器上显示字符串
💻 C
字号:
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^2;
sbit RW=P2^1;
sbit E=P2^0;
#define dataport P0
#define busy 0x80
uchar xpos;
uchar ypos;
/////////////////////////////
void delay5ms(void)
{
  uint i=5552;
  while(i--);
}
////////////////////////////
void checkbusy(void)
{
 dataport=0xff;
 RS=0;
 RW=1;
_nop_();
E=1;
_nop_();
while(dataport&busy);
E=0;
}
////////////////////////////
void writeir(uchar cmd,uchar attribc)
{
 if(attribc) checkbusy();
 RS=0;
 RW=0;
 _nop_();
 dataport=cmd;
 _nop_();
 E=1;
 _nop_();
 _nop_();
 E=0;
}
////////////////////////////
void writeddr(char c)
{
 checkbusy();
RS=1;
RW=0;
 _nop_();
 dataport=c;
 _nop_();
E=1;
 _nop_();
 _nop_();
E=0;
}
////////////////////////////
void lcdpos(uchar xpos,uchar ypos)
{
 uchar tmp;
xpos&=0x0f;
ypos&=0x01;
tmp=xpos;
if(ypos==1)
tmp|=0xc0;
tmp|=0x80;
writeir(tmp,0);
}
////////////////////////////
void lcdreset()
{
 writeir(0x38,0);
 writeir(0x38,1);
 writeir(0x08,1);
 writeir(0x01,1);
 writeir(0x06,1);
 writeir(0x0f,1);
}
////////////////////////////
void writechar(uchar xpos,uchar ypos,uchar c)
{
 lcdpos(xpos,ypos);
writeddr(c);
}
////////////////////////////
void main()
{
 lcdreset();
delay5ms();
writechar(0,1,'A');
while(1);
}
































































⌨️ 快捷键说明

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