新聞中心

1602控制forMSP430

作者: 時(shí)間:2016-11-27 來(lái)源:網(wǎng)絡(luò) 收藏
  • /*************************************************************************
  • //名稱(chēng):LocateXY
  • //參數(shù):unsignedcharx,unsignedchary
  • //返回值:無(wú)
  • //功能:確定1602寫(xiě)入數(shù)據(jù)的位置,X為行坐標(biāo),Y為列坐標(biāo)(都從0開(kāi)始)
  • *************************************************************************/
  • voidLocateXY(ucharx,uchary)
  • {
  • uchartemp;
  • temp=x&0x0f;
  • y&=0x01;
  • if(y)temp|=0x40;//如果在第2行
  • temp|=0x80;
  • WriteCommand(temp,1);
  • }
  • /*************************************************************************
  • //名稱(chēng):LcdInit
  • //參數(shù):無(wú)
  • //返回值:無(wú)
  • //功能:1602初始化
  • *************************************************************************/
  • voidLcdInit(void)
  • {
  • CtrlDir|=0x07;//控制線(xiàn)端口設(shè)為輸出狀態(tài)
  • DataDir|=0xFF;//數(shù)據(jù)端口設(shè)為輸出狀態(tài)
  • WriteCommand(0x38,0);//規(guī)定的復(fù)位操作
  • Delay5ms();
  • WriteCommand(0x38,0);
  • Delay5ms();
  • WriteCommand(0x38,0);
  • Delay5ms();
  • WriteCommand(0x38,1);//顯示模式設(shè)置
  • WriteCommand(0x08,1);//顯示關(guān)閉
  • WriteCommand(0x01,1);//顯示清屏
  • WriteCommand(0x06,1);//寫(xiě)字符時(shí)整體不移動(dòng)
  • WriteCommand(0x0c,1);//顯示開(kāi),不開(kāi)游標(biāo),不閃爍
  • }
  • /*************************************************************************
  • //名稱(chēng):WriteStr
  • //參數(shù):待寫(xiě)入數(shù)組的首地址,unsignedintn,unsignedcharx,unsignedchary
  • //返回值:無(wú)
  • //功能:在給定位置顯示一個(gè)數(shù)組,長(zhǎng)度為l
  • *************************************************************************/
  • voidWriteStr(uchar*a,uintl,ucharx,uchary)
  • {
  • uchari;
  • LocateXY(x,y);
  • for(i=0;i
  • WriteData(a[i]);
  • }
  • /*************************************************************************
  • //名稱(chēng):WriteNum
  • //參數(shù):待寫(xiě)入數(shù)字,unsignedcharx,unsignedchary
  • //返回值:無(wú)
  • //功能:在給定位置顯示一個(gè)數(shù)字(不超過(guò)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]);
  • }
  • /*************************************************************************
  • //名稱(chēng):WriteFloat
  • //參數(shù):待寫(xiě)入浮點(diǎn)數(shù),unsignedcharx,unsignedchary
  • //返回值:無(wú)
  • //功能:在給定位置顯示一個(gè)浮點(diǎn)數(shù)(整數(shù)部分和小數(shù)部分都不超過(guò)兩位)
  • *************************************************************************/
  • voidWriteFloat(floatn,ucharx,uchary)
  • {
  • uintInteger,Decimal;//Integer用于存放整數(shù)部分,Decimal用于存放小數(shù)部分
  • Integer=(uint)(n/1);
  • Decimal=(uint)(n*100-Integer*100);
  • WriteNum(Integer,x,y);
  • WriteData(NUM[10]);
  • WriteNum(Decimal,x+3,y);
  • }


  • 上一頁(yè) 1 2 下一頁(yè)

    關(guān)鍵詞: 1602控制MSP43

    評(píng)論


    相關(guān)推薦

    技術(shù)專(zhuān)區(qū)

    關(guān)閉