#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的各种例程哦,给有需要的人,有的也照搬过来的不过也不行,头都大了。
兄弟给你发过去了~~注意查收
一周热门 更多>