独闷闷网
标题:
三片选的19264液晶模块的C语言程序
[打印本页]
作者:
ligang
时间:
2013-12-30 23:39
标题:
三片选的19264液晶模块的C语言程序
// 19264 三片选
//***************************************************************************
//连线表: CPU=89C52
//RS=P3.0 R/W=P3.1 E=P3.2 DB0-DB7=P0.0-P0.7
//CS1=P3.3 CS2=P3.4 CS3=P3.5
//SysClock=12MHz
//***************************************************************************
//转自电子开发者论坛
#include <reg52.h>
#include <intrins.h>
#define LcmXPixel 192 //横像素
#define LcmYPixel 64 //纵像素
void int_zhongduan();
sbit RS =P2^0; //数据指令
sbit RW =P2^1; //读写
sbit E =P2^2; //使能
sbit CS1 =P2^3; //1片选
sbit CS2 =P2^4; //2片选
sbit CS3 =P2^5; //3片选
sbit RES =P2^6;
sbit P33=P3^3;
unsigned char Page;
unsigned char Col;
unsigned char code BMP0[];
void Delay(unsigned int MS);
void wtcom(void);
void Busy(unsigned char CSn)
{
CS1 = 1; //先都置高
CS2 = 1;
CS3 = 1;
switch (CSn&0x0f)
{
case 1: {CS1=0;break;}
case 2: {CS2=0;break;}
case 3: {CS3=0;break;}
default : {break;}
}
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P0 = 0xFF; //输出0xff以便读取正确
E = 1;
_nop_();_nop_();
_nop_();_nop_();
while(P0 & 0x80); //Status Read Bit7 = BUSY
E = 0;
_nop_();_nop_();
_nop_();_nop_();
}
void Locatexy(void)
{
unsigned char x,y;
switch (Col&0xc0) /* col.and.0xC0 */
{ /*条件分支执行 */
case 0: {Busy(1);break;}/*左区 */
case 0x40: {Busy(2);break;}/*中区 */
case 0x80: {Busy(3);break;}/*右区 */
}
x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/
y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */
wtcom(); /* waitting for enable */
RS = 0; //指令
RW = 0; //写
P0 = y; //设置页面地址
E = 1;
_nop_();_nop_();
_nop_();_nop_();
E = 0;
_nop_();_nop_();
_nop_();_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P0 = x; //设置列地址
E = 1;
_nop_();_nop_();
_nop_();_nop_();
E = 0;
_nop_();_nop_();
_nop_();_nop_();
}
//转自电子开发者论坛
void WriteCommand( unsigned char CSn,unsigned char CommandByte )
{
Busy(CSn);
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();_nop_();
_nop_();_nop_();
E = 0;
_nop_();_nop_();
_nop_();_nop_();
}
unsigned char ReadData( void )
{
unsigned char DataByte;
Locatexy();
RS = 1;
RW = 1;
P0 = 0xFF;
E = 1;
DataByte = P0;
E = 0;
return DataByte;
}
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
RS = 1; /*数据输出*/
RW = 0; /*写输出 */
P0 = DataByte; /*数据输出到数据口 */
E = 1; /*写入到LCM*/
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
E = 0;
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
}
void LcmClear( unsigned char FillByte )
{
Page = 0;
Col = 0;
for(Page=0
age<(LcmYPixel/8)
age++)
for(Col=0;Col<LcmXPixel;Col++)
WriteData(FillByte);
}
void LcmInit( void )
{
RES =0;
Delay(10);
RES =1;
Delay(30);
WriteCommand(1,0x3f); //开显示
WriteCommand(2,0x3f);
WriteCommand(3,0x3f);
WriteCommand(1,0xc0); //设置起始地址=0
WriteCommand(2,0xc0);
WriteCommand(3,0xc0);
WriteCommand(1,0x3f); //开显示
WriteCommand(2,0x3f);
WriteCommand(3,0x3f);
Col = 0;
Page= 0;
Locatexy();
}
void LcmPutDots( unsigned char DotByte,unsigned char n )
{
unsigned char i,j;
Page = 0;
Col = 0;
for(Page=0
age<(LcmYPixel/8)
age++)
{
Col=0;
for(j=0;j<(LcmXPixel/n);j++)
{
for(i=0;i<n;i++)
{
WriteData( DotByte );
Col++;
}
DotByte = ~DotByte;
}
if(n>=8) DotByte = ~DotByte;
}
}
void LcmPutBMP( unsigned char *puts )
{
unsigned int X=0;
Page = 0;
Col = 0;
for(Page=0
age<(LcmYPixel/8)
age++)
{
for(Col=0;Col<LcmXPixel;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
void LcmReverseBMP( void )
{
unsigned char temp;
Page = 0;
Col = 0;
for(Page=0
age<(LcmYPixel/8)
age++)
{
for(Col=0;Col<LcmXPixel;Col++)
{
temp = ReadData();
temp = ReadData();
temp = ~temp;
WriteData(temp);
}
}
}
void Delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //for 12M
while(usn!=0)
{
us=0xf6;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
//转自电子开发者论坛
void Main( void )
{
Delay(100); //等待复位
Delay(2);
int_zhongduan();
LcmInit();
LcmClear(0);
while(1)
{
LcmPutBMP(BMP0);
Delay(1500);
LcmReverseBMP();
Delay(1500);
LcmClear(0xff);
Delay(1500);
LcmPutDots(0x55,1);
Delay(1500);
LcmPutDots(0xAA,1);
Delay(1500);
LcmPutDots(0xCC,2);
Delay(1500);
LcmPutDots(0x33,2);
Delay(1500);
LcmPutDots(0xF0,4);
Delay(1500);
LcmPutDots(0x0F,4);
Delay(1500);
}
}
unsigned char code BMP0[]={ //字节颠倒
/*-- 宽度x高度=192x64 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xE0,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x60,0x40,0x00,0x80,0x80,
0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0x60,0x00,0x80,
0x80,0x80,0x80,0x80,0x80,0xE0,0xE0,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xC0,0x40,0x40,0x40,0x40,0x40,0xC0,0xC0,0x40,0x40,0x40,0x40,
0x40,0x40,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,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x31,0x71,0xC1,0x81,0xF9,0x3F,
0x03,0x20,0x7C,0x1F,0x03,0x02,0xE2,0xE2,0x02,0x02,0x1A,0x3E,0x06,0x00,0x00,0x00,
0x00,0x20,0x20,0xE3,0xE3,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x60,0x78,0x1E,0xFF,0xFF,0x00,0x00,0x01,
0xF9,0xF9,0x19,0x19,0x19,0xFF,0xFF,0x19,0x19,0x19,0xF9,0xF9,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0x18,0x18,0x18,0x18,0x18,0xFF,0xFF,0x18,0x18,0x18,0x18,
0x18,0x18,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x0C,0xFE,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0xF8,0xFE,0x07,0x03,0x03,0x03,0x06,0xFE,0xF8,0x00,0x00,0x00,
0x38,0x3E,0x07,0x03,0x03,0x03,0x87,0xFE,0x7C,0x00,0x00,0x00,0xF0,0xFC,0xCE,0x63,
0x63,0x63,0xE7,0xCE,0x8C,0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0x3C,0x1E,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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,0x78,0x1F,0x07,0x0F,0x1C,
0x38,0x80,0xC0,0xE0,0x70,0x1F,0x07,0x1F,0x38,0x60,0xC0,0x80,0x80,0x00,0x00,0x00,
0x00,0x00,0x80,0xFF,0x7F,0xC0,0x80,0x88,0x9F,0x0C,0x0C,0x06,0x00,0x00,0x7F,0x00,
0x00,0x0C,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,
0x09,0x1D,0xB9,0xE1,0xE1,0xFF,0xC7,0x81,0x81,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0xE0,0xFF,0x0F,0x02,0x02,0x02,0x02,0x02,0xFF,0xFF,0x02,0x02,0x02,0x02,
0x02,0x02,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x31,0x73,0xE7,0xC6,0xC6,0xC6,0x73,0x3F,0x0F,0x00,0x00,0x00,
0xE0,0xF0,0xD8,0xCC,0xC6,0xC3,0xC1,0xC0,0xC0,0x00,0x00,0x00,0x0F,0x3F,0x60,0xC0,
0xC0,0xC0,0xE0,0x7F,0x1F,0x00,0x00,0x00,0x0E,0x0F,0x0F,0x0C,0x0C,0x0C,0xFF,0xFF,
0x0C,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x01,0x00,0x00,
0x00,0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x02,
0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x00,0x00,0x00,
0x00,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x01,
0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
void Interrupt1 (void) interrupt 2 //按键启动和暂停
{
P33=1;
Delay(10);
Delay(10);
while(P33==0)
{
P33=1;
Delay(10);
Delay(10);
}
Delay(10);
Delay(10);
while(P33==1)
{
P33=1;
Delay(10);
Delay(10);
}
Delay(10);
Delay(10);
while(P33==0)
{
P33=1;
Delay(10);
Delay(10);
}
}
void int_zhongduan()
{
//外部中断1初始化
IT1 = 0;
EX1 = 1;
EA = 1;//打开中断
}
欢迎光临 独闷闷网 (http://dumenmen.com/)
Powered by Discuz! X3.2