// 12864I (串口)
//***************************************************************************
//连线表: CPU=89C52 *
//CS=P3.1 SID=P3.1 SCK=P3.2 RS=P3.3 Fosc=12Mhz *
//***************************************************************************
#include <reg51.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
sbit CS =P1^0; //片选
sbit SID=P1^1; //数据
sbit SCK=P1^2; //Clock信号
sbit RS =P1^3; //数据指令选择
sbit RST=P1^4;
//sbit Key=P1^5; //锁定按键
#define uchar unsigned char
#define uint unsigned int
uchar code bmp1[];
uchar code bmp2[];
uchar code bmp3[];
uchar code ASCIIchardot[];
uchar code Table[]={3,2,1,0,7,6,5,4,};
void WRI( uchar iidata )
{
uchar i;
CS=0;
RS=0;
for(i=0;i<8;i++)
{ SCK=1;
SID=( (iidata>>(7-i)) &0x01);
SCK=0;
_nop_();
SCK=1;
}
}
void WRD(uchar iddata)
{
uchar i;
CS=0;
RS=1;
for(i=0;i<8;i++)
{
SCK=1;
SID=( (iddata>>(7-i)) &0x01);
SCK=0;
_nop_();
SCK=1;
}
}
void Delay(uint MS)
{
uchar us,usn;
while(MS!=0)
{ usn = 4;
while(usn!=0)
{
us=0xf0;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
void LCR( void )
{
uint i,j;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address as ComTable
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( 0 );
}
}
}
void LcmInit( void )
{
WRI(0xAE); //Display OFF
WRI(0xA2); //1/64 Duty 1/9 Bias
WRI(0xA0); //ADC select --> right
WRI(0xC0); //com1 --> com64
WRI(0x27); //V0 regulator Rb/Ra=111B
WRI(0x81); //Sets V0
WRI(0x30); //对比度调节
WRI(0x2F); //voltage follower ON regulator ON booster ON
WRI(0xA6); //Normal Display (not reverse dispplay)
WRI(0xA4); //Entire Display Disable
LCR();
WRI(0xAF); //Display ON
WRI(0x40); //Set Display Start Line = com0
WRI(0xB0); //Set Page Address = 0
WRI(0x10); //Set Column Address 4 higher bits = 0
WRI(0x01); //Set Column Address 4 lower bits = 1 , from IC SEG1 -> SEG129
}
void LDspBmp( uchar *puts )
{
uchar i,j;
uint bb=0;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( puts[bb] );
bb++;
}
}
}
//显示ASICC字符的函数
void pchar(uchar col,uchar page,uchar Order)
//这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
{
uchar i;
uint ac;
ac = (Order-0x20)*0x10; //ASICC字符从0x20开始,每个16 byte
WRI(Table[page&0x07]|0xB0); //Set Page Address
WRI( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WRI( (col+1)&0x0F ); //Low Byte Colum from 1 -> 129 auto add
for(i=0;i<8;i++)
{
WRD( ASCIIchardot[ac] );
ac++;
}
page++; //下半字符page+1
WRI(Table[page&0x07]|0xB0); //Set Page Address
WRI( ((col+1)>>4) | 0x10); //Set Column Address High Byte
WRI( (col+1)&0x0F ); //Low Byte Colum from 1 -> 129 auto add
for(i=0;i<8;i++)
{
WRD( ASCIIchardot[ac] );
ac++;
}
page--; //写完一个字符page还原
}
//显示字符串的函数
/*
为了避免需要LcmPutChar返回page col值,
只能将判断col和paeg的程序放到PutStr中
调用函数的时候需要注意
*/
void pstr(uchar col,uchar page,uchar *puts)
{
while(*puts != '\0') //判断字符串时候显示完毕
{
if(col>120) //判断行末空间是否足够放一个字符,自动换行
{
page=page+2;
col=0;
}
if(page>6) //到了屏幕最下角,自动返回左上角
{
page=0;
col=0;
}
pchar(col,page,*puts);
puts++;
Delay(10); //延时演示效果
col=col+8; //下一个字符8列之后
}
}
void LcmDisplayDots( void )
{
uchar i,j,X=0x55;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( X );
X=~X;
}
}
}
void LcmDisplayDotsUp( void )
{
uchar i,j,X=0x55;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<4;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( X );
X=~X;
}
}
for(i=4;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( 0xff );
}
}
}
void LcmDisplayDotsDown( void )
{
uchar i,j,X=0x55;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<4;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( 0xff );
}
}
for(i=4;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
{
WRD( X );
X=~X;
}
}
}
void LcmDisplayBlack( )
{
uchar i,j;
WRI(0x40); //Set Display Start Line = com0
for(i=0;i<8;i++)
{
WRI(0xB0|Table[i]); //Set Page Address
WRI(0x10); //Set Column Address = 0
WRI(0x01); //Colum from 1 -> 129 auto add
for(j=0;j<128;j++)
WRD( 0xff );
}
}
/*
void DelayKey(uchar HalfSecond)
{ //Delay_key加入时间参数
uint i;
for(i=0;i<26*HalfSecond;i++)
{
if(Key==0)
{
Delay(20);
while(Key==0) {Delay(20);}
break;
}
else Delay(10);
}
}
*/
void main( void )
{
Delay(50);
RST=0;
Delay(250);
RST=1;
Delay(10);
LcmInit();
while(1)
{
LDspBmp(bmp1);
//DelayKey(2);
LDspBmp(bmp2);
//DelayKey(2);
LDspBmp(bmp3);
//DelayKey(2);
LCR();
pstr(0,0,"abcdefghijklmnopqrstuvwxyz123456ABCDEFGHIJKLMNOPQRSTUVWXYZ123456");
//DelayKey(2);
LcmDisplayBlack();
//DelayKey(2);
}
}
/* ASICC字库代码 8x16点阵 */
uchar code ASCIIchardot[16*96] = {
/* */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*! */
0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0x0C,0x00,0x00,0x00,
/*" */
0x00,0x08,0x30,0x60,0x08,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*# */
0x02,0x03,0x1E,0x02,0x03,0x1E,0x02,0x00,0x20,0xFC,0x20,0x20,0xFC,0x20,0x20,0x00,
/*$ */
0x00,0x0E,0x11,0x3F,0x10,0x0C,0x00,0x00,0x00,0x18,0x04,0xFF,0x84,0x78,0x00,0x00,
/*% */
0x0F,0x10,0x0F,0x00,0x07,0x18,0x00,0x00,0x00,0x84,0x38,0xC0,0x78,0x84,0x78,0x00,
/*& */
0x00,0x0F,0x10,0x11,0x0E,0x00,0x00,0x00,0x78,0x84,0xC4,0x24,0x98,0xE4,0x84,0x08,
/*' */
0x08,0x68,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*( */
0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
/*) */
0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
/** */
0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
/*+ */
0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xF8,0x80,0x80,0x80,0x00,
/*, */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0D,0x0E,0x00,0x00,0x00,0x00,0x00,
/*- */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
/*. */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00,0x00,
/*/ */
0x00,0x00,0x00,0x00,0x01,0x06,0x18,0x20,0x00,0x06,0x18,0x60,0x80,0x00,0x00,0x00,
/*0 */
0x00,0x07,0x08,0x10,0x10,0x08,0x07,0x00,0x00,0xF0,0x08,0x04,0x04,0x08,0xF0,0x00,
/*1 */
0x00,0x08,0x08,0x1F,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC,0x04,0x04,0x00,0x00,
/*2 */
0x00,0x0E,0x10,0x10,0x10,0x11,0x0E,0x00,0x00,0x0C,0x14,0x24,0x44,0x84,0x0C,0x00,
/*3 */
0x00,0x0C,0x10,0x11,0x11,0x12,0x0C,0x00,0x00,0x18,