⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 funclcd.c

📁 本人编写的无线电话程序,给予PIC18C801设计,包括了uCOS的移植以及菜单,自己设计的拼音注入法,完整地一级汉字库,希望对大家有所帮助
💻 C
字号:
/* File name: funcLCD.c                                                                              */
/* Description:                                                                                      */
/*   This file includes functions to operate the LCD                                                 */
/* State:                                                                                            */
/*   Under test with test1.mcp                                          2003.1.16                    */

#include <p18cxxx.h>
#include "includes.h"

#define RESET_LCD	LATCbits.LATC0

#pragma romdata IOPT1=0x131000
volatile unsigned char rom LCD1_CW;	//LCD left half control write port--0x131000
volatile unsigned char rom LCD1_CR;	//LCD left half control read port --0x131001
volatile unsigned char rom LCD1_DW;	//LCD left half data write port   --0x131002
volatile unsigned char rom LCD1_DR;	//LCD left half data read port    --0x131003

#pragma romdata IOPT2=0x131200
volatile unsigned char rom LCD2_CW;	//LCD right half control write port--0x131200
volatile unsigned char rom LCD2_CR;	//LCD right half control read port --0x131201
volatile unsigned char rom LCD2_DW;	//LCD right half data write port   --0x131202
volatile unsigned char rom LCD2_DR;	//LCD right half data read port    --0x131203

extern OS_EVENT  *rom DisplaySem;

void Do_LCD_Init(void){
	unsigned int i;
	//Set the pin output
	TRISCbits.TRISC0 = 0;
	//Reset the LCD
	RESET_LCD = 0;
	for(i=0;i<1000;i++){
		Nop();
	}
	RESET_LCD = 1;
	//Write initialization bytes
	while((LCD1_CR & 0x80)==0x80);
	LCD1_CW = 0x3f;
	while((LCD1_CR & 0x80)==0x80);
	LCD1_CW = 0xc0;
	while((LCD1_CR & 0x80)==0x80);
	LCD2_CW = 0x3f;
	while((LCD1_CR & 0x80)==0x80);
	LCD2_CW = 0xc0;
}

void Do_Clear_Screen(unsigned char startX,
					unsigned char startY,
					unsigned char endX,
					unsigned char endY){
	unsigned char leftY,rightY,leftW,rightW;
	unsigned char i,j,k;
	//unsigned char err;
	
	if(startY >= 64){	//Right half screen
		rightY = startY - 64;
		rightW = endY - startY + 1;
		leftW = 0;
	}
	else{
		leftY = startY;
		if(endY > 64){//Both half screen
			rightY = 0;
			leftY = startY;
			leftW = 64 - startY;
			rightW = endY-startY - leftW +1;
		}
		else {//left half screen
			leftW = endY - startY + 1;
			rightW = 0;
		}
	}

	OSSemPend(DisplaySem, 0, &i);//err);
	if (i == OS_NO_ERR){  //err == OS_NO_ERR
		if(leftW != 0){
			for(i = startX; i<=endX; i++){
				k = 0;
				while((LCD1_CR & 0x80)==0x80 && k<20){k++;}
				LCD1_CW = 0xb8 + i;
				k = 0;
				while((LCD1_CR & 0x80)==0x80 && k<20) {k++;}
				LCD1_CW = 0x40 + leftY;
				for(j=0;j<leftW;j++){
					k = 0;
					while((LCD1_CR & 0x80)==0x80 && k<20) {k++;}
					LCD1_DW = 0;
				}
			}
		}
		if(rightW != 0){
			for(i = startX; i<=endX; i++){
				k = 0;
				while((LCD2_CR & 0x80)==0x80&& k<20) {k++;};
				LCD2_CW = 0xb8 + i;
				k = 0;
				while((LCD2_CR & 0x80)==0x80&& k<20) {k++;};
				LCD2_CW = 0x40 + rightY;
				for(j=0;j<rightW;j++){
					k = 0;
					while((LCD2_CR & 0x80)==0x80&& k<20) {k++;};
					LCD2_DW = 0;
				}
			}
		}
	}
	OSSemPost(DisplaySem);
}

void Display_Picture(INT8U PosX, INT8U PosY, INT8U Width, INT8U Height, INT8U rom *pP, INT8U reverse){
	unsigned char leftY,leftW,rightY,rightW;
	unsigned char i,j,k;
	//unsigned char err;

	if(PosY >= 64){	//Right half screen
		rightY = PosY - 64;
		rightW = Width;
		leftW = 0;
	}
	else{
		leftY = PosY;
		if(PosY + Width > 64){//Both half screen
			rightY = 0;
			leftY = PosY;
			leftW = 64 - PosY;
			rightW = Width - leftW;
		}
		else {//left half screen
			leftW = Width;
			rightW = 0;
		}
	}
	
	OSSemPend(DisplaySem, 0, &i);
	if (i == OS_NO_ERR){
		for(j=PosX; j< PosX + Height; j++){
			if(leftW != 0){
				k = 0;
				while((LCD1_CR & 0x80)==0x80 && k<20) {k++;};
				LCD1_CW = 0xb8 + j;
				k = 0;
				while((LCD1_CR & 0x80)==0x80 && k <20) {k++;};
				LCD1_CW = 0x40 + leftY;
				for(i=0;i<leftW;i++){
					k = 0;
					while((LCD1_CR & 0x80)==0x80 && k<20) {k++;};
					LCD1_DW = (*pP++) ^ reverse;
				}
			}
			if(rightW != 0){
				k = 0;
				while((LCD2_CR & 0x80)==0x80 && k<20) {k++;};
				LCD2_CW = 0xb8 + j;
				k=0;
				while((LCD2_CR & 0x80)==0x80 && k<20) {k++;};
				LCD2_CW = 0x40 + rightY;
				for(i=0;i<rightW;i++){
					k = 0;
					while((LCD2_CR & 0x80)==0x80 && k < 20) {k++;};
					LCD2_DW = (*pP++) ^ reverse;
				}
			}
		}
	}
	OSSemPost(DisplaySem);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -