新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 1602控制forMSP430

        1602控制forMSP430

        作者: 時間:2016-11-27 來源:網絡 收藏
      1. /*************************************************************************
      2. //名稱:LocateXY
      3. //參數:unsignedcharx,unsignedchary
      4. //返回值:無
      5. //功能:確定1602寫入數據的位置,X為行坐標,Y為列坐標(都從0開始)
      6. *************************************************************************/
      7. voidLocateXY(ucharx,uchary)
      8. {
      9. uchartemp;
      10. temp=x&0x0f;
      11. y&=0x01;
      12. if(y)temp|=0x40;//如果在第2行
      13. temp|=0x80;
      14. WriteCommand(temp,1);
      15. }
      16. /*************************************************************************
      17. //名稱:LcdInit
      18. //參數:無
      19. //返回值:無
      20. //功能:1602初始化
      21. *************************************************************************/
      22. voidLcdInit(void)
      23. {
      24. CtrlDir|=0x07;//控制線端口設為輸出狀態
      25. DataDir|=0xFF;//數據端口設為輸出狀態
      26. WriteCommand(0x38,0);//規定的復位操作
      27. Delay5ms();
      28. WriteCommand(0x38,0);
      29. Delay5ms();
      30. WriteCommand(0x38,0);
      31. Delay5ms();
      32. WriteCommand(0x38,1);//顯示模式設置
      33. WriteCommand(0x08,1);//顯示關閉
      34. WriteCommand(0x01,1);//顯示清屏
      35. WriteCommand(0x06,1);//寫字符時整體不移動
      36. WriteCommand(0x0c,1);//顯示開,不開游標,不閃爍
      37. }
      38. /*************************************************************************
      39. //名稱:WriteStr
      40. //參數:待寫入數組的首地址,unsignedintn,unsignedcharx,unsignedchary
      41. //返回值:無
      42. //功能:在給定位置顯示一個數組,長度為l
      43. *************************************************************************/
      44. voidWriteStr(uchar*a,uintl,ucharx,uchary)
      45. {
      46. uchari;
      47. LocateXY(x,y);
      48. for(i=0;i
      49. WriteData(a[i]);
      50. }
      51. /*************************************************************************
      52. //名稱:WriteNum
      53. //參數:待寫入數字,unsignedcharx,unsignedchary
      54. //返回值:無
      55. //功能:在給定位置顯示一個數字(不超過5位且小于65536)
      56. *************************************************************************/
      57. voidWriteNum(uintn,ucharx,uchary)
      58. {
      59. ucharfive,four,three,two,one;
      60. LocateXY(x,y);
      61. if((n>=10000)&&(n<=65535))
      62. {
      63. five=n/10000;
      64. four=(n%10000)/1000;
      65. three=((n-five*10000)%1000)/100;
      66. two=((n-five*10000)%1000-three*100)/10;
      67. one=((n-five*10000)%1000-three*100)%10;
      68. WriteData(NUM[five]);
      69. WriteData(NUM[four]);
      70. WriteData(NUM[three]);
      71. WriteData(NUM[two]);
      72. WriteData(NUM[one]);
      73. }
      74. if((n>=1000)&&(n<=9999))
      75. {
      76. four=n/1000;
      77. three=(n%1000)/100;
      78. two=(n%1000-three*100)/10;
      79. one=(n%1000-three*100)%10;
      80. WriteData(NUM[four]);
      81. WriteData(NUM[three]);
      82. WriteData(NUM[two]);
      83. WriteData(NUM[one]);
      84. }
      85. if((n>=100)&&(n<=999))
      86. {
      87. three=n/100;
      88. two=(n-three*100)/10;
      89. one=(n-three*100)%10;
      90. WriteData(NUM[three]);
      91. WriteData(NUM[two]);
      92. WriteData(NUM[one]);
      93. }
      94. if((n>=10)&&(n<=99))
      95. {
      96. two=n/10;
      97. one=n%10;
      98. WriteData(NUM[two]);
      99. WriteData(NUM[one]);
      100. }
      101. if((n>0)&&(n<=9))WriteData(NUM[n]);
      102. }
      103. /*************************************************************************
      104. //名稱:WriteFloat
      105. //參數:待寫入浮點數,unsignedcharx,unsignedchary
      106. //返回值:無
      107. //功能:在給定位置顯示一個浮點數(整數部分和小數部分都不超過兩位)
      108. *************************************************************************/
      109. voidWriteFloat(floatn,ucharx,uchary)
      110. {
      111. uintInteger,Decimal;//Integer用于存放整數部分,Decimal用于存放小數部分
      112. Integer=(uint)(n/1);
      113. Decimal=(uint)(n*100-Integer*100);
      114. WriteNum(Integer,x,y);
      115. WriteData(NUM[10]);
      116. WriteNum(Decimal,x+3,y);
      117. }


      118. 上一頁 1 2 下一頁

        關鍵詞: 1602控制MSP43

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 娄底市| 锦屏县| 施秉县| 乐都县| 永登县| 新乡县| 阳城县| 航空| 黄山市| 水富县| 伊春市| 得荣县| 阿合奇县| 平江县| 天峨县| 广东省| 右玉县| 鄂尔多斯市| 深水埗区| 英超| 临夏市| 贵南县| 揭西县| 会昌县| 方山县| 纳雍县| 长乐市| 应用必备| 奉节县| 九台市| 格尔木市| 新乡市| 墨竹工卡县| 淮滨县| 浑源县| 衡东县| 贡觉县| 德清县| 炉霍县| 肥乡县| 宁德市|