📄 1604.c
字号:
//==========================================================================================
//型号:TCL1604A-01 控制器:SPLC780D
//硬件接口:数据线位IOA的高八位,RW接IOB11,E接IOB12,RS接IOB13
//测试情况:已测试成功
//Made By Caixing 2008.04.17
//==========================================================================================
#include<spce061a.h>
#include<hardware.h>
#define RS_1() {*P_IOB_Data|=0x2000;}//rs B13
#define RS_0() {*P_IOB_Data&=0xdfff;}//rs
#define RW_1() {*P_IOB_Data|=0x0800;}//rw B11
#define RW_0() {*P_IOB_Data&=0xf7ff;}//rw
#define E_1() {*P_IOB_Data|=0x1000;}//e B12
#define E_0() {*P_IOB_Data&=0xefff;}//e
//===========================================================================================
//语法格式:void LCD_delay(unsigned int i)
//实现功能:延时
//参数: unsigned int i
//返回值: 无
//Made By Caixing 2008.04.17
//===========================================================================================
void LCD_delay(unsigned int i)
{
while(i--) *P_Watchdog_Clear=0x0001;
}
//===========================================================================================
//语法格式:void waitforenable()
//实现功能:读忙
//参数: 无
//返回值: 无
//Made By Caixing 2008.04.17
//===========================================================================================
void waitforenable(void)//hen you ke neng ba IOA15 she ji wei shu ru
{
*P_IOA_Data&=0xffff;//初始化BF
*P_IOA_Dir&=0x00ff;//ff
RS_0();//when RS set low,it means read Busy flag - Address Counter (for read).
RW_1();//在读的情况下读出BF信号
E_0();
E_1();
while(*P_IOA_Data&0x8000)*P_Watchdog_Clear=0x0001;//check BF signal
E_0();
}
//===========================================================================================
//语法格式:void Write_Command(unsigned char command,unsigned int attribc)
//实现功能:向1604写命令
//参数: unsigned char command,unsigned int attribc
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void Write_Command(unsigned char command,unsigned int attribc)
{
if(attribc) waitforenable();
*P_IOA_Dir=0xffff;//注意要得放在读忙的后面,因为读忙时把端口设置为输入
E_0();
RS_0();
RW_0();//写数据或写指令取决于RS
*P_IOA_Data=(command<<8)&0xff00;//因为数据线接高八位,所以把传的数据向左移八位
E_1();
LCD_delay(10);
E_0()
}
//===========================================================================================
//语法格式:void Write_Data(unsigned char data)
//实现功能:向1604写数据
//参数: unsigned char data
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void Write_Data(unsigned char data)
{
waitforenable();
*P_IOA_Dir=0xffff;//注意要得放在读忙的后面,因为读忙时把端口设置为输入
E_0();
RS_1();
RW_0();
*P_IOA_Data=(data<<8)&0xff00;//因为数据线接高八位,所以把传的数据向左移八位
E_1();
LCD_delay(10);
E_0();
}
//===========================================================================================
//语法格式:void LCD_Rest(void)
//实现功能:LCD初始化
//参数: 无
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void LCD_Rest(void)
{
*P_IOA_Data&=0x00ff;//初始化端口
Write_Command(0x38,0);//Function set
LCD_delay(300);
Write_Command(0x38,0);//Function set
LCD_delay(100);
Write_Command(0x38,0); //三次显示模式, 不检测忙
LCD_delay(100);
Write_Command(0x38,1);//16*4显示,5*8点阵,8位数据接口,需要检测忙,//Function set
Write_Command(0x08,1);//关闭显示Display ON/OFF control
Write_Command(0x01,1);//clear显示
Write_Command(0x06,1);//指针和光标+1,不滚屏,//Entry mode set
Write_Command(0x0c,1);//开显示,不显示光标,不闪烁//Display ON/OFF control
}
//===========================================================================================
//语法格式:void LcmClear(void)
//实现功能:清除显示
//参数: 无
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void LcmClear(void)
{
Write_Command(0x01,1); //clear display
}
//===========================================================================================
//语法格式:void locatexy(unsigned char posx,unsigned char posy)
//实现功能:定位显示地址
//参数: unsigned char posx,unsigned char pos
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void locatexy(unsigned char posx,unsigned char posy)
{
unsigned char DDaddres;
posy&=0x03;
DDaddres=posx&0x0f; //限制4行,每行可显示16个字符
switch(posy)
{
case 0:
DDaddres+= 0x00; //0x00 - 0x0f
break;
case 1:
DDaddres+= 0x40; //0x40 - 0x4f
break;
case 2:
DDaddres+= 0x10; //0x10 - 0x1f
break;
case 3:
DDaddres+= 0x50; //0x50 - 0x5f
break;
default :
break;
}
DDaddres|=0x80;//送显示地址的时候最高位DB7为1
Write_Command(DDaddres,1);//Set display data RAM address
}
//===========================================================================================
//语法格式:void displayonechar(unsigned char x,unsigned char y,unsigned char data)
//实现功能:显示一个字符
//参数: unsigned char x,unsigned char y,unsigned char data
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void displayonechar(unsigned char x,unsigned char y,unsigned char data)
{
locatexy(x,y);//显示的地址
Write_Data(data);//Write data to character generator RAM or display data RAM
}
//===========================================================================================
//语法格式:void displaystring(unsigned char x,unsigned char y,unsigned *data
//实现功能:显示一串数组
//参数: unsigned char x,unsigned char y,unsigned *data
//返回值: 无
//Made By Caixing 2008.04.17
//==========================================================================================
void displaystring(unsigned char x,unsigned char y,unsigned *data)//显示一串数组
{
unsigned char i=0,j;
while(data[i]!='\0'){i++;}
for(j=0;j<i;j++)
{
displayonechar( x,y,data[j]);
x++;
if(x>15){x=0;y++;}
if(y>4){y=0;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -