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

📄 1602.txt

📁 1602主程序,使用msp430驱动荡不安602
💻 TXT
字号:
#include <msp430x14x.h>
#include "cry1602.h"
tyedef unsigned char uchar;
tyedef unsigned int uint;

/****************宏定义******************************/
#define DataDir   P4DIR
#define Dataport  P4OUT
#define busy      0x80
#define CtrlDir   P3DIR
#define CLR_RS P3OUT&=~BITO;     //RS = P3.0
#define SET_RS P3OUT|=BITO;     
#define CLR_RW P3OUT&=~BIT1;     //RW = P3.1
#define SET_RW P3OUT|=BIT1;     
#define CLR_EN P3OUT&=~BIT2;     //EN = P3.2
#define SET_EN P3OUT|=BIT2;  

/*******************************函数名Dispstr*********************************8/
功能:让液晶从某个位置起连续显示一个字符串
参数:X--位置的列坐标
     Y--位置的行坐标    
     prt--指向字条款串存放位置的指针
*************************************************************/
void dispstr(uchar x,uchar y,uchar *prt)
{
	uchar *temp;
	uchar i,n=0;
 	temp = ptr;
	while(*ptr++ != '\0')  n++     //计算字符串有效字符的个数

	{
	disp1char(x++,y,temp[i]);
	if(x==0x0f)
		{
		x = 0;
		y ^= 1;
		}
	}
}

/******************************************************8
函数名称:LocateXY
功能:向液晶输入显示安符位置的坐标信息
参数:X--位置的列坐标
     Y--位置的行坐标
返回值:无
******************************************/
void locarexy(uchar x,uchar y)
{
	uchar temp;
	y &= 0x01;
	if(y)  temp |= 0x40;  //如果在第2行
	temp |= 0x80;

	LcdwriteCimmand(temp,1);
}
/******************************************************
函数名称:Disp1Char
功能:在某个位置上显示一个字符
参数:X--位置的列坐标
     Y--位置的行坐标
     data--显示的字符数据
返回值:无
******************************************/
void Disp1char(uchar x,uchar y,uchar data)
{
	LocateXY( x, y);
	LcdWriteData( data);
}
/****************************************
函数名称:LcdReset
功能:对台贸1602液晶模块进行复位操作
参数:无
返回值:无
******************************************/
void LcdReset(vodi)
{
	ctrldir |= 0x07;               //控制线端口设为输出状态
	Datadir = 0xff;                //数据端口设为输出状态
	
	LcdWriteCommand(0x38, 0);      //规定的复位操作
	Delay5ms();
	LcdWriteCommand(0x38, 0);
	Delay5ms();
	LcdWriteCommand(0x38, 0);
	Delay5ms();


 	LcdWriteCommand(0x38, 1);             //显示模式设置
	LcdWriteCommand(0x08, 1);		//显示关闭
	LcdWriteCommand(0x01, 1);		//显示清屏
	LcdWriteCommand(0x06, 1);		//写字符时整体不移动
	LcdWriteCommand(0x06, 1);		//显示开,不开游标,不闪烁

}

/****************************************
函数名称:LcdWriteCommand
功能:向液晶模块写入命令
参数:cmd--命令
     chk--是不判忙的标志,1:判忙,2:不判
返回值:无
******************************************/
void LcdWriteCommane(uchar cmd,uchar chk)
{
	if (chk) WaitForEnable();		//检测忙信号?
	
	CLR_RS;
	CLR_RW;
	_NOP();
	CLR_EN;
}

/****************************************
函数名称:LcdWriteData
功能:向液晶显示的当前地址写入数据
参数:data--显示字符数据
返回值:无
******************************************/
void LcdwriteData(uchar data)
{
	waitForEnable();			//等待液晶不忙
	
	SET_RS;
	CLR_RW;
	_NOP();
	
	DataProt = data;			//将显示数据写入数据端口
	_NOP();

	SET_EN;					//产生使能脉冲信号
	_NOP();
	_NOP();
	CLR_EN;
}
/****************************************
函数名称:WaitForEnable
功能:等待遇602液晶完成内部操作
参数:无
返回值:无
******************************************/
void WaitForEnable(void)
{
	p4DIR &= 0x00;		//将P4口切换为输和状态

	
	CLR_RS;	
	SET_RW				
	_NOP();
	_NOP();
	SET_EN;
	_NOP();
	_NOP();

	while((P4IN & Busy)!=0);	//检测忙标志
	
	CLR_EN;

	P4DIR |= 0xff;			//将P4口切换为输出状态
	
}

/****************************************
函数名称:Delay5ms(void)
功能:延时约5ms
参数:无
返回值:无
******************************************/
void Delay5ms(void)
{
	uint i= 40000
	while(i !=0)
	{
	i--;
	}
}

⌨️ 快捷键说明

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