?? ssd1289.c
字號:
/* uchar spi_send(uchar out_data)
{
SPDR=out_data; //spi輸出
while((SPSR&0x80)==0);
SPSR=0;
return SPDR;
} */
uchar spi_send(uchar out_data)
{
uchar i,n;
for(i=0;i<8;i++)
{
n<<=1;
SCK=0;
MOSI=(out_data&0x80);
if(MISO) n++;
SCK=1;
out_data<<=1;
}
return n;
}
//=================================
void send_command(uchar out_data)
{
RS=0;
CS=0;
spi_send(out_data);
CS=1;
}
//=================================
void send_data(uint out_data)
{
RS=1;
CS=0;
spi_send(out_data>>8);
CS=1;
CS=0;
spi_send(out_data);
CS=1;
}
//=================================
void write_com(uchar address,uint num)
{
send_command(address);
send_data(num);
}
//=================================
void ssd1289_init(void)
{
write_com(0x0000,0x0001); DelayNS(1000); //打開晶振
write_com(0x0003,0xA8A4); DelayNS(1000); //0xA8A4
write_com(0x000C,0x0000); DelayNS(1000);
write_com(0x000D,0x080C); DelayNS(1000);
write_com(0x000E,0x2B00); DelayNS(1000);
write_com(0x001E,0x00B0); DelayNS(1000);
write_com(0x0001,0x2B3F); DelayNS(1000); //驅動輸出控制320*240 0x6B3F
write_com(0x0002,0x0600); DelayNS(1000);
write_com(0x0010,0x0000); DelayNS(1000);
write_com(0x0011,0x6070); DelayNS(1000); //0x4030 //定義數據格式 16位色 橫屏 0x6058
write_com(0x0005,0x0000); DelayNS(1000);
write_com(0x0006,0x0000); DelayNS(1000);
write_com(0x0016,0xEF1C); DelayNS(1000);
write_com(0x0017,0x0003); DelayNS(1000);
write_com(0x0007,0x0233); DelayNS(1000); //0x0233
write_com(0x000B,0x0000); DelayNS(1000);
write_com(0x000F,0x0000); DelayNS(1000); //掃描開始地址
write_com(0x0041,0x0000); DelayNS(1000);
write_com(0x0042,0x0000); DelayNS(1000);
write_com(0x0048,0x0000); DelayNS(1000);
write_com(0x0049,0x013F); DelayNS(1000);
write_com(0x004A,0x0000); DelayNS(1000);
write_com(0x004B,0x0000); DelayNS(1000);
write_com(0x0044,0xEF00); DelayNS(1000);
write_com(0x0045,0x0000); DelayNS(1000);
write_com(0x0046,0x013F); DelayNS(1000);
write_com(0x0030,0x0707); DelayNS(1000);
write_com(0x0031,0x0204); DelayNS(1000);
write_com(0x0032,0x0204); DelayNS(1000);
write_com(0x0033,0x0502); DelayNS(1000);
write_com(0x0034,0x0507); DelayNS(1000);
write_com(0x0035,0x0204); DelayNS(1000);
write_com(0x0036,0x0204); DelayNS(1000);
write_com(0x0037,0x0502); DelayNS(1000);
write_com(0x003A,0x0302); DelayNS(1000);
write_com(0x003B,0x0302); DelayNS(1000);
write_com(0x0023,0x0000); DelayNS(1000);
write_com(0x0024,0x0000); DelayNS(1000);
write_com(0x0025,0x8000); DelayNS(1000);
write_com(0x004f,0); //行首址0
write_com(0x004e,0); //列首址0
}
/**************************************************************************************
* 名 稱: DispOneColor
* 功 能: 全屏顯示某種顏色
* 參 數: Color : 顏色值
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void DispOneColor(uint Color)
{
int i,j;
write_com(0x004f,0); //行首址0
write_com(0x004e,0); //列首址0
send_command(0x22);
for(j=0;j<320;j++)
for(i=0;i<240;i++)
send_data(Color);
}
/**************************************************************************************
* 名 稱: DispClear
* 功 能: 清除顯示屏的顯示內容
* 參 數: 無
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2006.8.13 lcf 基本的功能完成
**************************************************************************************/
void DispClear(void)
{
DispOneColor(BLACK);
}
//==============================================
void Set_ramaddr(uint x,uint y)
{
write_com(0x004f,y); //行首址
write_com(0x004e,x); //列首址
}/**************************************************************************************
* 名 稱: DrawSingleAscii
* 功 能: 在指定的位置單個字符
* 參 數: x : x坐標
* y : y坐標
* LineColor : 字符的顏色
* FillColor : 字符背景顏色
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void DrawSingleAscii(uint x, uint y, uchar *pAscii, uint LineColor,uint FillColor, uchar Mod)
{
uchar i, j;
uchar str;
uint OffSet;
OffSet = (*pAscii - 32)*16;
for (i=0;i<16;i++)
{
Set_ramaddr(x,y+i);
send_command(0x22);
str = *(AsciiLib + OffSet + i);
for (j=0;j<8;j++)
{
if ( str & (0x80>>j) ) //0x80>>j
{
send_data((uint)(LineColor&0xffff));
}
else
{
if (NORMAL == Mod)
send_data((uint)(FillColor&0xffff));
else
{
Set_ramaddr(x+j+1,y+i);
send_command(0x22);
}
}
}
}
}
/**************************************************************************************
* 名 稱: DrawSingleHz
* 功 能: 在指定的位置顯示漢字
* 參 數: x : x坐標
* y : y坐標
* LineColor : 漢字的顏色
* FillColor : 漢字背景顏色
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
{
uint j=0,i=0,k=0;
uint str,len;
//---------------------------統計是否在字庫中出現
len=sizeof(HzLib)/sizeof(HzLib[0]);
for(j=0;j<sizeof(HzLib)/sizeof(HzLib[0]);j++)
if((uchar)HzLib[j].Index[0]==pHz[0]&&(uchar)HzLib[j].Index[1]==pHz[1])break;
//--------------------------
if(j<len)
{
for (i=0;i<HZ_column;i++)
{
Set_ramaddr(x,y+i);
send_command(0x22);
str = (uchar)HzLib[j].Msk[i*2]<<8|(uchar)HzLib[j].Msk[i*2+1];
for (k=0;k<HZ_column;k++)
{
if ( str & (0x8000>>k) ) //0x8000>>k
{
send_data((uint)(LineColor&0xffff));
}
else
{
if (NORMAL == Mod)
send_data((uint)(FillColor&0xffff));
else
{
Set_ramaddr(x+k+1,y+i);
send_command(0x22);
}
}
}
}
}
}
/**************************************************************************************
* 名 稱: DrawString
* 功 能: 在指定的位置顯示多個字符
* 參 數: x : x坐標
* y : y坐標
* LineColor : 字符的顏色
* FillColor : 字符背景顏色
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void DrawString(uint x, uint y, uchar *pStr, uint LineColor,uint FillColor, uchar Mod)
{
while(1)
{
if (*pStr == 0)
{
return;
}
if (*pStr > 0x80) //漢字
{
DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod);
x += HZ_column;
pStr += 2;
}
else //英文字符
{
DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);
x += 8;
pStr += 1;
}
}
}
//=================================
void DispNum(unsigned int x, unsigned int y, unsigned short num)
{
unsigned char str[5];
str[0] = num/1000+0x30;
str[1] = (num%1000)/100+0x30;
str[2] = (num%1000)%100/10+0x30;
str[3] = (num%1000)%100%10+0x30;
str[4] = '\0';
DrawString(x, y, str, RED, YELLOW, NORMAL);
}
/**************************************************************************************
* 名 稱: DispSmallPic
* 功 能: 在指定的位置顯示一張65K色的圖片
* 參 數: str : 圖片數組名
* 返 回 值: 無
*
* 修改歷史:
* 版本 日期 作者 改動內容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void DispSmallPic(uint x, uint y, uint w, uint h, const uchar *str)
{
uint i,j,temp;
for(j=0;j<h;j++)
{
Set_ramaddr(x,y+j);
send_command(0x22);
for(i=0;i<w;i++)
{ //send_data(*(unsigned short *)(&str[(j*w+i)*2])); //高位在前
temp=str[(j*w+i)*2+1]<<8; //低位在前
temp|=str[(j*w+i)*2];
send_data(temp);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -