📄 sed1335.c
字号:
#define LcdStatus (unsigned short *)0x22A00000
#define LcdDataW (unsigned short *)0x22A00000
#define LcdDataR (unsigned short *)0x22A00002
#define LcdComW (unsigned short *)0x22A00002 //CS2基地值为0x2200,本实验板中定义LCD使用CS2,地址为xxAx-xxxx
#define SED1335LAY1_l 0x0
#define SED1335LAY1_h 0x0
#define SED1335LAY2_l 0x0
#define SED1335LAY2_h 0x26
#define SED1335LAY3_l 0x0
#define SED1335LAY3_h 0x52
#define WidthX 320
#define WidthY 240
#define FontsW 12
#define FontsZ 16
//#include "bmp1335.h"
unsigned short *P;
unsigned char *DemoP;
unsigned char SED1335Init1[]={0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0};
unsigned char SED1335Init2[]={SED1335LAY1_l,SED1335LAY1_h,0xf0,SED1335LAY2_l,SED1335LAY2_h,0xf0,SED1335LAY3_l,SED1335LAY3_h,0x00,0xC0};
void Init1335(void);
void ClearScreen(void);
void ClearLayer1(void);
void ClearLayer2(void);
void ClearLayer3(void);
void ShowBitmap(unsigned char *Bmp);
void ShowText(void);
void ShowNovel(void);
void WriteChineseChar(unsigned short x, unsigned short y , unsigned char CharIndexH, unsigned char CharIndexL);
void Dot1335(unsigned short x, unsigned short y, unsigned char Mode, unsigned char Layer, unsigned char DotValue);
void WriteChinese(unsigned short x, unsigned short y , unsigned char CharIndexH, unsigned char CharIndexL);
void WriteAsci(unsigned short x, unsigned short y , unsigned char CharIndex);
unsigned char * TextWindowOut(unsigned short LeftTopX,unsigned short LeftTopY, unsigned short BottomRightX,unsigned short BottomRightY, unsigned char *RawText);
extern unsigned int GetOffetGBK(unsigned char Qh, unsigned char Wh);
extern unsigned char GBK1212[];
extern unsigned char Asci[];
extern unsigned char DemoChar[];
void Delay1335(void)
{
int i;
for(i=10;i>=0;i--)
{
;
}
}
void Init1335(void)
{
unsigned char WriteData;
int i;
unsigned char RdL,RdH;
P=LcdComW;
*P=0x40; //system set,8个参数
Delay1335();
P=LcdDataW;
for(i=0;i<8;i++)
{
*P=SED1335Init1[i]; //送具体指令参数:无边界、8*8点阵字体、80-9FH范围字幅代码、内部字符发生器有效,
Delay1335(); //交流驱动波形、字符宽度7H,字符高度7H,有效显示长度27H,LCD工作频率时间常数,
} //LCD的点行数F0H,显示屏一行所占显示缓冲区的字节数0028H
P=LcdComW;
*P=0x44; //设置显示RAM区中各显示区的起始地址及所占有的显示行数,它与system set中的AP参数结合,可确定显示区所占的字节数,该指令有10个参数。
Delay1335();
P=LcdDataW;
for(i=0;i<10;i++)
{
*P=SED1335Init2[i]; //给具体参数,分为4个显示区
Delay1335();
}
//right cursor
P=LcdComW;
*P=0x4c; //光标自由移动方向向右
Delay1335();
//hdot-scr
P=LcdComW;
*P=0x5A; //设置以点为单位的显示画面水平移动量,相当于一个字节内的卷动,带一个参数
Delay1335();
P=LcdDataW;
*P=0x00; //0H->7H,显示左移;7H->0H,显示右移
Delay1335();
//3-layer, all OR
P=LcdComW;
*P=0x5B; //规定画面重叠显示的合成方式及显示一、三区的显示属性
Delay1335();
P=LcdDataW;
*P=0x1C; //三重合成,三区:图形方式;一区:图形方式;合成关系:或
Delay1335();
//3-layer, on , no flash
P=LcdComW;
*P=0x59; //开显示,并规定各显示区及光标的显示方式
Delay1335();
P=LcdDataW;
*P=0x54; //三区:关闪烁;二、四区:关闪烁;一区:关闪烁;光标:关
Delay1335();
ClearScreen();
}
void ClearScreen(void)
{
//******now clear the screen*********//
int i;
//set address
P=LcdComW;
*P=0x46; //0x46:设置光标地址CSR。该地址两个功能:作为显示屏上光标显示的当前位置,作为显示缓冲区的当前地址指针。带两个参数
Delay1335();
P=LcdDataW;
*P=0x00; //地址低8位CSRL
Delay1335();
*P=0x00; //地址高8位CSRH
Delay1335();
//write data
P=LcdComW;
*P=0x42; //0x42:允许CPU连续地把显示数据写入显示区内
Delay1335();
P=LcdDataW;
for(i=0;i<(32*1024);i++)
{
*P=0x0;
Delay1335();
}
}
void ClearLayer1(void)
{
//******now clear the screen*********//
int i;
//set address
P=LcdComW;
*P=0x46; //0x46:设置光标地址CSR。该地址两个功能:作为显示屏上光标显示的当前位置,作为显示缓冲区的当前地址指针。带两个参数
Delay1335();
P=LcdDataW;
*P=SED1335LAY1_l; //地址低8位CSRL
Delay1335();
*P=SED1335LAY1_h; //地址高8位CSRH
Delay1335();
//write data
P=LcdComW;
*P=0x42; //0x42:允许CPU连续地把显示数据写入显示区内
Delay1335();
P=LcdDataW;
for(i=0;i<(40*240);i++)
{
*P=0x0;
Delay1335();
}
}
void ClearLayer2(void)
{
//******now clear the screen*********//
int i;
//set address
P=LcdComW;
*P=0x46; //0x46:设置光标地址CSR。该地址两个功能:作为显示屏上光标显示的当前位置,作为显示缓冲区的当前地址指针。带两个参数
Delay1335();
P=LcdDataW;
*P=SED1335LAY2_l; //地址低8位CSRL
Delay1335();
*P=SED1335LAY2_h; //地址高8位CSRH
Delay1335();
//write data
P=LcdComW;
*P=0x42; //0x42:允许CPU连续地把显示数据写入显示区内
Delay1335();
P=LcdDataW;
for(i=0;i<(40*240);i++)
{
*P=0x0;
Delay1335();
}
}
void ClearLayer3(void)
{
//******now clear the screen*********//
int i;
//set address
P=LcdComW;
*P=0x46; //0x46:设置光标地址CSR。该地址两个功能:作为显示屏上光标显示的当前位置,作为显示缓冲区的当前地址指针。带两个参数
Delay1335();
P=LcdDataW;
*P=SED1335LAY3_l; //地址低8位CSRL
Delay1335();
*P=SED1335LAY3_l; //地址高8位CSRH
Delay1335();
//write data
P=LcdComW;
*P=0x42; //0x42:允许CPU连续地把显示数据写入显示区内
Delay1335();
P=LcdDataW;
for(i=0;i<(40*240*3);i++)
{
*P=0x0;
Delay1335();
}
}
void ShowBitmap(unsigned char *Bmp)
{
int i;
//set address ly1
P=LcdComW;
*P=0x46;
Delay1335();
P=LcdDataW;
*P=SED1335LAY1_l;
Delay1335();
*P=SED1335LAY1_h;
Delay1335();
//write data
P=LcdComW;
*P=0x42;
Delay1335();
P=LcdDataW;
for(i=0;i<(320*30);i++)
{
P=LcdDataW;
*P=(*Bmp++);
Delay1335();
}
}
void ShowNovel(void)
{
unsigned char *Text;
Text = DemoChar;
TextWindowOut(0,0,319,239,Text);
}
void ShowText(void)
{
unsigned short x,y;
x=1;
y=80;
WriteChineseChar(x+0,y,0xbb,0xb6);//欢
WriteChineseChar(x+2,y,0xd3,0xad);//迎
WriteChineseChar(x+4,y,0xb9,0xe2);//光
WriteChineseChar(x+6,y,0xc1,0xd9);//临
WriteChineseChar(x+8,y,0xd1,0xd0);//研
WriteChineseChar(x+10,y,0xbe,0xbf);//究
WriteChineseChar(x+12,y,0xc9,0xfa);//生
WriteChineseChar(x+14,y,0xb5,0xe7);//电
WriteChineseChar(x+16,y,0xc6,0xf8);//气
WriteChineseChar(x+18,y,0xbc,0xbc);//技
WriteChineseChar(x+20,y,0xca,0xf5);//术
WriteChineseChar(x+22,y,0xb4,0xb4);//创
WriteChineseChar(x+24,y,0xd0,0xc2);//新
WriteChineseChar(x+26,y,0xca,0xb5);//实
WriteChineseChar(x+28,y,0xd1,0xe9);//验
WriteChineseChar(x+30,y,0xca,0xd2);//室
WriteChineseChar(x+32,y,0xa3,0xa1);//!
WriteChineseChar(x+34,y,0xa3,0xc0);//@
WriteChineseChar(x+35,y,0xa3,0xdf);//_
WriteChineseChar(x+36,y,0xa3,0xc0);//@
}
void WriteChineseChar(unsigned short x, unsigned short y , unsigned char CharIndexH, unsigned char CharIndexL)
{
unsigned short DestAdd;
unsigned char *CharPtr,tl,th;
int i;
unsigned short ByteX;
CharPtr=(unsigned char *)((unsigned int)GBK1212+(unsigned int)(24*GetOffetGBK(CharIndexH,CharIndexL)));
for(i=0;i<FontsW;i++)
{
DestAdd=x+y*(WidthX/8);
DestAdd+=(SED1335LAY1_l);
DestAdd+=((SED1335LAY1_h)<<8);
P=LcdComW;
*P=0x46;
Delay1335();
P=LcdDataW;
tl=0xff&(DestAdd);
*P=tl;
Delay1335();
th=((0xff00&(DestAdd))>>8);
*P=th;
Delay1335();
P=LcdComW;
*P=0x42;
Delay1335();
P=LcdDataW;
*P=*CharPtr;
Delay1335();
CharPtr++;
*P=*CharPtr;
Delay1335();
CharPtr++;
y++;
}
}
void WriteChinese(unsigned short x, unsigned short y , unsigned char CharIndexH, unsigned char CharIndexL)
{
unsigned char *CharPtr;
unsigned char TempChar;
unsigned char Mask;
int i,j;
CharPtr=(unsigned char *)((unsigned int)GBK1212+(unsigned int)(24*GetOffetGBK(CharIndexH,CharIndexL)));
for(i=0;i<FontsW;i++)
{
Mask=0x80;
TempChar=*CharPtr;
CharPtr++;
for(j=0;j<8;j++)
{
Dot1335(x+j,y+i,0x0,0x0,(Mask&TempChar));
Mask>>=1;
}
Mask=0x80;
TempChar=*CharPtr;
CharPtr++;
for(j=0;j<(FontsW-8);j++)
{
Dot1335(x+j+8,y+i,0x0,0x0,(Mask&TempChar));
Mask>>=1;
}
}
}
void WriteAsci(unsigned short x, unsigned short y , unsigned char CharIndex)
{
unsigned char *CharPtr;
unsigned char TempChar;
unsigned char Mask;
int i,j;
CharPtr=(unsigned char *)((unsigned int)Asci+(unsigned int)(24*(CharIndex)));
for(i=0;i<FontsW;i++)
{
Mask=0x80;
TempChar=*CharPtr;
CharPtr+=2;
for(j=0;j<6;j++)
{
Dot1335(x+j,y+i,0x0,0x0,(Mask&TempChar));
Mask>>=1;
}
}
}
//o--------->x 0-319
//|
//|
//|
//y 0-239
void Dot1335(unsigned short x, unsigned short y, unsigned char Mode, unsigned char Layer, unsigned char DotValue)
{
unsigned short ByteX,ByteY;
unsigned char OldByte;
unsigned char MaskByte;
int i;
int WhichBit;
ByteX=x/8;
WhichBit=x%8;
MaskByte=(0x80>>WhichBit);
i=ByteX+(y*(WidthX/8));
if(0x00==Layer)
{
i+=(SED1335LAY1_l);
i+=((SED1335LAY1_h)<<8);
}
else if(0x01==Layer)
{
i+=(SED1335LAY2_l);
i+=((SED1335LAY2_h)<<8);
}
else
{
i+=(SED1335LAY3_l);
i+=((SED1335LAY3_h)<<8);
}
P=LcdComW;
*P=0x46;
Delay1335();
P=LcdDataW;
*P=(i&0xff);
Delay1335();
*P=((0xff00&i)>>8);
Delay1335();
P=LcdComW;
*P=0x43; //sed1335将光标地址所确定的单元内的数据送至数据输出缓冲器内供CPU读取。同时光标地址根据光标移动方向参数自动修改。读功能将在下一条指令代码输入时中止
Delay1335();
P=LcdDataR;
OldByte=(unsigned char)*P;
if(0x00!=Mode)
DotValue=~(DotValue);
if(0x00==DotValue)
OldByte&=(~(MaskByte));
else
OldByte|=(MaskByte);
P=LcdComW;
*P=0x46;
Delay1335();
P=LcdDataW;
*P=(i&0xff);
Delay1335();
*P=((0xff00&i)>>8);
Delay1335();
P=LcdComW;
*P=0x42;
Delay1335();
P=LcdDataW;
*P=OldByte;
}
//to display text in a window
//GBK standard
//ascii char:
//tab : 0x09
//return : 0x0d
unsigned char *TextWindowOut(unsigned short LeftTopX,unsigned short LeftTopY, unsigned short BottomRightX,unsigned short BottomRightY, unsigned char *RawText)
{
unsigned char Next0,Next1;
unsigned short x,y;
x=LeftTopX;
y=LeftTopY;
while(0x00!=(*RawText))
{
Next0=*RawText;
if(0x0d==Next0)
{
RawText++;
}
else if(0x09==Next0)
{
x+=FontsW;
RawText++;
if((x+FontsW)>=BottomRightX) //we should start a new line
{
y+=FontsW;
x=LeftTopX;
}
if((y+FontsW)>=BottomRightY) //this window full
return RawText;
}
else if(0x0a==Next0)
{
//if(0x20==(*(RawText+1)))
{
y+=FontsW;
x=LeftTopX;
}
RawText++;
if((x+FontsW)>=BottomRightX) //we should start a new line
{
y+=FontsW;
x=LeftTopX;
}
if((y+FontsW)>=BottomRightY) //this window full
return RawText;
}
else if(Next0>=0x81)
{
Next0=*RawText;
Next1=*(RawText+1);
WriteChinese(x,y,Next0,Next1);
RawText+=2;
x+=FontsW;
if((x+FontsW)>=BottomRightX) //we should start a new line
{
y+=FontsW;
x=LeftTopX;
}
if((y+FontsW)>=BottomRightY)
return RawText;
}
else if(Next0==0x00)
{
return 0x00;
}
else
{
Next0=*RawText;
WriteAsci(x,y,Next0);
RawText+=1;
x+=FontsW/2;
if((x+(FontsW/2))>=BottomRightX) //we should start a new line
{
y+=FontsW;
x=LeftTopX;
}
if((y+FontsW)>=BottomRightY)
return RawText;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -