📄 bw128x64.c
字号:
#include <reg52.H>
#define TRUE 1
#define FALSE 0
sbit CS1= P3^0; //0有效
sbit CS2= P3^1;
sbit DI = P3^2; //1 data,0 instruction
sbit RW = P3^3; //1 read,0 write
sbit E = P3^4; // 1 读状态,0 写状态,下降沿锁存
sbit RESET = P3^5; //0 复位,1常态
sbit Busy = P1^7;
//unsigned char COLUMN;
void Initial();
void Delay(unsigned int time);
bit Q_Busy();
void Data_Write(unsigned char aa);
void Code_Write(unsigned char aa);
unsigned char Status_Read();
unsigned char Data_Read();
void location(unsigned y,unsigned x);
void Select_Chip1();
void Select_Chip2();
void Display_LcdWrite();
void Display_logo() ;
void test89(); // 测试89系统是否正常
void Lcd_Clear();
unsigned char code Logo9616[192];
//******************************************************
void main()
{
// test89();
Select_Chip1();
Initial();
Select_Chip2();
Initial();
while(1){
Lcd_Clear();
Display_LcdWrite();
// Display_logo() ;
};
}
//初始化
void Initial()
{
RESET=0; //复位有效
Delay(10000);
RESET=1;
Delay(10000);
Code_Write(0x3e); //display off
Delay(1000);
Code_Write(0x40); //Sets the Y address in the Y address counter.
Delay(1000);
Code_Write(0xb8); //Sets the X address at the X address register.
Delay(1000);
Code_Write(0xc0); //Z:Indicates the display data RAM displayed at the top of the screen.
Delay(1000);
Code_Write(0x3f); //display on
Delay(1000);
}
//延时
void Delay(unsigned int time)
{
while(time) time--; /*delay time*/
}
//查询 busy与否状态
bit Q_Busy()
{
bit kk;
Status_Read();
kk=Busy;
return kk; //1,busy;0,free;
}
//write 子程序:2个区分数据命令
void Data_Write(unsigned char aa)
{
// while(Q_Busy()){};
DI=1;
RW=0;
P1=aa; //作busy状态查询
E=1;
E=0;
}
void Code_Write(unsigned char aa)
{
// while(Q_Busy()){}; //作busy状态查询
DI=0;
RW=0;
P1=aa;
E=1;
E=0;
}
//读状态
unsigned char Status_Read()
{
unsigned char aa;
P1=0xff; //先写ff,后查询状态
DI=0;
RW=1;
E=1;
aa=P1;
E=0;
return aa;
}
//读数据
unsigned char Data_Read()
{
unsigned char aa;
// while(Q_Busy()){};
DI=1;
RW=1;
E=1;
E=0;
aa=0xff;
E=1;
aa=P1;
E=0;
return aa;
}
void location(unsigned y,unsigned x)//希望出现在y列,x页这个位置
{
y=y%128;
x=x%8; //一页是对应一个字节的8位
if(y>=64)
{
Select_Chip2();
y=y-64;
Code_Write(0x40+y); //Set Y 列
Code_Write(0xb8+x); //Set X 页
Delay(1000);
}
else {
Select_Chip1();
Code_Write(0x40+y); //Sets Y
Code_Write(0xb8+x); //X
Delay(1000);
}
}
void Select_Chip1()
{
CS1=1;CS2=0;
}
void Select_Chip2()
{
CS1=0;CS2=1;
}
//==================
//在LCD上清屏
//==================
void Lcd_Clear()
{
unsigned int i;
unsigned int j;
for(i=0;i<8;i++)
{
for(j=0;j<128;j++)
{
location(j,i); //j列,i 页
Data_Write(0xff);//1,dark;0,light;
}
}
}
//==================
//在LCD上显示写过程
//==================
void Display_LcdWrite()
{
unsigned int i;
unsigned int j;
for(i=0;i<4;i++)
{
for(j=0;j<130;j++)
{
location(j,i*2); //i 页,j列
Data_Write(0x00);//1,dark;0,light;
}
}
}
//========================================================
void Display_logo()
{
unsigned char z=0;
unsigned char i;
unsigned char j;
for(i=0;i<16;i++) //黑白图像,数组值为0,为亮,一个字节的一位(从高到低)代表了一个像素点
{
for(j=0;j<12;j++)
{
z=j+(i/8)*12;
location(z,i);
Data_Write(Logo9616[i*12+j]); //GD 16H*12L
}
}
Delay(500);
}
unsigned char code Logo9616[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //12列x16行
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xF0,0x00,0x38,0x3F,0x80,0x1F,0xF8,0x00,0xFC,0x00,0x1F,0xFF,
0x80,0x00,0x08,0x3F,0x80,0x0F,0xF8,0x00,0xF8,0x04,0x1F,0xFF,
0x80,0x00,0x08,0x3F,0x80,0x0F,0xF0,0x00,0xF0,0x0C,0x1F,0xFF,
0xC0,0x7E,0x08,0x3F,0x81,0x00,0x00,0x20,0xC0,0x1C,0x1F,0xFF,
0xCF,0x80,0x08,0x3F,0x81,0x80,0x00,0x60,0x80,0x3C,0x00,0x07,
0xF8,0x00,0x08,0x00,0x01,0xC0,0x00,0x60,0x00,0x0C,0x00,0x01,
0xE0,0x00,0x18,0x00,0x01,0xC1,0xC0,0xE0,0x80,0x04,0x00,0x00,
0xC0,0x00,0x78,0x00,0x01,0xE1,0x81,0xE0,0xFE,0x00,0x1F,0xC0,
0xC0,0x1F,0xD8,0x3F,0x81,0xE0,0x01,0xE0,0xFF,0x00,0x1F,0xE0,
0xC0,0xF8,0x18,0x3F,0x81,0xF0,0x03,0xE0,0x7E,0x00,0x1F,0x80,
0xC0,0x00,0x08,0x3F,0x81,0xF8,0x03,0xE0,0x00,0x04,0x00,0x00,
0xE0,0x00,0x08,0x3F,0x81,0xF8,0x07,0xE0,0x00,0x0C,0x00,0x01,
0xF8,0x00,0x38,0x3F,0xC1,0xFE,0x1F,0xF0,0x00,0x7F,0x00,0x1F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
//=================================================================
void test89()
{
do{
P1=0x0;
Delay(60000);
Delay(60000);
Delay(60000);
P1=0xff;
Delay(60000);
Delay(60000);
Delay(60000);
}while (1) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -