求一个12864画点简单程序,和一个画图的简单程序,不要教程 要亲测过可以才行。

求一个12864画点简单程序,和一个画图的简单程序,不要教程 要亲测过可以才行。,第1张

//如果只是要话一个点的话简单,这里是个串口程序

#include <reg52.h>

#include <intrins.h>

#define uchar unsigned char

#define uint unsigned int

/*****LCD接口定义*****/

sbit SID = P1^0 //串行数据

sbit SCLK = P1^1//串行同步时钟

/*****汉字地址表*****/

uchar code addr_tab[]={

0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行汉字位置

0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行汉字位置

0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行汉字位置

0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行汉字位置

}

/*****n(ms)延时子程序*****/

void delayms(uint t) //约延时n(ms)

{

uint i

while(t--)

{

for(i=0i<125i++)

}

}

/*****串行发送一个字节*****/

void SendByte(uchar Dbyte)

{

uchar i

for(i=0i<8i++)

{

SCLK = 0

Dbyte=Dbyte<<1 //左移一位

SID = CY//移出的位给SID

SCLK = 1

SCLK = 0

}

}

/*****写指令*****/

void Lcd_WriteCmd(uchar Cbyte )

{

//delayms(1)

SendByte(0xf8) //11111,RW(0),RS(0),0

SendByte(0xf0&Cbyte) //高四位

SendByte(0xf0&Cbyte<<4) //低四位(先执行<<)

}

/*****写数据*****/

void Lcd_WriteData(uchar Dbyte )

{

//delayms(1)

SendByte(0xfa) //11111,RW(0),RS(1),0

SendByte(0xf0&Dbyte) //高四位

SendByte(0xf0&Dbyte<<4) //低四位(先执行<<)

}

/*****初始化LCD*****/

void Lcd_Init(void)

{

delayms(3)

Lcd_WriteCmd(0x30) //选择基本指令集

delayms(1)

Lcd_WriteCmd(0x30) //选择8bit数据流

delayms(1)

Lcd_WriteCmd(0x0c) //开显示(无游标、不反白)

delayms(1)

Lcd_WriteCmd(0x01) //清除显示,并且设定地址指针为00H

delayms(2)

}

void pic_Disp(uchar x,uchar y)//显示一个点

{

Lcd_WriteCmd(0x34) //切换到扩充指令,

Lcd_WriteCmd(0x34)//关闭图形显示

Lcd_WriteCmd(0x80+y)//行地址

Lcd_WriteCmd(0x80+x)//列地址,如果是下半屏这里多加8

Lcd_WriteData(0)//写数据 D15-D8

Lcd_WriteData(1)//写数据 D7-D0

Lcd_WriteCmd(0x36)//打开图形显示

}

void main()

{

Lcd_Init()

pic_Disp(1,1)

while(1)

}

给你测试了,行可行

//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 BF0x80 //用于检测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=0k<xk++)

}

*/

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=1i<=ni++)

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=0i<8i++)

{

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=0i<count)

{

WRData(english[i*2])

WRData(english[i*2+1])

i++

}

}

//显示连续字串(半宽字符)

void ShowNUMChar(Uchar addr,Uchar i,Uchar count)

{

Uchar j

for(j=0j<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=0i<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=0j<0x20)

{

WRCommand(addr+j)//设定DDRAM地址

WRData(0x00)

WRData(i)

j++

}

}

void CLEARGDRAM(void)

{

Uchar j

Uchar i

WRCommand(0x34)

WRCommand(0x36)

for(j=0j<32j++)

{

WRCommand(0x80+j)

WRCommand(0x80)//X坐标

for(i=0i<32i++)//

{

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=0j<hightj++)//32

{ //先上半屏

WRCommand(Y1+j) //Y总坐标,即第几行

WRCommand(0x80)//X坐标,即横数第几个字节开始写起

for(i=0i<clongi++)//

{

WRData(TAB1[clong*j+i])

}

//后下半屏

for(k=0k<clongk++)//

{

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()

{}

}

引脚号 引脚名称 方向 功能说明

1 VSS - 模块的电源地

2 VDD - 模块的电源正端

3 V0 - LCD驱动电压输入端

4 RS(CS) H/L 并行的指令/数据选择信号;串行的片选信号

5 R/W(SID) H/L 并行的读/写选择信号;串行的数据口

6 E(CLK) H/L 并行的使能信号;串行的同步时钟

7 DB0 H/L 数据0

8 DB1 H/L 数据1

9 DB2 H/L 数据2

10 DB3 H/L 数据3

11 DB4 H/L 数据4

12 DB5 H/L 数据5

13 DB6 H/L 数据6

14 DB7 H/L 数据7

15 PSB H/L 并/串行接口选择:H-并行;L-串行

16 NC 空脚

17 /RET H/L 复位 低电平有效

18 NC 空脚

19 LED_A (LED+5V) 背光源正极(加int?)

20 LED_K (LED-OV) 背光源负极


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11129203.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存