本帖最后由 sunny鱼儿 于 2016-4-8 11:44 编辑
#include<C8051F020.h>
#include <stdio.h>
#include<INTRINS.h>
#define CsbOn P5|=0X1;
#define CsbOff P5&=~0X1;
#define CsaOn P5|=0X2;
#define CsaOff P5&=~0X2;
#define DiOn P5|=0X4;
#define DiOff P5&=~0X4;
#define RWOn P5|=0X8;
#define RWOff P5&=~0X8;
#define EOn P5|=0X10;
#define EOff P5&=~0X10;
/********************引脚定义********************/
/*sbit DI =P2^5; //数据指令
sbit RW =P2^4; //读写
sbit E =P3^7; //使能
sbit CSA =P2^7; //片选信号A
sbit CSB =P2^6;*/ //片选信号B
unsigned char page; //页 地址
unsigned char col; //列 地址
void wtcom(void);
/*unsigned char code BMP1[];
unsigned char code BMP2[];*/
unsigned char code puts[];
//unsigned char code bmp[2000];
/*unsigned char code puts2[];
unsigned char code puts3[];
unsigned char code puts4[];
unsigned char code puts5[];
unsigned char code puts6[];
unsigned char code puts7[];
unsigned char code puts8[];*/
void Delay (unsigned int MS);
/*void nop(void)
{
int i;
//for (i=0;i<1;i++);
//i=1;
} */
/***************************/
/*检查Busy */
/***************************/
void BusyL(void)
{ CsaOff;
//CSA=0;
CsbOff;
//CSB=0;
wtcom();
}
void BusyM(void)
{
// CSA=0;
CsaOff;
//CSB=1;
CsbOn;
wtcom();
}
void BusyR(void)
{
//CSA=1;
CsaOn;
//CSB=0;
CsbOff
wtcom();
}
void wtcom(void)
{
//DI = 0; //指令
//RW = 1; //读指令
DiOff;
RWOn;
P6 = 0xFF; //输出0xff以便读取正确
EOn;
//E = 1;
_nop_();
while(P6 & 0x80); //Status Read Bit7 = BUSY;如果忙,死循环,等待
EOff;
//E = 0;
_nop_();
}
void Locatexy(void) //坐标定位
{
unsigned char x,y;
switch (col &0xc0)
{
case 0x00:{BusyL();break;}
case 0x40:{BusyM();break;}
case 0x80:{BusyR();break;}
}
x =col &0x3f | 0x40;
y=page &0x07 | 0xB8;
wtcom();
//DI =0;
//RW =0;
DiOff;
RWOff;
P6=y;
//E =1;
EOn;
_nop_();
//E=0;
EOff;
_nop_();
wtcom();
//DI =0;
//RW =0;
DiOff;
RWOff;
P6 =x;
//E =1;
EOn;
_nop_();
//E=0;
EOff;
_nop_();
}
void WriteCommandL( unsigned char CommandByte)
{
BusyL();
P6 = CommandByte;
//DI =0;
//RW =0;
//E =1;
DiOff;
RWOff;
EOn;
_nop_();
//E=0;
EOff;
_nop_();
}
void WriteCommandM( unsigned char CommandByte)
{
BusyM();
P6 = CommandByte;
//DI =0;
//RW =0;
//E =1;
DiOff;
RWOff;
EOn;
_nop_();
//E=0;
EOff;
_nop_();
}
void WriteCommandR( unsigned char CommandByte)
{
BusyR();
P6 = CommandByte;
//DI =0;
//RW =0;
//E =1;
DiOff;
RWOff;
EOn;
_nop_();
//E=0;
EOff;
_nop_();
}
unsigned char ReadData(void)
{
unsigned char DataByte;
Locatexy();
//DI =1;
//RW =1;
DiOn;
RWOn;
P6 =0xFF;
//E =1;
EOn;
_nop_();
DataByte =P6;
//E =0;
EOff;
_nop_();
return DataByte;
}
void WriteData (unsigned char DataByte)
{
Locatexy();
//DI =1;
//RW =0;
DiOn;
RWOff;
P6=DataByte;
//E =1;
EOn;
_nop_();
//E =0;
EOff;
_nop_();
}
void LcmClear(void)
{
page =0;
col =0;
for (page=0;page<8;page++)
for (col =0;col<192;col++)
WriteData(0);
}
void LcmInit(void)
{
WriteCommandL(0x3f);
WriteCommandM(0xc0);
WriteCommandR(0x3f);
WriteCommandL(0xc0);
WriteCommandM(0xc0);
WriteCommandR(0xc0);
WriteCommandL(0x3f);
WriteCommandM(0x3f);
WriteCommandR(0x3f);
LcmClear();
col =0;
page =0;
Locatexy();
}
void LcmPutThreehz ( unsigned char *puts)
{
unsigned int x=0;
page =0;
col =0;
for (page=0;page<8;page++)
{
for (col=0;col<64;col++)
{
WriteData(puts[x]);
x++;
}
}
page =0;
col =64;
for (page=0;page<8;page++)
{
for (col=64;col<128;col++)
{
WriteData(puts[x]);
x++;
}
}
page =0;
col =128;
for (page=0;page<8;page++)
{
for (col=128;col<192;col++)
{
WriteData(puts[x]);
x++;
}
}
}
void Delay(unsigned int MS)
{
unsigned char us,usn;
while (usn!=0)
{
usn =2;
while (usn!=0)
{
us =0xf6;
while(us!=0) {us--;};
usn--;
}
MS--;
}
}
void main (void)
{
WDTCN = 0xDE;
WDTCN = 0xAD;
XBR2 = 0x40;
// unsigned int i;
Delay(1);
LcmInit();
while(1)
{
LcmPutThreehz( puts );
Delay(30);
}
}
/*-- 文字: 小 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
/*unsigned char code puts[]={
0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,
0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,
0x00,0x08,0x28,0x49,0x8A,0x0C,0xC8,0x38,0x08,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,
0x40,0x20,0x10,0x08,0x04,0x03,0x06,0x38,0x10,0x00,0x07,0x20,0x40,0x3F,0x00,0x00,
0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x08,0x1F,0x40,0x80,0x7F,0x00,0x00,
0x00,0x08,0x48,0x48,0x48,0x48,0x48,0x7F,0x48,0x48,0x48,0x48,0x48,0x48,0x08,0x00,
0x20,0x1C,0x00,0x00,0x3E,0x40,0x40,0x41,0x4E,0x44,0x40,0x70,0x22,0x1C,0x08,0x00,
0x00,0x40,0x40,0x48,0x48,0xC8,0x09,0xFA,0x46,0x80,0x40,0x20,0x30,0x00,0x00,0x00,
0x20,0x20,0x10,0x0C,0x03,0x40,0x80,0x7F,0x00,0x00,0x03,0x04,0x08,0x10,0x10,0x00,
0x80,0x90,0x94,0x94,0xF4,0x94,0x94,0xFE,0x92,0x92,0xF2,0x93,0x92,0x90,0x90,0x00,
0x00,0x04,0x44,0x44,0x47,0x44,0x44,0x7F,0x44,0x44,0x47,0x44,0x44,0x44,0x00,0x00,
0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xFE,0x06,0x42,0xC2,0x82,0x02,0x03,0x02,0x00,
0x00,0x08,0x04,0x02,0x01,0x00,0x00,0x7F,0x00,0x00,0x00,0x01,0x07,0x02,0x00,0x00,
0x08,0x08,0xC8,0xFF,0x48,0x88,0x0A,0x02,0x42,0x7E,0x42,0x42,0x42,0xC2,0x02,0x00,
0x04,0x03,0x00,0x7F,0x00,0x01,0x00,0x00,0x00,0x00,0x20,0x40,0x20,0x1F,0x00,0x00,}; */
/*-- 文字: 人 --*/
/*-- 宋体48; 此字体下对应的点阵为:宽x高=64x64 --*/
unsigned char code puts[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xF0,0xF0,0xE0,
0xE0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFD,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0x1F,
0x3F,0xFF,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,
0x00,0x07,0x7F,0xFF,0xF8,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0xFE,0xFF,0xFF,0x7F,0x0F,0x01,0x00,0x00,
0x00,0x00,0x00,0x07,0x1F,0xFF,0xFF,0xF8,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0xC0,0xE0,0xF8,0xFE,0x7F,0x1F,0x0F,0x03,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x7F,0xFF,0xFC,0xF8,0xE0,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xE0,0x70,0x78,0x3C,
0x1E,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0F,0x1F,0x3F,
0x7F,0xFE,0xFE,0xFC,0xF8,0xF0,0xF0,0xE0,0xE0,0xE0,0xC0,0xC0,0xC0,0x80,0x00,0x00,
0x00,0x00,0x00,0x18,0x1C,0x0C,0x0E,0x07,0x07,0x03,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0x07,0x07,0x0F,0x03,0x03,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x38,0x78,0xF0,0xF0,0xE0,0xE0,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x1F,0x7F,0x7F,0x7F,
0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x86,0xC6,0xE6,0xFE,0xFE,0xFF,0x7F,0x3F,0x3F,0x1F,0x0F,
0x0E,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,
0xE0,0xF0,0xF8,0x7C,0x3E,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1F,0x0F,0x07,
0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,
0xE0,0xF0,0xF8,0x7C,0x3E,0x1E,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x30,0x78,0xF8,0xFC,0xFC,0x7E,0x3E,0x1F,0x0F,0x07,0x07,0x03,0x03,
0x03,0x07,0x0E,0x1C,0x3C,0x78,0xF0,0xF0,0xF0,0xE0,0xE0,0xE0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0xE0,0xE0,0x60,0x60,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x03,0x03,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1C,0x38,0xF8,
0xF0,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x81,
0x8F,0x9F,0x9F,0x9F,0x87,0xC0,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x30,0x30,0x30,
0x30,0x30,0x30,0x30,0x30,0xF0,0xF0,0xF0,0xF0,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
0x30,0x30,0x30,0x30,0x30,0x30,0xF0,0xF8,0xFC,0xFC,0xF8,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x81,0xC1,0xF1,0xFD,0xFF,0x7F,0x1F,0x0F,0x03,0x03,0x01,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xFC,0xFE,
0xFF,0xFF,0xFF,0x01,0x00,0x00,0x80,0xE0,0xF0,0x7C,0x3F,0x1F,0x1F,0x0E,0x0C,0x00,
0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x0F,0x07,0x03,0x01,0x00,0xFF,
0xFF,0xFF,0xFF,0x06,0x0E,0x0F,0x1F,0x3D,0x7C,0xF8,0xF8,0xF0,0xE0,0x00,0x00,0x00,
0x00,0x00,0x80,0xFC,0xFF,0xFF,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x03,0x00,0x00,0xC0,
0xF0,0xFC,0xFF,0x3F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0xF8,0x7C,0x3F,0x0F,
0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xF8,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
0x1F,0x1F,0x0F,0x00,0x00,0x08,0x0C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0x0F,
0x1F,0x1F,0x0F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
|