標(biāo)題: 超聲波液晶顯示 [打印本頁]

作者: 田鵬    時(shí)間: 2017-7-2 08:37
標(biāo)題: 超聲波液晶顯示
  1. #include <reg52.H>
  2. #include <intrins.H>
  3. #include <math.H>

  4. #define uchar unsigned char
  5.   #define uint unsigned int

  6. sbit dula = P2^6;//數(shù)碼管鎖存器關(guān)閉
  7. sbit wela = P2^7;

  8. sbit RS = P3^5;   顯示屏打開
  9. sbit LCDEN = P3^4;

  10. void delayUs()
  11. {
  12.     _nop_();
  13. }

  14. void delayMs(uint a)
  15. {
  16.     uint i, j;
  17.     for(i = a; i > 0; i--)
  18.         for(j = 100; j > 0; j--);
  19. }


  20. void writeComm(uchar comm)
  21. {
  22.      RS = 0;   
  23.     P0 = comm;
  24.     LCDEN = 1;
  25.      delayUs();
  26.     LCDEN = 0;
  27.     delayMs(1);
  28. }

  29. //寫數(shù)據(jù):RS=1, RW=0;
  30. void writeData(uchar dat)
  31. {
  32.      RS = 1;
  33.      P0 = dat;
  34.      LCDEN = 1;
  35.     delayUs();
  36.     LCDEN = 0;
  37.     delayMs(1);
  38. }


  39. void init()
  40. {
  41.    
  42.      dula = wela = 0;
  43.     writeComm(0x38);   //顯示模式
  44.    writeComm(0x0c);//光標(biāo)
  45.     writeComm(0x06);  //光標(biāo)位置,科左移
  46.     writeComm(0x01); //清屏
  47. }

  48. void writeString(uchar * str, uchar length)
  49. {
  50.      uchar i;
  51.     for(i = 0; i < length; i++)
  52.     {
  53.          writeData(str[i]);
  54.      }
  55. }
  56. void main()
  57. {
  58.     uchar table[] = " xianzaiwendu:";
  59.    
  60.     init();

  61.     writeComm(0x80);
  62.     writeString(table, 16);
  63.     while(1)
  64.     {
  65.         
  66.     }
復(fù)制代碼



作者: 黑泡泡    時(shí)間: 2021-5-18 12:51
程序有問題
作者: 51hei團(tuán)團(tuán)    時(shí)間: 2021-5-18 18:08
黑泡泡 發(fā)表于 2021-5-18 12:51
程序有問題

我在搜索框輸入"超聲波 1602"幫你搜索到了幾個(gè)能成功仿真的工程http://www.torrancerestoration.com/bbs/dpj-189056-1.html




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1