#include "12864.h"
#include "ascii.h"
u8 ComTable[]={3,2,1,0,7,6,5,4};
u8 ComTable1[]={7,6,5,4,3,2,1,0};
/*******************
延迟函数
*******************/
void JLXdelay1(u16 i)
{
int j,k;
for(j=0;j0;i--);
}
/*******************
//清屏
*******************/
void LcmClear( Uchar FillData )
{
Uint i,j;
for(i=0;i<8;i++)
{
WriteCommand(0xB0|ComTable[i]); //Set Page Address
WriteCommand(0x10); //Set Column Address = 0
WriteCommand(0x01); //Colum from S1 -> S128 auto add
for(j=0;j<=128;j++)
{
WriteData( FillData );
}
}
}
/*******************
//初始化
*******************/
void LcmInit( void )
{
// WriteCommand(0xe2); //复位
WriteCommand(0xAE); //Display OFF
WriteCommand(0xA2); //1/64 Duty 1/9 Bias
WriteCommand(0xA0); //ADC select S0->S131(玻璃设计用 S1-S128)
WriteCommand(0xC0); //com1 --> com64
WriteCommand(0x24); //对某些模块没用,用的外部 Rb/Ra
WriteCommand(0x81); //Sets V0
WriteCommand(48); //内部电位器调节对比度
WriteCommand(0x2F); //voltage follower ON regulator ON booster ON
WriteCommand(0xA6); //Normal Display (not reverse dispplay)
WriteCommand(0xA4); //Entire Display Disable
WriteCommand(0x40); //Set Display Start Line = com0
WriteCommand(0xB0); //Set Page Address = 0
WriteCommand(0x10); //Set Column Address 4 higher bits = 0
WriteCommand(0x01); //Set Column Address 4 lower bits = 1 , from IC SEG1 -> SEG128
LcmClear(0);
WriteCommand(0xAF); //Display ON
}
/*******************
//显示字符
*******************/
void LcmPutChar(Uchar col,Uchar page,Uchar Order)
{
Uchar i;
Uint x;
x = (Order-0x20)*0x10; //ASICC 字符从 0x20 开始,每个 16 byte
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 -> S1 auto add
for(i=0;i<8;i++)
{
WriteData( ASCIIchardot[x] ); //数组
x++;
}
page++; //下半字符 page+1
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address HighByte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 ->S1 auto add
for(i=0;i<8;i++)
{
WriteData( ASCIIchardot[x]);
x++;
}
page--; //写完一个字符 page 还原
}
void LcmPutChar8_8(Uchar col,Uchar page,Uchar Order)
{
Uchar i;
Uint x;
x = (Order-0x20)*0x10; //ASICC 字符从 0x20 开始,每个 16 byte
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 -> S1 auto add
for(i=0;i<8;i++)
{
WriteData( ASCIIchardot[x] ); //数组
x++;
}
// page++; //下半字符 page+1
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address HighByte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 ->S1 auto add
for(i=0;i<8;i++)
{
WriteData( ASCIIchardot[x]);
x++;
}
// page--; //写完一个字符 page 还原
}
/*******************
//显示字符串
*******************/
void LcmPutStr(Uchar col,Uchar page,Uchar *puts)
{
while(*puts) //判断字符串时候显示完毕
{
if(col>(LcmXPixel-8)) //判断行末空间是否足够放一个字符,自动换行
{
page=page+2;
col=0;
}
if(page>(LcmYPixel/8-2)) //到了屏幕最下角,自动返回左上角
{
page=0;
col=0;
} LcmPutChar(col,page,*puts);
puts++;
col=col+8; //下一个字符 8 列之后
}
}
/*******************
//显示数字
*******************/
void LcmPutNum(Uchar col,Uchar page,u16 num)
{
if(num%100000/10000==0);
else LcmPutChar(col+8*0,page,num%100000/10000+0x30);
if(num%100000/10000==0&&num%10000/1000==0);
else LcmPutChar(col+8*1,page,num%10000/1000+0x30);
if((num%100000/10000==0)&&(num%10000/1000==0)&&(num%1000/100==0));
else LcmPutChar(col+8*2,page,num%1000/100+0x30);
LcmPutChar(col+8*3,page,num%100/10+0x30);
LcmPutChar(col+8*4,page,num%10/1+0x30);
}
/*******************
16*16的汉字显示
*******************/
void PUTchar16x16(u8 row,u8 col,u8 count,const u8 *put)
{
u16 X=0,j,i;
WriteCommand(0xb0+row);
WriteCommand(0x10+(8*col/16));
WriteCommand(0x00+(8*col%16));
for(j=0;j0;i--) //纵坐标,这里有讲究
//for(i=0;i<7;i++)
{
WriteCommand(0xB0|ComTable1[i]); //Set Page Address
WriteCommand( ((cl+1)>>4) | 0x10); //Set Column Address High Byte
WriteCommand( (cl+1)&0x0F ); //Low Byte Colum from S128 -> S1 auto add
// WriteCommand(0x10); //Set Column Address = 0
// WriteCommand(0x01); //Colum from S1 -> S128 auto add
for(j=0;j<32;j++) //这里就应该是32个格点 横坐标
{
WriteData( puts[X] );
X++;
}
}
}
//显示光标函数
void LcmPutChar_cu(Uchar col,Uchar page,u8 aa)
{
Uchar i;
Uint x;
// x = (Order-0x20)*0x10; //ASICC 字符从 0x20 开始,每个 16 byte
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 -> S1 auto add
for(i=0;i<8;i++)
if(aa==1)
WriteData(0x01);
else WriteData(0x00);
page++;
}
//重画字符带光标
void LcmPutChar_2(Uchar col,Uchar page,Uchar Order,u8 cursor_f)
{
Uchar i;
Uint x;
x = (Order-0x20)*0x10; //ASICC 字符从 0x20 开始,每个 16 byte
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 -> S1 auto add
for(i=0;i<8;i++)
{
WriteData( ASCIIchardot[x] ); //数组
x++;
}
page++; //下半字符 page+1
WriteCommand(ComTable[page&0x07]|0xB0); //Set Page Address
WriteCommand( ((col+1)>>4) | 0x10); //Set Column Address HighByte
WriteCommand( (col+1)&0x0F ); //Low Byte Colum from S128 ->S1 auto add
for(i=0;i<8;i++)
{
if(cursor_f==0)
{
WriteData( ASCIIchardot[x]);
x++;
}
else
{
WriteData( ASCIIchardot[x]|0x01);
x++;
}
}
page--; //写完一个字符 page 还原
}
/*****************12864h***********************/
#ifndef _12864_H
#define _12864_H
#include "main.h"
#define u8 unsigned char
#define u16 unsigned int
#define Uchar u8
#define Uint u16
#define CS _PA0
#define SID _PA4
#define SCK _PA3
#define RS _PA2
#define RES _PA1
#define LcmXPixel 128
#define LcmYPixel 64
void JLXdelay1(u16 i);
void data_send(unsigned char dat);
void WriteCommand(unsigned char x);
void WriteData(unsigned char dat);
void DelayMS(unsigned char MS);
void LcmClear( u8 FillData );
void LcmInit( void );
void LcmPutChar(Uchar col,Uchar page,u8 Order);
void LcmPutStr(Uchar col,Uchar page,Uchar *puts);
void LcmPutNum(Uchar col,Uchar page,u16 num);
void LcmPutBmp(const Uchar *puts,u8 heng);
void PUTchar16x16(u8 row,u8 col,u8 count,const u8 *put);
void zifu16x16xian(void);
void LcmPutChar_cu(Uchar col,Uchar page,u8 aa);
void LcmPutChar_2(Uchar col,Uchar page,Uchar Order,u8 cursor_f);
void LcmPutChar8_8(Uchar col,Uchar page,Uchar Order) ;
#endif