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

📄 12864_driver.c.txt

📁 使用凌阳SPCE061A作为主控核
💻 TXT
字号:
////////////////////////////////////////////////
//液晶驱动程序
//液晶型号:12864
//使用SPCE061A连接方式:(串行)
//**\CS:IOB0,SID:IOB15,SCLK:IOB1**
//**PSB:GND(serial),/RST:VCC**
////////////////////////////////////////////////
#include "SPCE061A.h"

#define CS_1	0x0001//液晶各个控制端定义
#define SID_1	0x8000  
#define SCLK_1	0x0002

#define CS_H    *P_IOB_Data|=CS_1
#define CS_L    *P_IOB_Data&=(0xFFFF-CS_1)
#define SID_H   *P_IOB_Data|=SID_1
#define SID_L   *P_IOB_Data&=(0xFFFF-SID_1)
#define SCLK_H  *P_IOB_Data|=SCLK_1
#define SCLK_L  *P_IOB_Data&=(0xFFFF-SCLK_1)

#define Clear_Watchdog *P_Watchdog_Clear=0x0001

unsigned int Disp_Addr=0x0000;

////////////////////////////////////////////////
//function: delay
////////////////////////////////////////////////
void delay(unsigned int i)
{
	while(i--)
		Clear_Watchdog;
}

////////////////////////////////////////////////
//function: simulate the high and low level-
//according to the Send_Data
//input: the sent data
////////////////////////////////////////////////
void Send_Simulate(unsigned int Send_Data)
{
	if(Send_Data&0x0080)
		SID_H;
    else
       	SID_L;
    SCLK_H;
    delay(8);
    Clear_Watchdog;
    SCLK_L;
}

////////////////////////////////////////////////
//function: send data or command
//input: data or command and their marks- 
//individually
//mark=0:data
//mark=1:command
////////////////////////////////////////////////
void Serial_Send(unsigned int data,unsigned int mark)
{
    unsigned int i,j,Com_or_Data;
	
	switch(mark)
	{
		case 0:
			Com_or_Data=0x00fa;
			break;
		case 1:
			Com_or_Data=0x00f8;
			break;
	}
	CS_H;//enable
	
	for(i=1;i<=8;i++)//判断发送数据或指令
	{
		Send_Simulate(Com_or_Data);
		Com_or_Data<<=1;
		Clear_Watchdog;
	}
	
    for(j=0;j<2;j++)//发送
    {
    	for(i=4;i>=1;i--)
    	{	
    		Send_Simulate(data);
    		data<<=1;
    		Clear_Watchdog;
    	}
        for(i=4;i>=1;i--)
        {
            SID_L;
            SCLK_H;
            delay(8);
            SCLK_L;
            Clear_Watchdog;
         }
     }
     CS_L;//disable
 }

void Lcd_Initial()//LCD初始化
{
	Serial_Send(0x0030,1);//功能设置:基本指令集
	Serial_Send(0x0004,1);//点设定:显示字符/光标从左到右移位,DDRAM地址加1 
    Serial_Send(0x000c,1);//显示设定:开显示,不显示光标位置
    Serial_Send(0x0001,1);//清DDRAM
    Serial_Send(0x0002,1);//DDRAM地址归位
    Serial_Send(0x0080,1);//把显示地址设为0X80,即为第一行的首位
}

////////////////////////////////////////////////
//function: select where to display
//input: line and row
//output:Disp_Addr(the globle variant)
////////////////////////////////////////////////
void Position_Select(int line,int row)
{
	if(line==1)
		Disp_Addr=0x80+row-1;
	else if(line==2)
		Disp_Addr=0x90+row-1;
	else if(line==3)
		Disp_Addr=0x88+row-1;
	else
		Disp_Addr=0x98+row-1;
}

////////////////////////////////////////////////
//function: display it at the address given
//input: line, row and the string
////////////////////////////////////////////////
void Disp_String(int line,int row,int string)
{
	Position_Select(line,row);
	Serial_Send(Disp_Addr,1);
	Serial_Send(string,0);
}

////////////////////////////////////////////////
//function: display it at the address given
//input: line, row and the strings
////////////////////////////////////////////////
void Disp_Strs(int line,int row,char *strings)
{
	int i;
	Position_Select(line,row);	
	Serial_Send(Disp_Addr,1);
	for(i=0;*(strings+i)!='\0';i++)
		Serial_Send(*(strings+i),0);
}





⌨️ 快捷键说明

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