AMPIRE 128X64驱动程序

c55连接AMPIRE12864硬件连接图如下

驱动程序如下

所有的函数实现效果注释中有

如果硬件连接图不一样的话建议更改 ce wr rs cs1 cs2 LcdData的值。

 #pragma large
#include"reg52.h"
#define uchar unsigned char 
sbit ce=P3^4;
sbit wr=P3^6;
sbit rs=P3^5;
sbit cs1=P3^3;
sbit cs2=P3^7;
sfr LcdData=0x90;

//检测LCD标志位
void checkLcd(){
	uchar a;
	do{
		LcdData=0xff;
		rs=0;
		wr=1;
		ce=1;
		ce=0;
		a=LcdData;
		a=a&0x80;
		if(a==0x00)
			break;
	}while(1);
}


//向LCD发送一个无参数命令
void writeCmd(uchar cmd){
	checkLcd();
	rs=0;
	wr=0;
	LcdData=cmd;
	ce=1;
	ce=0;
}

//向lcd写一个一字节的数据
void writeShowData(uchar showData){
	checkLcd();
	rs=1;
	wr=0;
	LcdData=showData;
	ce=1;
	ce=0;
}


//初始化LCD页地址
void setLcdX(uchar x){
	writeCmd(0xb8|x);
}
//初始化LCD列地址
void setLcdY(uchar y){
	writeCmd(0x40|y);
}

//初始化LCD
void initLcd(){
	cs1=0;
	cs2=0;
	writeCmd(0x3e);
	writeCmd(0xb8);
	writeCmd(0xc0);
	writeCmd(0x40);
	writeCmd(0x3f);
}

//将二维数组写入LCD12864当中 LcdData_1为LcdData_1[8][128]
void writeData(){
	uchar i,j;
	for(i=0;i<8;i++){
		
		for(j=0;j<128;j++){
			if(j==0){
				cs1=0;
				cs2=1;
				setLcdY();
			}
			if(j==64){
				cs1=1;
				cs2=0;
				setLcdY();
			}
			setLcdX(i);
			writeShowData(0x0f);
		}
	}
}

//画一个点
void writePoint(uchar x,uchar y,uchar LcdShowData){
	if(y>=64){
		cs1=1;
		cs2=0;
	}
	if(y<64){
		cs1=0;
		cs2=1;
	}
	setLcdX(x);
	setLcdY(y);
	writeShowData(LcdShowData);
}

猜你喜欢

转载自blog.csdn.net/qq_36797488/article/details/104624507