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

📄 splc051.c

📁 Atmega16+SPCL051液晶驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
//***************************************************************************//
//文件描述:SPLC501用户接口驱动程序,
//
//声明:	小丑	20050519	Sunnorth	Mz Design
//
//
//***************************************************************************//
//头文件
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/delay.h>
//自定义头文件
#include	"SPLC051.h"
#include	"main.h"
//宏定义
#define CS1	0
#define RES	1
#define A0	2
#define RW	3
#define EP	4
#define LED0()	PORTB|=(1<<PB1)
#define LED1()	PORTB&=~(1<<PB1)

unsigned int CurPaintMode;				//Show Mode Cover of XOR
unsigned int CurPowerMode;				//Show the Power Mode of LCD501
unsigned int CurLCDSet;					//Show the LCD Set灰度
unsigned int CurScroll;					//Show the scroll dotes
unsigned int CurScrMode;				//显示正相/反相(1/0)
unsigned int CurASCIIFont;				//当前ASCII码的字号(8X16/6X8)

//**************
void LED_test(void)
{
	while(1)
	{
		PORTB=0xff;
		LED1();
		for(int i=0;i<50;i++)
			_delay_ms(250);
		LED0();
		PORTB=0xff;
		for(int i=0;i<50;i++)
			_delay_ms(250);
	}
}//***************************************************************************//
//程序:F_SPLC501_Initial_IO()
//描述:SPLC501接口的初始化程序  C语言调用 
//参数:无
// 声明:	手心	20070117	AVRGCC
//***************************************************************************//
void F_SPLC501_Initial_IO(void)
{
	DDRA=(1<<A0)|(1<<CS1)|(1<<EP)|(1<<RW);				//定义为输出口,控制LCD
	PORTA=0xff;
	DDRB=0xff;				//定义为输出口,数据端口
	PORTB=0xff;
}
//***************************************************************************//
//程序:F_SPLC501_Write_Com(unsigned int Command)
//描述:往SPLC501里写一个字节指令  C语言调用
//参数:送入要传送的指令
// 声明:	手心	20070117	AVRGCC
//注意A0=0,EP=1,RW=0,Cs=0
//***************************************************************************//
void F_SPLC501_Write_Com(unsigned int Command)
{
	PORTA=(0<<A0)|(1<<EP)|(0<<RW)|(0<<CS1);	//片选LCD,使能命令模式
	DDRB=0xff;				//定义为输出口,数据端口
	PORTB=Command;
	PORTA|=(1<<CS1);							//取消片选
}
//***************************************************************************//
//程序:F_SPLC501_Write_Data(unsigned int SendData)
//描述:往SPLC501里写一个字节数据  C语言调用
//参数:送入要传送的数据
// 声明:	手心	20070117	AVRGCC
//注意A0=1,EP=1,RW=0,Cs=0
//***************************************************************************//
void F_SPLC501_Write_Data(unsigned int SendData)
{
	PORTA=(1<<A0)|(1<<EP)|(0<<RW)|(0<<CS1);	//片选LCD,使能写数据
	DDRB=0xff;				//定义为输出口,数据端口
	PORTB=(SendData);
	PORTA|=(1<<CS1);							//取消片选
}
//***************************************************************************//
//程序:F_SPLC501_Read_Data()
//描述:从SPLC501里读一个字节数据  C语言调用
//参数:输出传送的数据
// 声明:	手心	20070117	AVRGCC
//注意A0=1,EP=0,RW=1,Cs=0
//***************************************************************************//
unsigned int F_SPLC501_Read_Data(void)
{
	unsigned int temp_data;
	PORTA=(1<<A0)|(0<<EP)|(1<<RW)|(0<<CS1);	//片选LCD,使能读数据
	DDRB=0x00;				//定义为输入口,数据端口
	temp_data=PORTB;
	PORTA|=(1<<CS1);							//取消片选
	return temp_data;
}
//***************************************************************************//
//程序:F_SPLC501_Read_Status()
//描述:从SPLC501里读状态字数据  C语言调用
//参数:输出传送的数据
// 声明:	手心	20070117	AVRGCC
//注意A0=0,EP=0,RW=1,Cs=0
//***************************************************************************//
unsigned int F_SPLC501_Read_Status(void)
{
	unsigned int temp_status;
	PORTA=(0<<A0)|(0<<EP)|(1<<RW)|(0<<CS1);	//片选LCD,使能读状态
	DDRB=0x00;				//定义为输入口,数据端口
	temp_status=PORTB;
	PORTA|=(1<<CS1);							//取消片选
	return temp_status;
}
//***************************************************************************//
//程序:F_LCD_ON_OFF(unsigned int SetCom)
//描述:液晶开关函数  C语言调用 
//参数:unsigned int SetCom		SetCom=0:LCD Off  SetCom!=0:LCD On
// 声明:	手心	20070117	AVRGCC
//***************************************************************************//
void F_LCD_ONOFF(unsigned int SetCom)
{
	if(SetCom)							//ON LCD
		F_SPLC501_Write_Com(M_LCD_ON);
	else								//OFF LCD
		F_SPLC501_Write_Com(M_LCD_OFF);
}

//***************************************************************************//
//程序:LCD501_Init(unsigned int InitialData)
//描述:液晶显示初始化函数  C语言调用 
//参数:unsigned int InitialData	初始化显示的字
// 声明:	手心	20070117	AVRGCC
//***************************************************************************//
void LCD501_Init(unsigned int InitialData)
{
	unsigned int i,j;
	F_SPLC501_Initial_IO();						//Initial LCD IO
	F_SPLC501_Write_Com(M_LCD_ON);				//LCD On
	F_SPLC501_Write_Com(M_LCD_POWER_ALL);		//设置上电控制模式
	
	F_SPLC501_Write_Com(M_LCD_ELE_VOL);			//电量设置模式(显示亮度)
	F_SPLC501_Write_Com(0x12);					//指令数据0x00~0x3f
	
	F_SPLC501_Write_Com(M_LCD_VDD_SET);			//V5内部电压调节电阻设置
	F_SPLC501_Write_Com(M_LCD_VDD);				//LCD偏压设置,V3时选
	
	F_SPLC501_Write_Com(M_LCD_COM_NOR);			//Com 扫描方式设置
	F_SPLC501_Write_Com(M_LCD_SEG_REV);			//Segment方向选择
	F_SPLC501_Write_Com(M_LCD_ALL_LOW);			//全屏点亮/变暗指令
	F_SPLC501_Write_Com(M_LCD_ALL_NOR);			//正向反向显示控制指令

	F_SPLC501_Write_Com(M_LCD_STATIC_OFF);		//关闭静态指示器
	F_SPLC501_Write_Com(0x00);					//指令数据
	
	F_SPLC501_Write_Com(M_LCD_BEGIN_LINE+0);	//设置显示起始行对应RAM
	for(i=0;i<8;i++)							//往LCD中填充初始化的显示数据
	{
		F_SPLC501_Write_Com(M_LCD_COL_PAGE+i);
		F_SPLC501_Write_Com(M_LCD_COL_LINE_LOW);
		F_SPLC501_Write_Com(M_LCD_COL_LINE_HIG);
		for(j=0;j<128;j++)
		{
			switch(i)
			{
			case 1:
					F_SPLC501_Write_Data(Welcome_word[j]);//Welcome_word
					break;
			case 2:
					F_SPLC501_Write_Data((Welcome_word[j]>>8));//Welcome_word
					break;
			case 4:
					if(j>=40 && j<88)
						F_SPLC501_Write_Data(Welcome_word[128+j-40]);//Welcome_word
					else
						F_SPLC501_Write_Data(InitialData);
					break;
			case 5:		
					if(j>=40 && j<88)
						F_SPLC501_Write_Data((Welcome_word[128+j-40]>>8));//Welcome_word
					else
						F_SPLC501_Write_Data(InitialData);
					break;
			default:
					F_SPLC501_Write_Data(InitialData);
					break;
			}
		}
	}
	F_SPLC501_Write_Com(0xee);
	CurPaintMode = 0;
	CurPowerMode = 1;			//now is normal mode
	CurLCDSet = 8;
	CurScroll = 0;
	CurScrMode = 1;
	CurASCIIFont = 1;
}
//======================================================
// 程序:	void LCD501_Power(unsigned int ModeCode)
// 描述:	SPLC501电源管理,进入参数指定的模式,而当LCD在SLEEP和STDBY模式下时,
//			调用该函数会使LCD唤醒
// 参数:		ModeCode - 可以是下列参数之一:
//				1	PWR_ON: 	正常工作模式
//				2	PWR_SLEEP:	睡眠模式,屏幕不显示,但内容在唤醒后仍保留
//				3	PWR_STDBY: 待机模式,比SLEEP省电,但显示内容会丢失
//				0	PWR_OFF:	关闭电源
// 声明:	手心	20070117	AVRGCC
//======================================================
void LCD501_Power(unsigned int ModeCode)
{
	if(CurPowerMode == PWR_SLEEP)
	{
		F_SPLC501_Write_Com(M_LCD_ALL_LOW);
		F_SPLC501_Write_Com(M_LCD_STATIC_ON);
		F_SPLC501_Write_Com(0x0003);
		CurPowerMode = 1;
	}
	else if(CurPowerMode == PWR_STDBY)
	{
		F_SPLC501_Write_Com(M_LCD_ON);
		F_SPLC501_Write_Com(M_LCD_ALL_LOW);
		CurPowerMode = 1;
	}
	else{
		switch(ModeCode)
		{
			case PWR_ON:
				F_SPLC501_Write_Com(M_LCD_ON);
				break;
			case PWR_SLEEP:
				F_SPLC501_Write_Com(M_LCD_STATIC_OFF);
				F_SPLC501_Write_Com(0x0000);
				F_SPLC501_Write_Com(M_LCD_OFF);
				F_SPLC501_Write_Com(M_LCD_ALL_LIGNT);
				break;
			case PWR_STDBY:
				F_SPLC501_Write_Com(M_LCD_STATIC_ON);
				F_SPLC501_Write_Com(0x0003);
				F_SPLC501_Write_Com(M_LCD_OFF);
				F_SPLC501_Write_Com(M_LCD_ALL_LIGNT);
				break;
			default://POW_OFF
				F_SPLC501_Write_Com(M_LCD_OFF);
				break;
		}//
		CurPowerMode = ModeCode;
	}
}
//***************************************************************************//

⌨️ 快捷键说明

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