求个单片机控制12864ZB液晶屏的简单程序
型号12864ZBBLWABBA5.0V只要能输出数字就好。。。多谢。。。=.=么有人鸟我。。真的是只需要一个。。。能让俺液晶屏亮起来能出字的小程序。。。ARDUINO网...
型号12864ZB
BLWABBA 5.0V
只要能输出数字就好。。。
多谢。。。
=.=么有人鸟我。。
真的是只需要一个。。。能让俺液晶屏亮起来能出字的小程序。。。
ARDUINO网站上的示例试过了不行。。。
就比如下面这个程序,运行但是液晶屏只是全屏亮。。
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.print("hello, world!");
}
void loop() {
}
在线等
(再强调下。。是用arduino..谢谢几位的回答但是都没有解决问题..) 展开
BLWABBA 5.0V
只要能输出数字就好。。。
多谢。。。
=.=么有人鸟我。。
真的是只需要一个。。。能让俺液晶屏亮起来能出字的小程序。。。
ARDUINO网站上的示例试过了不行。。。
就比如下面这个程序,运行但是液晶屏只是全屏亮。。
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.print("hello, world!");
}
void loop() {
}
在线等
(再强调下。。是用arduino..谢谢几位的回答但是都没有解决问题..) 展开
4个回答
展开全部
在使用下例程序之前要先根据你的电路定义你的IO口
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#define uchar unsigned char // 8bit, 0 ~ 255
#define uint unsigned int // 16bit, 0 ~ 65,535
#define ulong unsigned long // 32bit, 0 ~ 4,294,967,295
/*-----------建立自定义演示用字符库-----------*/
uchar code CCTAB[]={
/*-- 文字: 实 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x00,0x01,0x00,0x7F,0xFE,0x48,0x02,0x86,0x84,0x02,0x80,0x10,0x80,0x0C,0x80,
0x04,0x84,0xFF,0xFE,0x01,0x00,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x0C,0x60,0x04,
/*-- 文字: 验 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x40,0xFC,0x40,0x08,0xA0,0x48,0xA0,0x49,0x10,0x4A,0x0E,0x4D,0xF4,0x48,0x00,
0x7C,0x48,0x06,0x48,0x05,0x48,0x1D,0x50,0xE5,0x10,0x44,0x24,0x17,0xFE,0x08,0x00,
/*-- 文字: 中 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x04,0x7F,0xFE,0x41,0x04,0x41,0x04,0x41,0x04,0x41,0x04,
0x7F,0xFC,0x41,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00
};
uchar code symbo[]={
/*-- 调入了一幅图像:D:\guoq files\technic support\pic\128x32 Symbo.bmp --*/
/*-- 宽度x高度=128x32 --*/
0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,
0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x08,0x00,0x80,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,
0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,
0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//-----------------------------------
// Delay Routine
//-----------------------------------
void delay100us(void) //delay TIMER1*1 ms for 12MHz
{
uchar data i;
for(i=0;i<=10;i++)
{
_nop_();
_nop_();
}
}
void delayms( uint m ) // 12MHz Xtal, close to ms value
{
uint j;
uint i;
for(i=0; i<m; i++)
for(j=0; j<109; j++)
_nop_();
}
//-----------------------------------
//直接访问方式驱动子程序
//-----------------------------------
/*
void SdCmd(uchar Command) //send command{
uchar xdata *wcom_addr;
uchar xdata *rcom_addr;
uchar busy;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
wcom_addr=0x8000;
*wcom_addr = Command;
}
void SdData(uchar DData) //send display data
{
uchar xdata *wdata_addr;
uchar xdata *rcom_addr;
uchar busy;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
wdata_addr =0x8100;
*wdata_addr = DData;
}
uchar RdData()
{
uchar xdata *rcom_addr;
uchar xdata *rdata_addr;
uchar busy,DData;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
rdata_addr =0x8300;
DData =*rdata_addr;
return(DData);
}
*/
//-----------------------------------
// 串行通讯方式驱动子程序
//-----------------------------------
//uchar bdata transdata; //该变量可为位操作之变量
//sbit transbit = transdata^7;
//sbit SCLK = P3^6;
//sbit SID = P3^7;
//sbit CS = P3^1;
//-----------------------------------
/*void SdCmd(uchar Command) //send command
{
uchar i,j,buffur[3];
SCLK = 0;
CS = 1;
buffur[0]=0xf8;
buffur[1]=Command&0xf0;
buffur[2]=(Command&0x0f)<<4;
for(i=0;i<3;i++)
{
transdata=buffur[i];
for(j=0;j<8;j++)
{
SID=transbit;
SCLK=1;
SCLK=0;
transdata=transdata<<1;
}
}
CS=0;
delayms(100);
}
//void SdData(uchar DData) //send display data
{
uchar i,j,buffur[3];
SCLK = 0;
CS = 1;
buffur[0]=0xfa;
buffur[1]=DData&0xf0;
buffur[2]=(DData&0x0f)<<4;
for(i=0;i<3;i++)
{
transdata=buffur[i];
for(j=0;j<8;j++)
{
SID=transbit;
SCLK=1;
SCLK=0;
transdata=transdata<<1;
}
}
CS=0;
delayms(100);
}
*/
//-----------------------------------
// 间接控制方式驱动子程序
//-----------------------------------
#define LCDBUS P1
sbit RS = P3^1;
sbit RW = P3^7;
sbit E = P3^6;
sbit PSB = P3^4;
sbit RST = P3^5;
//------------------------------------
void SdCmd(uchar Command) //send command
{
// uchar busy;
RS = 0;
/* RW = 1;
do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RW=0;
LCDBUS = Command;
E = 1;
E = 0;
delay100us();
}
void SdData(uchar DData) //send display data
{
// uchar busy;
RS = 0;
/* RW = 1;
do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RS=1;
RW=0;
LCDBUS = DData;
E = 1;
E = 0;
delay100us();
}
uchar RdData()
{
// uchar busy;
uchar DData;
RS = 0;
RW = 1;
/* do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RS=1;
LCDBUS=0xff;
E=1;
DData = LCDBUS;
E = 0;
return(DData);
}
//-----西文写入函数----------------
void PrintASCII(uint x,y,uchar *pstr) //通用函数
{
uint addr;
y=y<<4;
addr=y|0x80+x;
SdCmd(addr);
while(*pstr>0)
{
SdData(*pstr++);
}
}
//----中文写入函数-----------------
void PrintGB(uchar x,y,uchar *pstr)
{
uint addr;
y=y<<4;
addr=y|0x80+x;
SdCmd(addr);
while(*pstr>0)
{
SdData(*pstr++);
delayms(300); //演示用
}
}
//----初始化函数-----------------
void initLCM()
{
RST=0;
delayms(5);
RST=1;
delayms(800);
SdCmd(0x30); /* 设置工作方式(8位总线) */
SdCmd(0x06); /* 设置输入方式 */
SdCmd(0x0f); /* 设置显示方式 */
SdCmd(0x01); /* 清屏 */
delayms(2);
}
//----清屏函数------------------
void ClearRAM()
{
uchar i,j;
// SdCmd(0x01);
// delayms(2);
SdCmd(0x34);
for(i=0;i<32;i++)
{
SdCmd(i|0x80);
SdCmd(0x80);
for(j=0;j<16;j++)
{
SdData(0x00);//
SdData(0x00);
}
}
SdCmd(0x30);
}
//---- 画图函数-----------------------------
void ShowBmp(uchar x,y, width,high,uchar *bmp)
{
uchar i,j;
SdCmd(0x34);
SdCmd(0x36);
for(i=y;i<(y+high);i++)
{
if (i<32)
{
SdCmd(0x80|i);
SdCmd(0x80|x);
}
else
{
SdCmd(0x80|(i-32));
SdCmd(0x80|(x+8));
}
for(j=0;j<width;j++)
{
SdData(*bmp++);
SdData(*bmp++); //
}
}
SdCmd(0x30);
}
//---画点函数----------------
void Draw_Dot(uint x,y)
{
uchar m,n;
uint k;
if(y>=32)
{
y=y-32;
x=x+128;
}
SdCmd(y|0x80);
k=x/16;
SdCmd(k|0x80);
k=0x8000;
k=k>>x%16;
m=RdData();
m=RdData()|k>>8;
n=RdData()|k;
k=x/16;
SdCmd(y|0x80);
SdCmd(k|0x80);
SdData(m);
SdData(n);
}
//--- 画线函数---------------
void Draw_Line(uint x1,y1,x2,y2)
{
uint temp;
int dalt_x,dalt_y,err=0;
if (y1>y2)
{
temp=x1;
x1=x2;
x2=temp;
temp=y1;
y1=y2;
y2=temp;
}
Draw_Dot(x1,y1);
dalt_x=x2-x1;
dalt_y=y2-y1;
if(dalt_x>=0)
{
if(dalt_y>dalt_x)//k>1
{
while(y1<y2)
{
if(err<0)
{
x1=x1+1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
else
{
y1=y1+1;
err=err-dalt_x;
}
Draw_Dot(x1,y1);
}
}
else // 0<=k=<1
{
if (dalt_y==0)
y1=y1-1;
while(x1<x2)
{
if(err<0)
{
x1=x1+1;
err=err+dalt_y;
}
else
{
y1=y1+1;
x1=x1+1;
err=err+dalt_y-dalt_x;
}
Draw_Dot(x1,y1);
}
}
}
else
{
dalt_x=x1-x2;
if(dalt_y>dalt_x)//k<-1
{
while(y1<y2)
{
if(err<0)
{
x1=x1-1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
else
{
y1=y1+1;
err=err-dalt_x;
}
Draw_Dot(x1,y1);
}
}
else //0>k>=-1
{
if (dalt_y==0)
y1=y1-1;
while(x1>x2)
{
if(err<0)
{
x1=x1-1;
err=err+dalt_y;
}
else
{
x1=x1-1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
Draw_Dot(x1,y1);
}
}
}
}
//-----自建字库函数-------------------
void Set_CGRAM(uint num,uchar *pstr)
// num 汉字个数;pstr:汉字数组名
{
uchar i;
SdCmd(0x40);
for(i=0;i<num*32;i++)// 计算数据量
{
SdData(*pstr++);
}
}
//--功能演示函数-------------------------
void quxian1()
{
SdCmd(0x06);
PrintGB( 0,0,"画面不动光标地址加1 指令代码为06");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x04);
PrintGB( 15,0,"画面不动光标地址减1 指令代码为04");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x07);
PrintGB( 0,0,"画面整体左移1 位指令代码为07");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x05);
PrintGB( 15,0,"画面整体右移1 位指令代码为05");
delayms(3000);
SdCmd(0x06);
}
//----做图演示函数------------------------------------
void quxian2()
{
uint code data1[48]={88,89,85,87,89,90,89,89,
88,86,87,86,88,89,90,94,
95,96,96,97,99,99,101,103,
101,101,100,103,105,113,113,
117,117,116,114,107,110,114,
113,112,115,112,113,119,120,
125,124,128};
uint a1,b1,a2,b2,i;
SdCmd(0x01);
delayms(2);
SdCmd(0x0c);
PrintASCII(0,0," Time");
PrintASCII(14,1,"Temp");
SdCmd(0x34);
SdCmd(0x36);
Draw_Line(1, 60, 125,60);// 设置坐标 X coordinate
Draw_Line(1, 15, 1, 60);// 设置坐标 Y coordinate
delayms(1000);
a1=1;
for ( i=0;i<40;i++)
{
b1=data1[i]-70;
Draw_Dot(a1,b1);//画点
a1=a1+3;
}
delayms(3000);
a1=1;
for ( i=0;i<40;i++)
{
b1=data1[i]-70;
b2=data1[i+1]-70;
a2=a1+3;
Draw_Line(a1,b1,a2,b2);//画线
a1=a2;
}
SdCmd(0x32);
}
//-----------------------------------
// Main Program
//-----------------------------------
void main()
{
SP=0x60;
EA=0;
// PSB=0; //串行接口选择
PSB=1; //并行接口选择
LCDBUS=0xff; // 初始化接口
RW=1;
E =0;
initLCM();
Set_CGRAM(3,CCTAB);
while(1)
{
SdCmd(0x01); /* 清屏 */
delayms(2);
ClearRAM();
//--自定义字符显示
SdCmd(0x0f);
SdCmd(0x82);
SdData(0x00);
SdData(0x00);
SdData(0x00);
SdData(0x02);
SdData(0x00);
SdData(0x04);
//-- 字库字符显示
PrintASCII(8,0," ST7920 演示程序");
delayms(3000);
//-- 图画显示
SdCmd(0x01); /* 清屏 */
delayms(2);
ClearRAM();
ShowBmp(0,0,8,32,symbo);
ShowBmp(0,32,8,32,symbo);
delayms(3000);
//-- 写入功能展示
SdCmd(0x01);
delayms(2);
quxian1();
delayms(3000);
//-- 做图功能展示
ClearRAM();
quxian2(); // 仅在并行接口使用
delayms(3000);
}
}
// end of program
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#define uchar unsigned char // 8bit, 0 ~ 255
#define uint unsigned int // 16bit, 0 ~ 65,535
#define ulong unsigned long // 32bit, 0 ~ 4,294,967,295
/*-----------建立自定义演示用字符库-----------*/
uchar code CCTAB[]={
/*-- 文字: 实 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x00,0x01,0x00,0x7F,0xFE,0x48,0x02,0x86,0x84,0x02,0x80,0x10,0x80,0x0C,0x80,
0x04,0x84,0xFF,0xFE,0x01,0x00,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x0C,0x60,0x04,
/*-- 文字: 验 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x40,0xFC,0x40,0x08,0xA0,0x48,0xA0,0x49,0x10,0x4A,0x0E,0x4D,0xF4,0x48,0x00,
0x7C,0x48,0x06,0x48,0x05,0x48,0x1D,0x50,0xE5,0x10,0x44,0x24,0x17,0xFE,0x08,0x00,
/*-- 文字: 中 --*/
/*-- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x04,0x7F,0xFE,0x41,0x04,0x41,0x04,0x41,0x04,0x41,0x04,
0x7F,0xFC,0x41,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00
};
uchar code symbo[]={
/*-- 调入了一幅图像:D:\guoq files\technic support\pic\128x32 Symbo.bmp --*/
/*-- 宽度x高度=128x32 --*/
0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,
0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x08,0x00,0x80,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,
0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,
0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,
0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,
0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//-----------------------------------
// Delay Routine
//-----------------------------------
void delay100us(void) //delay TIMER1*1 ms for 12MHz
{
uchar data i;
for(i=0;i<=10;i++)
{
_nop_();
_nop_();
}
}
void delayms( uint m ) // 12MHz Xtal, close to ms value
{
uint j;
uint i;
for(i=0; i<m; i++)
for(j=0; j<109; j++)
_nop_();
}
//-----------------------------------
//直接访问方式驱动子程序
//-----------------------------------
/*
void SdCmd(uchar Command) //send command{
uchar xdata *wcom_addr;
uchar xdata *rcom_addr;
uchar busy;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
wcom_addr=0x8000;
*wcom_addr = Command;
}
void SdData(uchar DData) //send display data
{
uchar xdata *wdata_addr;
uchar xdata *rcom_addr;
uchar busy;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
wdata_addr =0x8100;
*wdata_addr = DData;
}
uchar RdData()
{
uchar xdata *rcom_addr;
uchar xdata *rdata_addr;
uchar busy,DData;
do
{
rcom_addr=0x8200;
busy = *rcom_addr&0x80;
}
while (busy==0x80);
rdata_addr =0x8300;
DData =*rdata_addr;
return(DData);
}
*/
//-----------------------------------
// 串行通讯方式驱动子程序
//-----------------------------------
//uchar bdata transdata; //该变量可为位操作之变量
//sbit transbit = transdata^7;
//sbit SCLK = P3^6;
//sbit SID = P3^7;
//sbit CS = P3^1;
//-----------------------------------
/*void SdCmd(uchar Command) //send command
{
uchar i,j,buffur[3];
SCLK = 0;
CS = 1;
buffur[0]=0xf8;
buffur[1]=Command&0xf0;
buffur[2]=(Command&0x0f)<<4;
for(i=0;i<3;i++)
{
transdata=buffur[i];
for(j=0;j<8;j++)
{
SID=transbit;
SCLK=1;
SCLK=0;
transdata=transdata<<1;
}
}
CS=0;
delayms(100);
}
//void SdData(uchar DData) //send display data
{
uchar i,j,buffur[3];
SCLK = 0;
CS = 1;
buffur[0]=0xfa;
buffur[1]=DData&0xf0;
buffur[2]=(DData&0x0f)<<4;
for(i=0;i<3;i++)
{
transdata=buffur[i];
for(j=0;j<8;j++)
{
SID=transbit;
SCLK=1;
SCLK=0;
transdata=transdata<<1;
}
}
CS=0;
delayms(100);
}
*/
//-----------------------------------
// 间接控制方式驱动子程序
//-----------------------------------
#define LCDBUS P1
sbit RS = P3^1;
sbit RW = P3^7;
sbit E = P3^6;
sbit PSB = P3^4;
sbit RST = P3^5;
//------------------------------------
void SdCmd(uchar Command) //send command
{
// uchar busy;
RS = 0;
/* RW = 1;
do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RW=0;
LCDBUS = Command;
E = 1;
E = 0;
delay100us();
}
void SdData(uchar DData) //send display data
{
// uchar busy;
RS = 0;
/* RW = 1;
do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RS=1;
RW=0;
LCDBUS = DData;
E = 1;
E = 0;
delay100us();
}
uchar RdData()
{
// uchar busy;
uchar DData;
RS = 0;
RW = 1;
/* do
{
LCDBUS=0xff;
E = 1;
busy = LCDBUS&0x80;
E = 0;
}
while (busy==0x80);*/
RS=1;
LCDBUS=0xff;
E=1;
DData = LCDBUS;
E = 0;
return(DData);
}
//-----西文写入函数----------------
void PrintASCII(uint x,y,uchar *pstr) //通用函数
{
uint addr;
y=y<<4;
addr=y|0x80+x;
SdCmd(addr);
while(*pstr>0)
{
SdData(*pstr++);
}
}
//----中文写入函数-----------------
void PrintGB(uchar x,y,uchar *pstr)
{
uint addr;
y=y<<4;
addr=y|0x80+x;
SdCmd(addr);
while(*pstr>0)
{
SdData(*pstr++);
delayms(300); //演示用
}
}
//----初始化函数-----------------
void initLCM()
{
RST=0;
delayms(5);
RST=1;
delayms(800);
SdCmd(0x30); /* 设置工作方式(8位总线) */
SdCmd(0x06); /* 设置输入方式 */
SdCmd(0x0f); /* 设置显示方式 */
SdCmd(0x01); /* 清屏 */
delayms(2);
}
//----清屏函数------------------
void ClearRAM()
{
uchar i,j;
// SdCmd(0x01);
// delayms(2);
SdCmd(0x34);
for(i=0;i<32;i++)
{
SdCmd(i|0x80);
SdCmd(0x80);
for(j=0;j<16;j++)
{
SdData(0x00);//
SdData(0x00);
}
}
SdCmd(0x30);
}
//---- 画图函数-----------------------------
void ShowBmp(uchar x,y, width,high,uchar *bmp)
{
uchar i,j;
SdCmd(0x34);
SdCmd(0x36);
for(i=y;i<(y+high);i++)
{
if (i<32)
{
SdCmd(0x80|i);
SdCmd(0x80|x);
}
else
{
SdCmd(0x80|(i-32));
SdCmd(0x80|(x+8));
}
for(j=0;j<width;j++)
{
SdData(*bmp++);
SdData(*bmp++); //
}
}
SdCmd(0x30);
}
//---画点函数----------------
void Draw_Dot(uint x,y)
{
uchar m,n;
uint k;
if(y>=32)
{
y=y-32;
x=x+128;
}
SdCmd(y|0x80);
k=x/16;
SdCmd(k|0x80);
k=0x8000;
k=k>>x%16;
m=RdData();
m=RdData()|k>>8;
n=RdData()|k;
k=x/16;
SdCmd(y|0x80);
SdCmd(k|0x80);
SdData(m);
SdData(n);
}
//--- 画线函数---------------
void Draw_Line(uint x1,y1,x2,y2)
{
uint temp;
int dalt_x,dalt_y,err=0;
if (y1>y2)
{
temp=x1;
x1=x2;
x2=temp;
temp=y1;
y1=y2;
y2=temp;
}
Draw_Dot(x1,y1);
dalt_x=x2-x1;
dalt_y=y2-y1;
if(dalt_x>=0)
{
if(dalt_y>dalt_x)//k>1
{
while(y1<y2)
{
if(err<0)
{
x1=x1+1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
else
{
y1=y1+1;
err=err-dalt_x;
}
Draw_Dot(x1,y1);
}
}
else // 0<=k=<1
{
if (dalt_y==0)
y1=y1-1;
while(x1<x2)
{
if(err<0)
{
x1=x1+1;
err=err+dalt_y;
}
else
{
y1=y1+1;
x1=x1+1;
err=err+dalt_y-dalt_x;
}
Draw_Dot(x1,y1);
}
}
}
else
{
dalt_x=x1-x2;
if(dalt_y>dalt_x)//k<-1
{
while(y1<y2)
{
if(err<0)
{
x1=x1-1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
else
{
y1=y1+1;
err=err-dalt_x;
}
Draw_Dot(x1,y1);
}
}
else //0>k>=-1
{
if (dalt_y==0)
y1=y1-1;
while(x1>x2)
{
if(err<0)
{
x1=x1-1;
err=err+dalt_y;
}
else
{
x1=x1-1;
y1=y1+1;
err=err+dalt_y-dalt_x;
}
Draw_Dot(x1,y1);
}
}
}
}
//-----自建字库函数-------------------
void Set_CGRAM(uint num,uchar *pstr)
// num 汉字个数;pstr:汉字数组名
{
uchar i;
SdCmd(0x40);
for(i=0;i<num*32;i++)// 计算数据量
{
SdData(*pstr++);
}
}
//--功能演示函数-------------------------
void quxian1()
{
SdCmd(0x06);
PrintGB( 0,0,"画面不动光标地址加1 指令代码为06");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x04);
PrintGB( 15,0,"画面不动光标地址减1 指令代码为04");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x07);
PrintGB( 0,0,"画面整体左移1 位指令代码为07");
delayms(3000);
SdCmd(0x01);
delayms(2);
SdCmd(0x05);
PrintGB( 15,0,"画面整体右移1 位指令代码为05");
delayms(3000);
SdCmd(0x06);
}
//----做图演示函数------------------------------------
void quxian2()
{
uint code data1[48]={88,89,85,87,89,90,89,89,
88,86,87,86,88,89,90,94,
95,96,96,97,99,99,101,103,
101,101,100,103,105,113,113,
117,117,116,114,107,110,114,
113,112,115,112,113,119,120,
125,124,128};
uint a1,b1,a2,b2,i;
SdCmd(0x01);
delayms(2);
SdCmd(0x0c);
PrintASCII(0,0," Time");
PrintASCII(14,1,"Temp");
SdCmd(0x34);
SdCmd(0x36);
Draw_Line(1, 60, 125,60);// 设置坐标 X coordinate
Draw_Line(1, 15, 1, 60);// 设置坐标 Y coordinate
delayms(1000);
a1=1;
for ( i=0;i<40;i++)
{
b1=data1[i]-70;
Draw_Dot(a1,b1);//画点
a1=a1+3;
}
delayms(3000);
a1=1;
for ( i=0;i<40;i++)
{
b1=data1[i]-70;
b2=data1[i+1]-70;
a2=a1+3;
Draw_Line(a1,b1,a2,b2);//画线
a1=a2;
}
SdCmd(0x32);
}
//-----------------------------------
// Main Program
//-----------------------------------
void main()
{
SP=0x60;
EA=0;
// PSB=0; //串行接口选择
PSB=1; //并行接口选择
LCDBUS=0xff; // 初始化接口
RW=1;
E =0;
initLCM();
Set_CGRAM(3,CCTAB);
while(1)
{
SdCmd(0x01); /* 清屏 */
delayms(2);
ClearRAM();
//--自定义字符显示
SdCmd(0x0f);
SdCmd(0x82);
SdData(0x00);
SdData(0x00);
SdData(0x00);
SdData(0x02);
SdData(0x00);
SdData(0x04);
//-- 字库字符显示
PrintASCII(8,0," ST7920 演示程序");
delayms(3000);
//-- 图画显示
SdCmd(0x01); /* 清屏 */
delayms(2);
ClearRAM();
ShowBmp(0,0,8,32,symbo);
ShowBmp(0,32,8,32,symbo);
delayms(3000);
//-- 写入功能展示
SdCmd(0x01);
delayms(2);
quxian1();
delayms(3000);
//-- 做图功能展示
ClearRAM();
quxian2(); // 仅在并行接口使用
delayms(3000);
}
}
// end of program
展开全部
#include <reg52.h> //包括一个52标准内核的头文件
//
sbit RS=P2^4;
sbit RW=P2^3;
sbit E=P2^2;
sbit P36=P3^6;
unsigned char n,k,h,l,m;
unsigned int c[6]={0xD6AA,0xD0D0,0xD1A7,0xD4BA};//输入汉字“知行学院 ”
void delay(unsigned int z) /*延时 z ms*/ //延时 z ms
{
unsigned int i;
unsigned char j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void zhiling(unsigned char a)/*写命令*/ //写命令
{
E=0;RS=0;RW=0;
E=1;
P1=a;
delay(5); //延时 5ms
E=0;
delay(5); //延时 5ms
}
void shuju(unsigned char b) /*写数据*/ //写数据
{
E=0;RS=1;RW=0;
E=1;
P1=b;
delay(5); //延时 5ms
E=0;
delay(5); //延时 5ms
}
void shuju2(unsigned int w) /*写汉字数据*/
//写汉字数据
{
shuju(((w&0xff00)>>8)&0xff);
shuju(w&0xff);
}
void init() /*初始化*/ //初始化
{
zhiling(0x01); //清屏
zhiling(0x30); //功能设置
zhiling(0x0d); //开/关显示设置
zhiling(0x06); //输入方式设置
zhiling(0x14); //光标右移
}
void main()/*主程序*/
{
unsigned char i;
delay(500);
init();
zhiling(0x80); //第一行
for(i=0;i<4;i++)
shuju2(c[i]);
}
//
sbit RS=P2^4;
sbit RW=P2^3;
sbit E=P2^2;
sbit P36=P3^6;
unsigned char n,k,h,l,m;
unsigned int c[6]={0xD6AA,0xD0D0,0xD1A7,0xD4BA};//输入汉字“知行学院 ”
void delay(unsigned int z) /*延时 z ms*/ //延时 z ms
{
unsigned int i;
unsigned char j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void zhiling(unsigned char a)/*写命令*/ //写命令
{
E=0;RS=0;RW=0;
E=1;
P1=a;
delay(5); //延时 5ms
E=0;
delay(5); //延时 5ms
}
void shuju(unsigned char b) /*写数据*/ //写数据
{
E=0;RS=1;RW=0;
E=1;
P1=b;
delay(5); //延时 5ms
E=0;
delay(5); //延时 5ms
}
void shuju2(unsigned int w) /*写汉字数据*/
//写汉字数据
{
shuju(((w&0xff00)>>8)&0xff);
shuju(w&0xff);
}
void init() /*初始化*/ //初始化
{
zhiling(0x01); //清屏
zhiling(0x30); //功能设置
zhiling(0x0d); //开/关显示设置
zhiling(0x06); //输入方式设置
zhiling(0x14); //光标右移
}
void main()/*主程序*/
{
unsigned char i;
delay(500);
init();
zhiling(0x80); //第一行
for(i=0;i<4;i++)
shuju2(c[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
前面几个回答给的都是89c52的代码,跟avr不兼容。你自己帖的这个arduino不是12864的代码,是1602的,我做arduino实验的时候用过。
12864的驱动库官方是没有带的。淘宝上卖12864的卖家手里有库文件和例子程序。你可以向已经买过该宝贝的买家要一个。 淘宝里搜索 arduino 12864 然后点开宝贝,看谁买过并在线。然后弹对方消息。^_^
12864的驱动库官方是没有带的。淘宝上卖12864的卖家手里有库文件和例子程序。你可以向已经买过该宝贝的买家要一个。 淘宝里搜索 arduino 12864 然后点开宝贝,看谁买过并在线。然后弹对方消息。^_^
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-12-29
展开全部
一般控制方法都是通用的吧,
RS,RW ,E是关键
RS,RW ,E是关键
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询