#include
#include
#include
#include
#define unchar unsigned char
#define unint unsigned int
/*************LCD指令****************/
#define GLCD_ON 63 //打開LCD
#define GLCD_OFF 62 //關(guān)閉LCD
#define GLCD_LINE 192 //左半邊起始行
#define SET_PAGE 184 //設(shè)置頁數(shù)
#define SET_Y 64 //設(shè)置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;
//檢查忙碌標(biāo)志
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
}
/************初始復(fù)位*******************/
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);
}
}
/*********************寫入顯示數(shù)據(jù)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 送出 數(shù)據(jù)
EN=0; // P2_7= 0
RS=0; // P2_5 = 0
RW=1; // P2_6 = 1
// 檢查忙碌標(biāo)記,直到繪圖型LCD不忙碌時就返回
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
}
/*********************讀顯示數(shù)據(jù)****************/
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;
//檢查忙碌標(biāo)志
check_GLCD();
CS1=bei_cs1;
CS2=bei_cs2;
return command;
}
gotoxy(unsigned x,unsigned y)
{
Gy=y;
Gx=x;
}
/*****************主程序區(qū)****************************/
main()
{
unsigned int j,n;
unsigned char c2,c3;
while(1)
{
clear_GLCD();
gotoxy(0,0);
write_GLCD(1); //設(shè)置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); //設(shè)置x 3F/63
CS1=0;
CS2=0;
EN=0;
for(n=0;n<50000;++n);
}
}
1044201183705432.sch