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

📄 12864.c

📁 单片机控制LCD12864液晶显示驱动程序
💻 C
字号:
#include "12864.h"
//#include <reg52.h>

#define ShortDelay()\
{\
unsigned char t =20;\
while ( --t != 0 );\
}

void SPI_Write(char dat) //reentrant
{
unsigned char t = 8;
do
{
DATA = (bit)(dat & 0x80);
dat <<= 1;
CLK = 1;
ShortDelay();
CLK = 0;
ShortDelay();
} while ( --t != 0 );
}


char SPI_Read()// reentrant
{
char dat;
unsigned char t = 8;
DATA = 1; //读取数据之前DIO 引脚要置1 以切换到输入状态
do
{
CLK = 1;
ShortDelay();
dat <<= 1;
if ( DATA) dat++;
CLK = 0;
ShortDelay();
} while ( --t != 0 );
return dat;
}

void SPIWR(uchar Wdata,uchar RS)
{
	SPI_Write(0xf8+(RS<<1));
	SPI_Write(Wdata&0xf0);
	SPI_Write((Wdata<<4)&0xf0);
}
void WriteInstruction(uchar cmd)//写指令
{
    Delay(5000);
//	E=0;
//	RW=0;
 //   RS=0;
//    E=1;
    SPIWR(cmd,0);
    Delay(50);
//    E=0;   
}
void WriteData(uchar dat)//写数据
{
    Delay(50);
//	E=0;
//	RW=0;
//	RS=1;
//	E=1;
	SPIWR(dat,1); 
    Delay(50);
//    E=0; 

}
void LCDInit(void)//初始化LCD
{
	CS=0;
    Delay(600);
	CS=1;
	WriteInstruction(0x30);

    WriteInstruction(0x30);

    Delay(5000);
    WriteInstruction(0x30);
  	Delay(5000);
	WriteInstruction(0x0c);
    Delay(2000);
	WriteInstruction(0x01);
    Delay(2000);
	WriteInstruction(0x06);
  	Delay(2000);
}
/*void CLS(void)//清屏指令
{
  WriteInstruction(0x1);
}*/


void ShowSingle(uchar x,uchar y,uchar z)//X表示第几个字,Y表示第几行,Z表示字符;
{
  switch (y)
  {
    case 1:WriteInstruction(0x80+x-1);break;
    case 2:WriteInstruction(0x90+x-1);break;
    case 3:WriteInstruction(0x88+x-1);break;
    case 4:WriteInstruction(0x98+x-1);break;
	default:break;
  }
   WriteData(z);
}

//show_group()显示一行字或字符程序;X:从第几个字开始显示(1~8);Y:第几行(1~4);n:一行有几个字符
 void ShowGroup(uchar x,uchar y,uchar *p)
{
  switch (y)
  {
    case 1:WriteInstruction(0x80+x-1);break;
    case 2:WriteInstruction(0x90+x-1);break;
    case 3:WriteInstruction(0x88+x-1);break;
    case 4:WriteInstruction(0x98+x-1);break;
	default:break;
  }
  while(*p)
  {
  WriteData(*p++);
  }
}
 

//延时
void Delay(uint i)
{
  while(i--);
}

⌨️ 快捷键说明

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