#include<reg52.h>
#include <intrins.h>
sbit WWR=P0^1;
sbit RRD=P0^2;
sbit CS=P0^3;
sbit A0=P0^4;
sbit REST=P0^5;
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x00,0x80,0x7F,0xC4,0x11,0x0C,0x11,0x10, //7
0x11,0x20,0x11,0x44,0x11,0x0C,0xFF,0xD0,
0x11,0x20,0x11,0x42,0x11,0x06,0x11,0x08,
0x21,0x10,0x21,0x20,0x41,0x40,0x01,0x00,
};
uchar code SysTab[8]={0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0x00};
uchar code ScrTab[10]={0x00,0x00,0xf0,0x00,0x40,0xf0,0x00,0x08,0x00,0x00};
void delayms(unsigned int x)//1ms
{
unsigned char j;
while(x--)
{for(j=0;j<125;j++)
{;}
}
}
void delay100us(unsigned char x)//100us
{
unsigned char j;
while(x--)
{for(j=0;j<12;j++)
{;}
}
}
void WriteCommand(uchar command)
{
CS=0;
RRD=1;
P1=command;
A0=1;
WWR=0;
WWR=1;
}
void WriteData(unsigned char LCDdata)
{
CS=0;
RRD=1;
P1=LCDdata;
A0=0;
WWR=0;
WWR=1;
}
void Init_LCD()
{ uchar i;
REST=1;
REST=0;
REST=1;
WriteCommand(0x40); //设置SYSTEM SET参数
for(i=0;i<8;i++)
{
WriteData(SysTab[i]);
}
/* WriteData(0x30);
WriteData(0x87);
WriteData(0x07);
WriteData(0x27);
WriteData(0x42);
WriteData(0xf0);
WriteData(0x28);
WriteData(0x00); */
WriteCommand(0x44); //设置SYSTEM SET Scroll参数
for(i=0;i<10;i++)
{
WriteData(ScrTab[i]);
}
/* WriteData(0x00);
WriteData(0x00);
WriteData(0xf0);
WriteData(0x00);
WriteData(0x40);
WriteData(0xf0);
WriteData(0x00);
WriteData(0x08);
WriteData(0x00);
WriteData(0x00); */
WriteCommand(0x5a); //HDOT SCR点不移位
WriteData(0x00);
WriteCommand(0x5b); //简单合成显示,L1为文本,L2为图形,L3为文本属性,单屏时不用四区
WriteData(0x04);
WriteCommand(0x59); //开显示及设显示状态
WriteData(0x44); //一,,三,区均开显示但不闪烁,光标显示关闭,二四区关显示
}
void Locatexy(uchar x,uchar y)
{
uint add;
add = (uint)y*0x28+x;
// if(attribs)temp += 0x40*256; // 如果需要就指向第二区,加上第二区首地址
WriteCommand( 0x46 ); // 光标Locate,定位
WriteData( (uchar)(add & 0xff) ); // 写入参数CSRL设置参数光标指针低8位
WriteData( (uchar)(add >>8 ) ); // 写入参数CSRH设置参数光标指针高8位
WriteCommand(0x5d);
WriteData(0x07);
WriteData(0x87);
WriteCommand(0x59);
WriteData(0x03);
}
void dprintf()
{ uchar i,j;
Locatexy(0,0);
WriteCommand(0x4f);
WriteCommand(0x42);
for(i=0;i<16;i++)
{ WriteData(table[i*2]);
}
Locatexy(0,1);
WriteCommand(0x4f);
WriteCommand(0x42);
for(j=0;j<16;j++)
{WriteData(table[i*2+1]);}
void qingping(void) //清文本区
{ uchar k;
WriteCommand(0x46); //设置光标指针0x0000-第一显示区,CSRW代码
WriteData(0x00);//列
WriteData(0x00);//行
WriteCommand(0x42); //设置数据写入,MWRITE代码
for (k=0x00;k<0xff;k++)
{
WriteCommand(0x20);
}
}
void clear1(void) //清图形点阵
{ uint i;
WriteCommand(0x4c); //光标向右
WriteCommand(0x46); //光标坐标设置
WriteData(0x00);
WriteData(0x00);
WriteCommand(0x42);
for(i=0;i<0xffff;i++)
{
WriteData(0x00);
}
}
void main(void)
{
Init_LCD();
clear1();
qingping();
Loc//dprintf(0,10,"图形方式测试");
while(1);}
就是什么都没有显哦,是什么原因哦,各位大哥帮看看,这还有一份SD1335的各种例程哦,给有需要的人,有的也照搬过来的不过也不行,头都大了。
那大虾,我在下半屏写入字模时,也就是第三显示区时,就显示乱码,第一和第三显示区都是图形显示方式的,但就是显示乱码。
还有啊,第一和第三区才是主显示区啊、也就是上半屏和下半屏啊。
ALIM2121.JPG (321.21 KB, 下载次数: 0)
下载附件
2012-5-8 10:54 上传
CmdWrite(0x40); //系统设置
DataWrite(0x32); //P1参数:单屏幕,CGROM+CGRAM1+CGRAM2
DataWrite(0x87); //P2参数:8点列
DataWrite(0x07); //P3参数:8点行
DataWrite(0x13); //P4参数:CR显示窗口宽度为 20
DataWrite(0x18); //P5参数:TC/R>=C/R+4
DataWrite(0xA0); //P6参数:160扫描行
DataWrite(0x14); //P7参数:APL AP>=CR+1
DataWrite(0x00); //P8参数:APH
CmdWrite(0x44); //显示区域设置
DataWrite(0x00); //显示一区首地址为 0000H
DataWrite(0x00);
DataWrite(0xA0); //显示一区的扫描行数 160行
DataWrite(0x00); //显示二区首地址为 0x1000H
DataWrite(0x10);
DataWrite(0xA0); //显示二区的扫描行数 160行
DataWrite(0x00); //显示三区首地址为 0x2000H
DataWrite(0x20);
CmdWrite(0x58); //显示状态设置,显示总开关
DataWrite(0x54); //打开各区显示和光标
CmdWrite(0x5b); //合成方式设置
DataWrite(0x08); //两重合成显示,一区文本,三区图形,三个区"或"关系
CmdWrite(0x5c); //CGRAM的起始地址为0x4000H
DataWrite(0x00);
DataWrite(0x40);
CmdWrite(0x5d); //光标形状设置
DataWrite(0x07);
DataWrite(0x06);
CmdWrite(0x4c); //光标移动方向设为向右
FullScreenFill(0x00,0x00,0x00); //清显示一区
FullScreenFill(0x00,0x10,0x00); //清显示二区
FullScreenFill(0x00,0x20,0x00); //清显示三区
CmdWrite(0x59); //打开显示总开关
DataWrite(0x54); //04无光标,05无闪烁,07闪烁
一周热门 更多>