單片機連接PG160128A基本操作

PG160128A爲一個有160*128點陣的lcd顯示屏,它有着16個字模

相關文檔在連接:

https://max.book118.com/html/2017/0702/119715409.shtm

個人硬件連接圖如下

運行效果圖如下

下面是代碼,請結合硬件連接圖來看基本操作

代碼移植的時候只需更改變量 data1 wr rd cd

#include"reg52.h"
#define uchar unsigned char
sfr data1=0xA0;
//data1爲P2傳輸數據	P2的地址爲0xA0 來源於reg52.h
sbit wr=P3^6;
sbit rd=P3^7;
sbit cd=P3^5;

//寫一次數據
void wrOneData(uchar data_1);
//讀取狀態檢測
uchar lcdStatue();
//判斷s0s1爲高
void lcdEnable();
//發送無參命令
void postFunction0(uchar cmd);
//發送單參數命令
void postFunction1(uchar cmd, uchar data_1);
//發送雙參數命令
void postFunction2(uchar cmd, uchar data_1, uchar data_2);
//判斷s2s3爲高
void lcdOneWrEnable();
//一次讀寫測試
void lcdOneWr();
void main(){
	while(1){
		postFunction2(0x42,0x00,0x00);
		postFunction2(0x43,0x14,0x00);
		postFunction0(0x44);
		postFunction0(0x96);
		lcdOneWr();
		postFunction2(0x21,0x00,0x00);
		
	}
}


uchar lcdStatue(){
	uchar flag;
	cd=1;
	rd=1;
	wr=1;
	data1=0xff;
	rd=0;
	flag=data1;
	rd=1;
	return flag;
}

void lcdEnable(){
	while(1){
	if(lcdStatue()&0x03==0x03)
		break;
	}
}

void postFunction0(uchar cmd){
	lcdEnable();
	cd=1;
	rd=1;
	data1=cmd;
	wr=0;
	wr=1;
}
void postFunction1(uchar cmd,uchar data_1){
	lcdEnable();
	cd=0;
	rd=1;
	wr=1;
	data1=data_1;
	wr=0;
	wr=1;
	lcdEnable();
	cd=1;
	rd=1;
	data1=cmd;
	wr=0;
	wr=1;
}

void postFunction2(uchar cmd,uchar data_1,uchar data_2){
	lcdEnable();
	cd=0;
	rd=1;
	wr=1;
	data1=data_1;
	wr=0;
	wr=1;
	lcdEnable();
	cd=0;
	rd=1;
	wr=1;
	data1=data_2;
	wr=0;
	wr=1;
	lcdEnable();
	cd=1;
	rd=1;
	data1=cmd;
	wr=0;
	wr=1;
}

void lcdOneWrEnable(){
	while(1){
		if(lcdStatue()&0x0c==0x0c){
		break;
		}
	}
}
void LcdOneWr(){
	int i=0;
	postFunction2(0x24,0x00,0x00);
	lcdOneWrEnable();
	postFunction0(0xb0);
	for(i=0;i<128;i++){
		lcdOneWrEnable();
		//這裏向PG160128A發送數據使用的是字庫的數據範圍爲0x02~0x0f
		wrOneData(0x02);
	}
	postFunction0(0xb2);
}

void wrOneData(uchar data_1){
	cd=0;
	wr=1;
	rd=1;
	data1=data_1;
	wr=0;
	wr=1;
}

作者:吾非善類

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章