回 帖 发 新 帖 刷新版面

主题:1602液晶屏源代码

/*********************************************

本程序关于1602液晶屏驱动,

用的主芯片是stc89c52

开发软件KEIL4

开发语言C

硬件开发平台:

开发板:信盈达supper800

实现显示内容:

网站:www.edu118.com 

技术交流群:qq81146602

*********************************************/
#include <reg52.h>    
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^7;
sbit RW=P3^4;
sbit E =P3^5;

void delay(uint t); 
void SendCommandByte(uchar ch);
void SendDataByte(uchar ch);
void InitLcd();
void DisplayMsg1(uchar *p);
void DisplayMsg2(uchar *p);



void delay(uint t) 
{
for(;t!=0;t--) ;
}



void SendCommandByte(uchar ch) 
{
RS=0;
RW=0;
P0=ch;
E=0;
delay(1);
E=1;
delay(1000); //delay 40us
}


void SendDataByte(uchar ch) 

RS=1;
RW=0;
P0=ch;
E=0;
delay(1);
E=1;
delay(1000); //delay 40us
}



void InitLcd() 
{
SendCommandByte(0x38);
SendCommandByte(0x38); 
SendCommandByte(0x38); 
SendCommandByte(0x38);
SendCommandByte(0x08); 
SendCommandByte(0x01);
SendCommandByte(0x0c); 
SendCommandByte(0x06); 
}



void DisplayMsg1(uchar *p)
{
unsigned char count;
SendCommandByte(0x80);
for(count=0;count<16;count++)
{
SendDataByte(*p++);
}
}


void DisplayMsg2(uchar *p)
{
unsigned char count;
SendCommandByte(0xc0); 
for(count=0;count<16;count++)
{
SendDataByte(*p++);
}
}



void main(void)
{
char code msg1[16]=" www.edu118.com ";
char code msg2[16]="qq81146602";
InitLcd();  //调用液晶屏初始化函数
while(1)
{
DisplayMsg1(msg1);
DisplayMsg2(msg2);
delay(60000);
}
}

回复列表 (共2个回复)

沙发

板凳

欢迎大家来讨论交流:

网站:www.edu118.com 

技术交流群:qq81146602


我来回复

您尚未登录,请登录后再回复。点此登录或注册