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

📄 lcd.c

📁 LwIP adaptation for Fujitsu MB90f497 and CS8900A Ethernet driver
💻 C
字号:
#include "mb90495.h"
#include "lwip/lcd.h"
#include <math.h>
#define DATAP PDR5
#define E PDR5_P56
#define RS PDR5_P54
#define MARK 0
#define RW PDR5_P55
#pragma section FAR_CODE=RAMCODE	/* located the program into RAM */
#pragma section CODE=RAMCODE


static char LCD_data[4][20];
static char LCDline=0;
static char LCDlinepos=0;

void Delay(unsigned int cnt)
{
    while(cnt>1) cnt--;
}



void lcdout(unsigned char f)
{
 DATAP=(DATAP & 0xf0) | (f & 0x0f);
 Delay(10);
 E=0;
 Delay(5);
 E=1;
 Delay(5);
 
}

void Put_Inst(unsigned char f)
{
 

 RS=0;

 DATAP=(DATAP & 0xf0) | ((f & 0xf0) >> 4);

 E=0;
 Delay(5);
 E=1;
 Delay(5);

 DATAP=(DATAP & 0xf0) | (f & 0x0f);

 E=0;
 Delay(5);
 E=1;
 Delay(20);


}

void Put_Char_ll(unsigned char f) {
 RS=1;
// Delay(10);
 DATAP=(DATAP & 0xf0) | ((f & 0xf0) >> 4);
// Delay(10);
 E=0;
 Delay(5);
 E=1;
 Delay(5);
 DATAP=(DATAP & 0xf0) | (f & 0x0f);
// Delay(10);
 E=0;
 Delay(5);
 E=1;
 Delay(20);
}

void ShiftDisplay() {
char x,y;
SetCur(0,0);
for(x=1;x<4;x++) {
	SetCur(x-1,0);
	for(y=0;y<20;y++) {
		LCD_data[x-1][y]=LCD_data[x][y];
		Put_Char_ll(LCD_data[x-1][y]);
	}
	};
	SetCur(3,0);
	for(x=0;x<20;x++) Put_Char_ll(' ');
}
	
void Put_Char(unsigned char f)
{
	if(f=='\n') {
		if(LCDlinepos<19) 
		for(;LCDlinepos<=19;LCDlinepos++) 
			LCD_data[LCDline][LCDlinepos]=' ';	
		LCDlinepos=0;
		if(++LCDline>3) {
			LCDline=3;
			ShiftDisplay();
		}
		SetCur(LCDline,LCDlinepos);
		return;
	}
	
 if(LCDlinepos==20) {
	if(++LCDline<=3) {
		LCDlinepos=1;
		SetCur(LCDline,0);	  
		LCD_data[LCDline][LCDlinepos]=f;
                Put_Char_ll(f);
		return;
		} else { 
			ShiftDisplay();
			LCDline=3;
		        LCDlinepos=1;
			SetCur(3,0);
			LCD_data[3][0]=f;
			Put_Char_ll(f);
			return;
			}
	} else {
		LCD_data[LCDline][LCDlinepos]=f; 
		Put_Char_ll(f);
		LCDlinepos++;	
	}
}

void Clr(void)
{
Put_Inst(0x01);
Delay(50000);
}


void SetCur(char string,char collumn)
{
	
     switch(string) {
    case 0:  Put_Inst(0x80 | collumn);
         break;
    case 1:  Put_Inst(0x80 | 0x40 | collumn);
         break;
    case 2:  Put_Inst(0x80 | (0x14 + collumn));
         break;
    case 3:  Put_Inst(0x80 | 0x40 | (0x14 + collumn));
         break;
    default: break;
    }
  //while(CheckBusy()!=0);
	Delay(100);
}

void Put_String(const char *p)
{

 while(*p!='\0') { 
		Put_Char(*p);
        p++;
	}


}


void LCDInit(void) {
 ADER=0;
 DDR5=0xff;
 PDR5=0x40;
 RW=0;
 Delay(40000);

 lcdout(0x03);
 Delay(40000);
 
 lcdout(0x03);

 Delay(40000);
 lcdout(0x03);
 Delay(40000);
 Delay(40000);



 DATAP=(DATAP & 0xf0)| 0x02;
 E=0;
 Delay(5);
 E=1;
 Delay(5);
 Put_Inst(0x28);
 Put_Inst(0x0C);
 Put_Inst(0x06);
 Put_Inst(0x01);
 Delay(2000);
 
}

/* arg - 麒耠

⌨️ 快捷键说明

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