#include
#include
#include
#include
#define unchar unsigned char
#define unint unsigned int
/*************LCD指令****************/
#define GLCD_ON 63 //打开LCD
#define GLCD_OFF 62 //关闭LCD
#define GLCD_LINE 192 //左半边起始行
#define SET_PAGE 184 //设置页数
#define SET_Y 64 //设置Y轴位置
#define CLEAR 0 //清除LCD
/*************LCD控制****************/
sbit EN = P2^7;
sbit RW = P2^6;
sbit RS = P2^5;
sbit CS2 = P2^4;
sbit CS1 = P2^3;
unchar Gx,Gy;
/***************查忙*****************/
check_GLCD()
{
unsigned char x,bei_cs1,bei_cs2;
bei_cs1=CS1;
CS1=0;
bei_cs2=CS2;
CS2=0;
EN = 0;
RW = 1;
RS = 0;
P1 = 0xff;
EN = 1;
do
{
x=P1&0x80;
}
while(x);
EN = 1;
RW = 1;
RS = 1;
CS1=bei_cs1;
CS2=bei_cs2;
}
/*********************写入控制指令0/0****************/
void write_GLCD(unsigned command)
{
unsigned char bei_cs1,bei_cs2;
bei_cs1=CS1;
bei_cs2=CS2;
EN = 0;
CS1=0;
CS2=0;
RW = 0;
RS = 0;
EN = 1;
P1 = command;
EN = 0;
RW = 1;
RS = 1;
//检查忙碌标志
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
}
/************初始复位*******************/
clear_GLCD()
{
unsigned int i,j;
for(i=0;i<2;i++);
CS1=1;
CS2=1;
write_GLCD(GLCD_ON);
write_GLCD(GLCD_LINE);
for(i=0;i<8;i++)
{
write_GLCD(SET_PAGE+i);
write_GLCD(SET_Y);
for(j=0;j<64;j++)
write_GLCD(0);
}
}
/*********************写入显示数据1/0****************/
void write_GLCD_data(unsigned GLCDdata)
{
unsigned char bei_cs1,bei_cs2;
bei_cs1=CS1;
bei_cs2=CS2;
EN=0;
CS1=0;
CS2=0;
RW=0; // P2_6 = 0
RS=1; // P2_5 = 1
EN=1; // P2_7=1
P0=GLCDdata; // 从 P0 送出 数据
EN=0; // P2_7= 0
RS=0; // P2_5 = 0
RW=1; // P2_6 = 1
// 检查忙碌标记,直到绘图型LCD不忙碌时就返回
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
}
/*********************读显示数据****************/
read_GLCD()
{
unsigned char bei_cs1,bei_cs2,command;
bei_cs1=CS1;
bei_cs2=CS2;
EN = 0;
CS1=0;
CS2=0;
P1=0xff;
RW = 1;
RS = 1;
EN = 1;
command = P1;
EN = 0;
RW = 1;
RS = 1;
//检查忙碌标志
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
return command;
}
gotoxy(unsigned x,unsigned y)
{
Gy=y;
Gx=x;
}
/*****************主程序区****************************/
main()
{
unsigned int j,n;
unsigned char c2,c3;
while(1)
{
clear_GLCD();
gotoxy(0,0);
write_GLCD(1); //设置x 3F/63 GLCD_ON
write_GLCD(GLCD_LINE); // C0/192
for(c2=0;c2<4;c2++)
{
write_GLCD(SET_PAGE+c2); //184
write_GLCD(SET_Y); //64
for(j=0;j<64;j++)
{
write_GLCD(64+j);
write_GLCD_data(j);
c3=read_GLCD();
}
c3=read_GLCD();
}
EN=1;
write_GLCD(1); //设置x 3F/63
CS1=0;
CS2=0;
EN=0;
for(n=0;n<50000;++n);
}
}
1044201183705432.sch