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

📄 lcd.c

📁 全国电子设计大赛获奖作品 悬挂运动控制系统
💻 C
字号:
/***********************************
project: 凌阳SPCE61A单片机应用例程
item:液晶显示
version: V1.0

Description:
    液晶基本操作,显示一行

Author: 江苏大学电气信息工程学院


***********************************/
#include "spce061v004.h"
#include "main.h"

int De;

//=========================================================================================
//写一位
//=========================================================================================
void WriteBit(char B)
{
	int D;	

	D=*P_IOB_Buffer&0xfffd;		//SDA输出数据
	if(B!=0)
		*P_IOB_Data=D|0x0002;
	else
		*P_IOB_Data=D&0xfffd;
	
	D=*P_IOB_Buffer&0xfffe;		//SCK脉冲
	*P_IOB_Data=D|0x0001;
	De=8;
	while(De--);
	*P_IOB_Data=D&0xfffe;
}	

//=========================================================================================
//写一个字节
//=========================================================================================
void WriteByte(char B,char I)
{
	int D,i;
	D=*P_IOB_Buffer&0xffbf;
	*P_IOB_Data=D|0x0040;		//片选有效
	
	for(i=1;i<6;i++)
		WriteBit(1);			//5个空脉冲,数据为1 synchronizing bitstring
	
	WriteBit(0);				//RW=0
	De=5;
	while(De--);
	WriteBit(I);				//写指令还是数据?
	De=5;
	while(De--);
	WriteBit(0);				//写一个0
	De=5;
	while(De--);
	
	WriteBit(B&0x0080);//写第7位
	De=5;
	while(De--);
	WriteBit(B&0x0040);//写第6位
	De=5;
	while(De--);
	WriteBit(B&0x0020);//写第5位
	De=5;
	while(De--);
	WriteBit(B&0x0010);//写第4位
	De=5;
	while(De--);

	for(i=1;i<5;i++)
		WriteBit(0);			//4个空脉冲,数据为0
	De=5;
	while(De--);

	WriteBit(B&0x0008);//写第3位
	De=5;
	while(De--);
	WriteBit(B&0x0004);//写第2位
	De=5;
	while(De--);
	WriteBit(B&0x0002);//写第1位
	De=5;
	while(De--);
	WriteBit(B&0x0001);//写第0位
	De=5;
	while(De--);

	for(i=1;i<5;i++)
		WriteBit(0);			//4个空脉冲,数据为0
	De=5;
	while(De--);
	
	D=*P_IOB_Buffer&0xffbf;
	*P_IOB_Data=D&0xffbf;		//片选有效
	
	*P_Watchdog_Clear=C_WDTCLR;
}

//=========================================================================================
//LCD初始化
//=========================================================================================
void LCDinit(void)
{
 	int D,i;

    i=3;while(i--);
    
    WriteByte(0x30,0);
	Delay(DELAYINTERNAL1);
    WriteByte(0x01,0);
	Delay(DELAYINTERNAL1);
    WriteByte(0x06,0);
	Delay(DELAYINTERNAL1);
    WriteByte(0x0c,0);
	Delay(DELAYINTERNAL1);
}

//=========================================================================================
//显示一行
//=========================================================================================

void LCDWriteLine(int Line,unsigned int HZCode[10])
{
	int i;
	switch (Line)
	{
		case 1:Line=0x80;break;
		case 2:Line=0x90;break;
		case 3:Line=0x88;break;
		case 4:Line=0x98;break;
	}
	WriteByte(Line,0);
	Delay(1000);
	for (i=0;i<8;i++)
	{
		WriteByte((HZCode[i]&0xff00)>>8,1);
		WriteByte(HZCode[i]&0x00ff,1);
	}
}

⌨️ 快捷键说明

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