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

📄 lsd12864.h

📁 为MSP430设计的12864
💻 H
字号:

typedef unsigned long DWORD;
typedef unsigned int  WORD;
typedef unsigned char BYTE;

#define		P2_0_RS			0x01
#define		P2_1_RW			0x02
#define		P2_2_EN			0x04
#define		P2_3_CS1		0x08
#define		P2_3_CS2		0x40
#define		P2_3_RST		0x80

#define		P3_0_DB0		0x01
#define		P3_1_DB1		0x02
#define		P3_2_DB2		0x04
#define		P3_3_DB3		0x08
#define		P3_4_DB4		0x10
#define		P3_5_DB5		0x20
#define		P3_6_DB6		0x40
#define		P3_7_DB7		0x80


BYTE yi[16]=
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
BYTE er[16]=
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};
BYTE san[16]=
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};
BYTE si[16]=
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};
BYTE wu[16]=
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};
BYTE liu[16]=
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};
BYTE qi[16]=
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};
BYTE ba[16]=
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};
BYTE jiu[16]=
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};
BYTE ling[16]=
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};



void lsd_ini( void )
{
	P3DIR = 0xFF;  //选为输出
	P3OUT = 0x00;
	
	P2DIR  = 0xFF;
	P2OUT  = P2_3_CS1 | P2_3_CS2 | P2_3_RST;  //对应为一
	P2OUT &=~P2_3_RST;  //RST清零
	_NOP();
	_NOP();
	P2OUT |= P2_2_EN;  //LCD使能信号
	_NOP();
	_NOP();
	P2OUT &=~P2_2_EN;  //LCD使能信号清零
	_NOP();
	_NOP();
	P2OUT |= P2_3_RST;  //RST置一
	_NOP();
	_NOP();		//CS1 CS2 RST为一
}

void write_command( BYTE nByte )
{
	P3DIR = 0xFF;
	P2OUT |= P2_3_CS1+P2_3_CS2;  //CS1 CS2 置一,选中左右两屏
	P2OUT &=~(P2_0_RS+P2_1_RW);  //D/I=0,地址线为指令,R/W=0
	P3OUT = nByte;  //输出指令
	P2OUT |= P2_2_EN;
	P2OUT &=~P2_2_EN;  //E产生下降沿,指令读入LED
}

void write_char( BYTE nByte, BYTE CS1, BYTE CS2 )
{
	P3DIR = 0xFF;
	//选屏	
	if(CS1) P2OUT |= P2_3_CS1;
	else P2OUT &=~P2_3_CS1;
	
	if(CS2) P2OUT |= P2_3_CS2;
	else P2OUT &=~P2_3_CS2;
	
	P2OUT |= P2_0_RS;  //地址线为显示数据
	P2OUT &=~P2_1_RW;  //R/W=0
	
	P3OUT  = nByte;
	P2OUT |= P2_2_EN;
	P2OUT &=~P2_2_EN;  //E产生下降沿,数据读入LED
}
void clear_lcd( void )
{
	BYTE i,j;
	for(i=0;i<8;i++)
	{
		write_command(i|0xB8);  //设置页地址
		write_command(0x40);  //Y指针指起始位置
		for(j=0;j<128;j++)
		{
			if(j<=63) write_char(0,1,0);
			else write_char(0,0,1);
			_NOP();
		}
	}
	
}


void display_hz ( BYTE *chr, BYTE nRow, BYTE nCol ) //先行再列、2行128列.nCol不应大于127
{
	BYTE i,tmpCol;
	
	write_command(0xB8|nRow);   //设置页地址
	tmpCol=nCol;
	for(i=0;i<16;i++)
	{
		if(tmpCol<=63)
		{
			write_command(0x40|tmpCol);
			write_char(chr[i],1,0);  //左半屏输出
		}
		else
		{
			write_command(0x40|(tmpCol-64));
			write_char(chr[i],0,1);  //右半屏输出
		}
		tmpCol++;
	}
	
	write_command(0xB8|nRow+1);
	tmpCol=nCol;
	for(i=0;i<16;i++)
	{
		if(tmpCol<=63)
		{
			write_command(0x40|tmpCol);
			write_char(chr[i+16],1,0);
		}
		else
		{
			write_command(0x40|(tmpCol-64));
			write_char(chr[i+16],0,1);
		}
		tmpCol++;
	}
}
void display_char( BYTE *chr, BYTE nRow, BYTE nCol )
{
	BYTE i,tmpCol;
	
	write_command(0xB8|nRow);   //设置页地址
	tmpCol=nCol;
	for(i=0;i<8;i++)
	{
		if(tmpCol<=63)
		{
			write_command(0x40|tmpCol);
			write_char(chr[i],1,0);  //左半屏输出
		}
		else
		{
			write_command(0x40|(tmpCol-64));
			write_char(chr[i],0,1);  //右半屏输出
		}
		tmpCol++;
	}
	
	write_command(0xB8|nRow+1);
	tmpCol=nCol;
	for(i=0;i<8;i++)
	{
		if(tmpCol<=63)
		{
			write_command(0x40|tmpCol);
			write_char(chr[i+8],1,0);
		}
		else
		{
			write_command(0x40|(tmpCol-64));
			write_char(chr[i+8],0,1);
		}
		tmpCol++;
	}
}



void display_shuzi (unsigned int a,BYTE nRow, BYTE nCol)
{
  int shu [6]={0,0,0,0,0,0};
  int i;
  int flag=0;
  shu[4]=a/10000;
  shu[3]=(a/1000)%10;
  shu[2]=(a/100)%10;
  shu[1]=(a/10)%10;
  shu[0]=a%10;
  for (i=4;i>=0;i--)
  {
    switch (shu[i])
    {
    case 1:display_char (yi,nRow,nCol+8*(4-i));flag=1;break;
    case 2:display_char (er,nRow,nCol+8*(4-i));flag=1;break;
    case 3:display_char (san,nRow,nCol+8*(4-i));flag=1;break;
    case 4:display_char (si,nRow,nCol+8*(4-i));flag=1;break;
    case 5:display_char (wu,nRow,nCol+8*(4-i));flag=1;break;
    case 6:display_char (liu,nRow,nCol+8*(4-i));flag=1;break;
    case 7:display_char (qi,nRow,nCol+8*(4-i));flag=1;break;
    case 8:display_char (ba,nRow,nCol+8*(4-i));flag=1;break;
    case 9:display_char (jiu,nRow,nCol+8*(4-i));flag=1;break;
    case 0:if(shu[i+1]||flag)display_char (ling,nRow,nCol+8*(4-i));
    }
  }
  if(a==0)display_char (ling,nRow,nCol+32);
}

⌨️ 快捷键说明

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