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

📄 lcd.cpp

📁 dsp2812上的零耗时键盘 c++源代码例子
💻 CPP
字号:
#include "lcd.h"

LcdObj::LcdObj(void)
{
	Init();
}

void LcdObj::Init(void)
{
    SendCommand(0x30);//发送功能设定控制命令(8位)
    SendCommand(0x30);//发送功能设定控制命令(8位)
    SendCommand(0x01);//发送清除显示命令 
    SendCommand(0x06);//发送进入点命令0x06 
    SendCommand(0x0a);//发送开关显示关光标命令
    SendCommand(0x0c);//发送开显示关光标命令
    SendCommand(0x02);//发送位址归位命令,设定DDRAM位址计数器为0
	SendCommand(0x17);//游标或显示移位控制
    SendCommand(0x80);//发送设定DDRAM地址0x00命令,光标定位到(0,0)
	ClearBuffer();//清空LCD显示缓冲区
	DisplayBuffer();
}

void LcdObj::delay(unsigned int t)
{
  	while(t>0)
  	{
    	t--;
    	for (int i = 0; i < 150; i++);
    }
}

void LcdObj::SendCommand(char cCommand)
{
	LcdComH = cCommand;
	LcdComL = cCommand;
  	if (cCommand == 0x01)//清除显示命令,需要等待时间相对较长
	{
		delay(1600);//st7920要求等待1.6mS
//		DSP28x_usDelay(1600);//st7920要求等待1.6mS
	}
  	else
	{
		delay(72);//st7920要求等待72uS
//		DSP28x_usDelay(72);//st7920要求等待72uS
	}
}

void LcdObj::SendData(char cData)
{
	LcdDatH = cData;
	LcdDatL = cData;
	delay(72);//st7920要求等待72uS
//	DSP28x_usDelay(72);//st7920要求等待72uS
}

void LcdObj::ClearBuffer(void)
{
unsigned char i, j;
	for (i = 0;i < 4;i ++) 
	{
		for (j = 0;j < 16; j ++) 
		{
		  Buffer[i][j] = ' ';
		}
		RowWriteEnable[i] = 1;//允许此行刷新汉字显示
	}
	Row = 0;
	Col = 0;
}

void LcdObj::DisplayBuffer(void)
{
unsigned char i, j;
  	for (i = 0; i < 4; i ++) 
  	{//4行汉字
    	if (RowWriteEnable[i]) 
    	{//允许此行刷新汉字显示
      		SendCommand(0x80 + (i & 1) * 16 + (i >> 1) * 8);//移动光标
      		for (j = 0; j < 16; j ++) 
      		{//每行8个汉字16个字符
        		SendData(Buffer[i][j]);//刷新显示字符
      		}
	  		RowWriteEnable[i] = 0;//过后不允许此行刷新汉字显示
		}
  	}
}

void LcdObj::SetDisplayPos(unsigned char row, unsigned char col)
{
	Row = row & 0x03;//4行
	Col = col & 0x0f;//16列
}

void LcdObj::Display(const char *string)
{
char len, i;
  	len = strlen(string);
  	if ((Row < 4) && ((Col + len) <= 16)) 
  	{
    	if (len == 0) 
    	{
      		while(Col < 16) 
      		{
      			Buffer[Row][Col ++] = ' ';
      		}
		}
		else
      		for (i = 0; i < len; i ++) Buffer[Row][Col ++] = string[i];
		RowWriteEnable[Row] = 1;//需要显示刷新
  	}
}

⌨️ 快捷键说明

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