1602控制forMSP430
- /*****************************************************************
- //文件名:1602.h
- //描述:该头文件定义与1602有关的各种接口、函数,适用于MSP430F149
- //编写人:小邪@清水
- //版本号:1.00
- *****************************************************************/
- #include
- #include"1602.h"
- #defineucharunsignedchar
- #defineuintunsignedint
- ucharNUM[]={"0123456789."};
- /*****************************************************************
- //关于1602的一些宏定义
- //注意:除第三个外都要根据实际使用IO口更改
- *****************************************************************/
- #defineDataDirP4DIR
- #defineDataPortP4OUT
- #defineBusy0x80
- #defineCtrlDirP3DIR
- #defineCLR_RSP3OUT&=~BIT0;//RS=P3.0
- #defineSET_RSP3OUT|=BIT0;
- #defineCLR_RWP3OUT&=~BIT1;//RW=P3.1
- #defineSET_RWP3OUT|=BIT1;
- #defineCLR_ENP3OUT&=~BIT2;//EN=P3.2
- #defineSET_ENP3OUT|=BIT2;
- /*************************************************************************
- //名称:delay
- //参数:无
- //返回值:无
- //功能:延时5ms的时间
- *************************************************************************/
- voidDelay5ms(void)
- {
- uinti=40000;
- while(i!=0)
- {
- i--;
- }
- }
- /*************************************************************************
- //名称:WaitForEnable
- //参数:无
- //返回值:无
- //功能:等待直到1602完成当前操作
- *************************************************************************/
- voidWaitForEnable(void)
- {
- P4DIR&=0x00;//将P4口切换为输入状态
- CLR_RS;
- SET_RW;
- _NOP();
- SET_EN;
- _NOP();
- _NOP();
- while((P4IN&Busy)!=0);//检测忙标志
- CLR_EN;
- P4DIR|=0xFF;//将P4口切换为输出状态
- }
- /*************************************************************************
- //名称:WriteCommand
- //参数:cmd--命令,chk--是否判忙的标志,1:判忙,0:不判
- //返回值:无
- //功能:向1602写指令
- *************************************************************************/
- voidWriteCommand(ucharcmd,ucharchk)
- {
- if(chk)WaitForEnable();//检测忙信号
- CLR_RS;
- CLR_RW;
- _NOP();
- DataPort=cmd;//将命令字写入数据端口
- _NOP();
- SET_EN;//产生使能脉冲信号
- _NOP();
- _NOP();
- CLR_EN;
- }
- /*************************************************************************
- //名称:WriteData
- //参数:unsignedcharData
- //返回值:无
- //功能:向1602写入数据
- *************************************************************************/
- voidWriteData(uchardata)
- {
- WaitForEnable();//等待液晶不忙
- SET_RS;
- CLR_RW;
- _NOP();
- DataPort=data;//将显示数据写入数据端口
- _NOP();
- SET_EN;//产生使能脉冲信号
- _NOP();
- _NOP();
- CLR_EN;
- }
-
关键词:
1602控制MSP43
评论