#include"main.h"
#include"12864.h"
#include<intrins.h>
#include<stdlib.h>
#define BASIC_SET 0x30
#define EXTEND_SET 0x34
#define DRAW_ON 0x36
#define DRAW_OFF 0x34
//=======================================================================
// 函數名稱: void delaypic(uint k)
// 函數功能: 延時函數
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
void delaypic(uint k)
{
uint i;
uchar j;
for(i = 0; i < k ;i ++)
for(j = 0; j < 10 ;j ++);
}
//=======================================================================
// 函數名稱: delay(uint16 time)
// 函數功能:延時函數
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
delay(uint16 time)
{
uint16 i,j;
for(i=0;i<time;i++)
for(j=0;j<100;j++);
}
//=======================================================================
// 函數名稱: checkbusy()
// 函數功能:查忙
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
checkbusy()
{
RS=0;
RW=1;
E=1;
while((P0&0x80)==0x80);
E=0;
}
//=======================================================================
// 函數名稱:wcode(uint8 cmdcode)
// 函數功能:寫入命令
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
wcode(uint8 cmdcode)
{
checkbusy();
RS=0;
RW=0;
E=1;
P0 = cmdcode;
delay(10);
E=0;
}
//=======================================================================
// 函數名稱: wdata(uint8 dispdata)
// 函數功能:寫入數據
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
wdata(uint8 dispdata)
{
checkbusy();
RS=1;
RW=0;
E=1;
P0 = dispdata;
delay(10);
E=0;
}
/*******************************************************
* 函 數 名:unsigned char rd_dat( void )
* 功能描述:讀數據
* 函數說明:從12864b讀數據
* 輸入參數:無
* 返 回 值:unsigned char byReturnValue
*******************************************************/
unsigned char rd_dat( void )
{
unsigned char byReturnValue ;
P0 = 0xff ;
checkbusy();
RS=1;
RW=1;
E=0;
E=1;
byReturnValue = P0 ;
E=0;
return byReturnValue ;
}
//=======================================================================
// 函數名稱: InitLCD()
// 函數功能:LCD初始化
// 作者:
// 日期:2017.8.4
// 備注:
//=======================================================================
InitLCD()
{
PSB=1;
RES=0;
delay(10);
RES=1;
wcode(0x30);
wcode(0x0c);
wcode(0x01);
wcode(0x06);
}
//=======================================================================
// 函數名稱: void dis(uint8 x,uint8 y,uint8 code *s)
// 函數功能:坐標位置寫入數據
// 作者:
// 日期:2017.8.4
// 備注:X為橫行,Y為縱行
//=======================================================================
void dis(uint8 x,uint8 y,uint8 *s)
{
switch(y)
{
case 0: wcode(0x80+x);break;
case 1: wcode(0x90+x);break;
case 2: wcode(0x88+x);break;
case 3: wcode(0x98+x);break;
default:break;
}
while(*s>0)
{
wdata(*s);
delay(10);
s++;
}
}
/*******************************************************
* 函 數 名:void DrawPoint( unsigned char X, unsigned char Y, unsigned char Color )
* 功能描述:畫點
* 函數說明:在制定位置畫一個像素的點
* 輸入參數:unsigned char X, unsigned char Y, unsigned char Color
* X為列,Y為行,COLOR為不顯示、顯示或者翻轉(0、1、2)
* 返 回 值:無
*******************************************************/
void DrawPoint( unsigned char X, unsigned char Y, unsigned char Color )
{
unsigned char Row , Tier , Tier_bit ;
unsigned char ReadOldH, ReadOldL ;
Tier = X >> 4 ;
Tier_bit = X & 0x0f ;
if( Y < 32 )
{
Row = Y ;
}
else
{
Row = Y - 32 ;
Tier += 8 ;
}
wcode(Row + 0x80); //寫入行坐標
wcode(Tier + 0x80); //寫入列坐標
rd_dat();
ReadOldH = rd_dat() ; //讀出原始數據
ReadOldL = rd_dat() ;
wcode(Row + 0x80);
wcode(Tier + 0x80);
if( Tier_bit < 8 )
{
switch( Color)
{
case 0 : ReadOldH &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ; //不顯示
case 1 : ReadOldH |= ( 0x01 << ( 7 - Tier_bit )) ; break ; //顯示
case 2 : ReadOldH ^= ( 0x01 << ( 7 - Tier_bit )) ; break ; //翻轉
default : break ;
}
wdata(ReadOldH); //寫入新數據
wdata(ReadOldL);
}
else
{
switch(Color)
{
case 0 : ReadOldL &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;
case 1 : ReadOldL |= ( 0x01 << ( 15 - Tier_bit )) ; break ;
case 2 : ReadOldL ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;
default : break ;
}
wdata(ReadOldH);
wdata(ReadOldL);
}
}
/*------------------------------------------------
設置到繪圖模式
------------------------------------------------*/
void SetGraphicMode()
{
wcode(0x36); //選擇8bit數據流 圖形模式
delaypic(50);
}
/*------------------------------------------------
顯示圖片
------------------------------------------------*/
void LCD_PutGraphic(unsigned char code *img)
{
int i,j;
//顯示上半屏內容設置
for(i=0;i<32;i++)
{
wcode(0x80 + i); //SET 垂直地址 VERTICAL ADD
wcode(0x80); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
wdata(*img);
img++;
}
}
//顯示下半屏內容設置
for(i=0;i<32;i++)
{
wcode(0x80 + i); //SET 垂直地址 VERTICAL ADD
wcode(0x88); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
wdata(*img);
img++;
}
}
}
/*------------------------------------------------
清屏
------------------------------------------------*/
void ClrScreen()
{
wcode(0x01);
delaypic(40);
}
//***************************************************************************以下為GDRAM繪圖部分************************************************************************//
//*********************繪圖顯示的清屏函數(因清屏指令在畫圖時不能用)------------------------------------------------------------------------------注意!!!!!!!
void gui_clear()
{
uchar i , j , k;
wcode(EXTEND_SET);//擴展指令集,8位數據傳輸
wcode(DRAW_OFF); //繪圖顯示關閉
for(i = 0; i < 2; i ++)//分上下兩屏寫
{
for(j = 0; j < 32; j ++)
{
wcode(0x80 + j);//寫y坐標
delaypic(1);
if(i == 0) //寫x坐標
{
wcode(0x80);
delaypic(1);
}
else //寫下半屏
{
wcode(0x88);
delaypic(1);
}
for(k = 0; k < 16; k ++)//寫一整行數據
{
wdata(0x00);//寫高字節
wdata(0x00);//寫低字節
delaypic(1);
}
}
|