新闻中心

EEPW首页>嵌入式系统>设计应用> 1602控制forMSP430

1602控制forMSP430

作者: 时间:2016-11-27 来源:网络 收藏
  • /*************************************************************************
  • //名称:LocateXY
  • //参数:unsignedcharx,unsignedchary
  • //返回值:无
  • //功能:确定1602写入数据的位置,X为行坐标,Y为列坐标(都从0开始)
  • *************************************************************************/
  • voidLocateXY(ucharx,uchary)
  • {
  • uchartemp;
  • temp=x&0x0f;
  • y&=0x01;
  • if(y)temp|=0x40;//如果在第2行
  • temp|=0x80;
  • WriteCommand(temp,1);
  • }
  • /*************************************************************************
  • //名称:LcdInit
  • //参数:无
  • //返回值:无
  • //功能:1602初始化
  • *************************************************************************/
  • voidLcdInit(void)
  • {
  • CtrlDir|=0x07;//控制线端口设为输出状态
  • DataDir|=0xFF;//数据端口设为输出状态
  • WriteCommand(0x38,0);//规定的复位操作
  • Delay5ms();
  • WriteCommand(0x38,0);
  • Delay5ms();
  • WriteCommand(0x38,0);
  • Delay5ms();
  • WriteCommand(0x38,1);//显示模式设置
  • WriteCommand(0x08,1);//显示关闭
  • WriteCommand(0x01,1);//显示清屏
  • WriteCommand(0x06,1);//写字符时整体不移动
  • WriteCommand(0x0c,1);//显示开,不开游标,不闪烁
  • }
  • /*************************************************************************
  • //名称:WriteStr
  • //参数:待写入数组的首地址,unsignedintn,unsignedcharx,unsignedchary
  • //返回值:无
  • //功能:在给定位置显示一个数组,长度为l
  • *************************************************************************/
  • voidWriteStr(uchar*a,uintl,ucharx,uchary)
  • {
  • uchari;
  • LocateXY(x,y);
  • for(i=0;i
  • WriteData(a[i]);
  • }
  • /*************************************************************************
  • //名称:WriteNum
  • //参数:待写入数字,unsignedcharx,unsignedchary
  • //返回值:无
  • //功能:在给定位置显示一个数字(不超过5位且小于65536)
  • *************************************************************************/
  • voidWriteNum(uintn,ucharx,uchary)
  • {
  • ucharfive,four,three,two,one;
  • LocateXY(x,y);
  • if((n>=10000)&&(n<=65535))
  • {
  • five=n/10000;
  • four=(n%10000)/1000;
  • three=((n-five*10000)%1000)/100;
  • two=((n-five*10000)%1000-three*100)/10;
  • one=((n-five*10000)%1000-three*100)%10;
  • WriteData(NUM[five]);
  • WriteData(NUM[four]);
  • WriteData(NUM[three]);
  • WriteData(NUM[two]);
  • WriteData(NUM[one]);
  • }
  • if((n>=1000)&&(n<=9999))
  • {
  • four=n/1000;
  • three=(n%1000)/100;
  • two=(n%1000-three*100)/10;
  • one=(n%1000-three*100)%10;
  • WriteData(NUM[four]);
  • WriteData(NUM[three]);
  • WriteData(NUM[two]);
  • WriteData(NUM[one]);
  • }
  • if((n>=100)&&(n<=999))
  • {
  • three=n/100;
  • two=(n-three*100)/10;
  • one=(n-three*100)%10;
  • WriteData(NUM[three]);
  • WriteData(NUM[two]);
  • WriteData(NUM[one]);
  • }
  • if((n>=10)&&(n<=99))
  • {
  • two=n/10;
  • one=n%10;
  • WriteData(NUM[two]);
  • WriteData(NUM[one]);
  • }
  • if((n>0)&&(n<=9))WriteData(NUM[n]);
  • }
  • /*************************************************************************
  • //名称:WriteFloat
  • //参数:待写入浮点数,unsignedcharx,unsignedchary
  • //返回值:无
  • //功能:在给定位置显示一个浮点数(整数部分和小数部分都不超过两位)
  • *************************************************************************/
  • voidWriteFloat(floatn,ucharx,uchary)
  • {
  • uintInteger,Decimal;//Integer用于存放整数部分,Decimal用于存放小数部分
  • Integer=(uint)(n/1);
  • Decimal=(uint)(n*100-Integer*100);
  • WriteNum(Integer,x,y);
  • WriteData(NUM[10]);
  • WriteNum(Decimal,x+3,y);
  • }


  • 上一页 1 2 下一页

    关键词:1602控制MSP43

    评论


    相关推荐

    技术专区

    关闭