求51单片机LCD12864串行显示程序,只用SID口和SCLK口,能显示输出四行中文的,最好写上main函数,谢谢

 我来答
GUEL86
2012-08-08 · TA获得超过5855个赞
知道大有可为答主
回答量:5538
采纳率:86%
帮助的人:2689万
展开全部
//LCD12864字库系列(控制器ST7920A),单片机:89S52,晶振:12M,
//串口连接 与 并口连接 ( 串口时 屏蔽 并行模块)
//并行连接方式,P2.0-RS,P2.1-RW,P2.2-E
#include<reg52.h>
#include <intrins.h>
sbit RS=P3^2; //串口时为CS
sbit RW=P3^1; //串口为SID
sbit E=P3^0; //串口为时钟SCLK
sbit stop=P2^2;
sbit PSB=P3^4;
sbit REST=P3^3;
//以下是用<at89x51.h>头文件的定义
/*
#define RS P2_0
#define RW P2_1 //定义引脚
#define E P2_2
#define PSB P2_3
#define REST P2_4
#define Data P1
#include<at89x51.h>
*/
#define BF 0x80 //用于检测LCM状态字中的Busy标识
typedef unsigned int Uint;
typedef unsigned char Uchar;
//字符串例子
//"F1--English",也可以往里面写入汉字码,一个汉字由两个码组成
const Uchar F1English[]={0x46,0x31,0x2d,0x2d,0x45,0x6e,0x67,0x6c,0x69,0x73,0x68,0x00};
const Uchar lengthF1=6; //字符串长度
//汉字,直接可以写入字形
unsigned char code uctech[] = {"有限公司"};
const Uchar lengthCF3=8;
Uchar code TAB1[]={
/*-- 调入了一幅图像:D:\公司的文件\程序图片\未命名11.bmp --*/
/*-- 宽度x高度=128x64 --*/
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0xAE,0x90,0x00,0x00,0x00,0x00,0x00,
0x95,0x55,0x48,0x80,0x00,0x00,0x00,0x00,
0x2B,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xA8,0x00,0x22,0x15,0x20,0x00,0x00,0x00,
0x97,0xFB,0x00,0x00,0x00,0x00,0x00,0x00,
0x45,0x55,0x08,0xA0,0x00,0x00,0x00,0x0A,
0x6F,0xF4,0x00,0x00,0x00,0x00,0x00,0x00,
0xB2,0x80,0x40,0x00,0x04,0x40,0x00,0x00,
0xBA,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x4D,0x55,0x15,0x15,0x20,0x00,0x00,0x95,
0xD5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xE8,0x40,0x40,0x00,0x00,0x00,0x4A,
0xAA,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x2A,0x00,0x40,0x00,0x00,0x15,
0x54,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFD,0xD0,0xAA,0x01,0x00,0x00,0x25,
0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xB6,0x00,0x10,0x00,0x01,0x4A,
0x49,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFD,0xE8,0x40,0x00,0x00,0x11,
0x00,0x24,0x84,0x00,0x00,0x00,0x00,0x00,
0xAB,0xFF,0xFF,0x55,0x00,0x00,0x00,0x24,
0x02,0x49,0x5E,0xA0,0x00,0x00,0x00,0x00,
0x84,0xBF,0xFF,0xF4,0x88,0x00,0x00,0x00,
0x10,0x05,0xFF,0xF4,0x00,0x00,0x00,0x00,
0x29,0x0B,0xFF,0xFA,0x20,0x00,0x00,0x00,
0x02,0xBF,0xFF,0xFC,0x00,0x00,0x00,0x00,
0x44,0xA0,0x57,0xFD,0x80,0x00,0x00,0x00,
0x08,0x5F,0xFF,0xFF,0x80,0x00,0x00,0x00,
0x91,0x0A,0xAA,0xF6,0x50,0x00,0x00,0x00,
0x41,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,
0x44,0xA0,0x01,0x1B,0x84,0x00,0x00,0x00,
0x26,0xFF,0xFF,0xFF,0x90,0x00,0x00,0x00,
0x11,0x0A,0xAA,0x6D,0x68,0x00,0x00,0x00,
0x0B,0xFB,0xFF,0xEF,0xE0,0x00,0x00,0x00,
0xC4,0xA0,0x01,0x02,0x80,0x00,0x00,0x00,
0x43,0xF1,0xFE,0x63,0xF0,0x00,0x00,0x00,
0x15,0x55,0x54,0x55,0x6A,0x00,0x00,0x00,
0x9F,0xE3,0xFC,0x87,0x38,0x00,0x00,0x00,
0xCA,0xAB,0x91,0x00,0x90,0x00,0x00,0x00,
0x07,0xC1,0xFA,0x2A,0x80,0x00,0x00,0x00,
0x25,0xFF,0xFE,0x95,0x2A,0x00,0x00,0x00,
0x2F,0x13,0xFE,0xFC,0x10,0x00,0x00,0x00,
0x95,0xFF,0xFF,0xC0,0x50,0x00,0x00,0x00,
0x0F,0x41,0xFF,0xF3,0x80,0x00,0x00,0x00,
0x4F,0xFF,0xFF,0xF9,0x2A,0x00,0x00,0x00,
0x9F,0x08,0xFF,0xD4,0x00,0x00,0x00,0x00,
0xB3,0xFF,0xFF,0xFE,0x54,0x80,0x00,0x00,
0x1E,0xA0,0x7F,0xA0,0x00,0x00,0x00,0x00,
0x5F,0xFE,0x7F,0xFE,0xAA,0x00,0x00,0x00,
0x5F,0x57,0xFE,0x00,0x00,0x00,0x00,0x00,
0xAF,0xFD,0x7F,0xFF,0x94,0x80,0x00,0x00,
0x1F,0xFE,0xE8,0x00,0x00,0x00,0x00,0x00,
0x7F,0xFA,0x7F,0x5F,0xCA,0x00,0x00,0x00,
0x3F,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xAF,0xF1,0x7F,0xDE,0xF5,0x40,0x00,0x00,
0x1A,0xA0,0x80,0x00,0x00,0x00,0x00,0x00,
0xDF,0xF2,0x3F,0xFC,0xC2,0x00,0x00,0x00,
0x50,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x2F,0xFA,0xBF,0xFF,0xF4,0xA0,0x00,0x00,
0x05,0x42,0x00,0x00,0x00,0x00,0x00,0x00,
0x97,0xFE,0x3F,0xFF,0xE3,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x68,0xFF,0xDF,0xD5,0x78,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x5F,0xFF,0x48,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD0,0xAA,0xF4,0xA0,0xAA,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0A,0x45,0x09,0x05,0x11,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA1,0x28,0xA0,0x00,0x44,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x42,0x04,0x52,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA5,0x09,0x51,0x00,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x50,0x04,0x4A,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xAA,0x05,0x50,0x21,0x48,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x90,0x02,0x84,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD4,0x05,0x48,0x10,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x81,0x20,0x00,0x02,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA4,0x84,0x92,0x48,0x94,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x48,0x10,0x00,0x00,0x21,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//这个是在串口时指令和数据之间的延时
/*
void delay10US(Uchar x)
{
Uchar k;
for(k=0;k<x;k++);
}
*/
const Uchar delay=250; //延时时间常数
static void Wait1ms(void)//延迟1 ms
{
Uchar cnt=0;
while (cnt<delay) cnt++;
}
//延迟n ms
void WaitNms(int n)
{
Uchar i;
for(i=1;i<=n;i++)
Wait1ms();
}
void stopint(void)//中断程序
{
if(stop==0)
while(1);
}
//**************************************************************************//
//以下是并口时才开的
//读忙标志,
void RDBF(void)
{
Uchar temp;
RS=0; // RS=0
RW=1; // RW=1
while(1)
{
P1=0xFF; //数据线为输入
E=1;
temp=P1;
E=0; // E=0
if ((temp&0x80)==0) break;
}
}
//写数据到指令寄存器
void WRCommand(Uchar comm)
{
RDBF();
RW=0;
P1=comm;
E=1;
E=0;
}
//写数据到数据寄存器
void WRData(Uchar TEMP)
{
RDBF();
RS=1;
RW=0;
P1=TEMP;
E=1;
E=0;
stopint();
}
/////////////////////////////////////////////////////////////////////////////////
//以下是串口时开的读写时序
/*void SendByteLCD(Uchar WLCDData)
{
Uchar i;
for(i=0;i<8;i++)
{
if((WLCDData<<i)&0x80)RW=1;
else RW=0;
E=0;
E=1 ;
}
}
SPIWR(Uchar Wdata,Uchar WRS)
{
SendByteLCD(0xf8+(WRS<<1));
SendByteLCD(Wdata&0xf0);
SendByteLCD((Wdata<<4)&0xf0);
}
void WRCommand(Uchar CMD)
{
RS=0;
RS=1;
SPIWR(CMD,0);
delay10US(90);//89S52来模拟串行通信,所以,加上89S52的延时,
}
void WRData(Uchar Data)
{
RS=0;
RS=1;
SPIWR(Data,1);
}
*/
/*******************************************************************/
//初始化LCD-8位接口
void LCDInit(void)
{ // PSB=0; //串口
PSB=1;//并口时选这个,上一行取消
REST=1;
REST=0;
REST=1;
WRCommand(0x30); //基本指令集,8位并行
WRCommand(0x06); //启始点设定:光标右移
WRCommand(0x01); //清除显示DDRAM
WRCommand(0x0C); //显示状态开关:整体显示开,光标显示关,光标显示反白关
WRCommand(0x02); //地址归零
}
//显示数组字符串(显示半宽字型16*8点阵)
void ShowQQChar(Uchar addr,Uchar *english,Uchar count)
{
Uchar i;
WRCommand(addr); //设定DDRAM地址
for(i=0;i<count;)
{
WRData(english[i*2]);
WRData(english[i*2+1]);
i++;
}
}
//显示连续字串(半宽字符)
void ShowNUMChar(Uchar addr,Uchar i,Uchar count)
{
Uchar j;
for(j=0;j<count;)
{
WRCommand(addr); //设定DDRAM地址
WRData(i+j);
j++;
WRData(i+j);
addr++;
j++;
}
}
//自定义字符写入CGRAM
void WRCGRAM(Uchar data1,Uchar data2,Uchar addr)
{
Uchar i;
for(i=0;i<16;)
{
WRCommand(addr+i); //设定CGRAM地址
WRData(data1);
WRData(data1);
i++;
WRCommand(addr+i); //设定CGRAM地址
WRData(data2);
WRData(data2);
i++;
}
}
//显示自定义的字符,并把这个字符填满全屏16*16
void ShowCGChar(Uchar addr,Uchar i)
{
Uchar j;
for(j=0;j<0x20;)
{
WRCommand(addr+j); //设定DDRAM地址
WRData(0x00);
WRData(i);
j++;
}
}
void CLEARGDRAM(void)
{
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<32;j++)
{
WRCommand(0x80+j);
WRCommand(0x80);//X坐标
for(i=0;i<32;i++)//
{
WRData(0x00);
}
}

}
//写入GDRAM 绘图,Y是Y绘图坐标,2个字节一行,CLONG是图形长度,以字节
//为单位;HIGHT是图形高度,TAB是图形数据表.12864M的图形显示是相当于256*32点阵.
//由两屏128*32上下两屏组成,同一行的下屏的头地址紧接上屏的未地址。
//绘图在串口输入时,会比在并口下的输入要慢一些
void WRGDRAM(Uchar Y1,Uchar clong,Uchar hight,Uchar *TAB1)
{
Uint k;
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<hight;j++)//32
{ //先上半屏
WRCommand(Y1+j); //Y总坐标,即第几行
WRCommand(0x80);//X坐标,即横数第几个字节开始写起
for(i=0;i<clong;i++)//
{
WRData(TAB1[clong*j+i]);
}
//后下半屏

for(k=0;k<clong;k++)//
{
WRData(TAB1[clong*(j+hight)+k]);
}

}
}
void menu(void)
{
LCDInit();
ShowNUMChar(0x80,0x01,0x0f);//显示半宽特殊符号
ShowNUMChar(0x90,0x30,0x0f);//显示半宽0~?数字标点
ShowNUMChar(0x88,0x41,0x0f);//显示半宽A~P大写
ShowNUMChar(0x98,0x61,0x0f);//显示半宽a~p小写
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
WRCGRAM(0xff,0x00,0x40);//写入横
WRCGRAM(0x00,0xff,0x50);//写入横2
WRCGRAM(0xaa,0xaa,0x60);//写入竖
WRCGRAM(0x55,0x55,0x70);//写入竖2
ShowCGChar(0x80,0x00);//显示横并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,02);//显示横2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,04);//显示竖并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,06);//显示竖2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
WRCGRAM(0x00,0x00,0x40);//清CGRAM1
WRCGRAM(0x00,0x00,0x50);//清CGRAM2
WRCGRAM(0xaa,0x55,0x40);//写入点
WRCGRAM(0x55,0xaa,0x50);//写入点2
ShowCGChar(0x80,00);//显示点并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,02);//显示点2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowQQChar(0x80,uctech,lengthCF3);//显示'有限公司',以下共四行
ShowQQChar(0x90,uctech,lengthCF3);
ShowQQChar(0x88,uctech,lengthCF3);
ShowQQChar(0x98,uctech,lengthCF3);
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
}
void menu2(void)
{ CLEARGDRAM();
WRGDRAM(0x80,16,32,TAB1);
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
}
//主函数
void main(void)
{
menu();//初始化及半宽字符和点横竖汉字扫描
menu2();//绘图显示
for(;;)
{;}
}
更多追问追答
追问
看程序里是并口的,把注释的串口去掉注释,把并口注释就行了?
追答
就是了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式