欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1936|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

51單片機(jī)驅(qū)動(dòng)TM1637 固定地址 程序能優(yōu)化嗎?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1010435 發(fā)表于 2022-8-29 09:34 | 只看該作者 回帖獎(jiǎng)勵(lì) |正序?yàn)g覽 |閱讀模式
我是個(gè)單片機(jī)愛(ài)好者,喜歡驅(qū)動(dòng)各類數(shù)碼管,網(wǎng)上TM1637都是地址+1模式,我改了個(gè)固定地址模式,請(qǐng)問(wèn)我這種代碼能優(yōu)化簡(jiǎn)寫(xiě)嗎?這個(gè)代碼仿真通過(guò)了。不是很懂C語(yǔ)言。
  1. void SmgDisplay(unsigned char Wei,i) //寫(xiě)顯示寄存器
  2. {

  3. I2CStart();
  4. I2CWrByte(0x44); // 40H 地址自動(dòng)加 1 模式,44H 固定地址模式,本程序采用固定地址模式

  5. I2CStop();
  6. I2CStart();
  7.         if(Wei==1)
  8.         {
  9.          I2CWrByte(0xc0); //設(shè)置 地址,
  10.          I2CWrByte(Num[i]); //送數(shù)據(jù)
  11.          I2CStop();
  12.          I2CStart();
  13.          I2CWrByte(0xc1); //設(shè)置 地址,
  14.          I2CWrByte(Numoff); //送數(shù)據(jù)
  15.          I2CStop();
  16.          I2CStart();
  17.          I2CWrByte(0xc2); //設(shè)置 地址,
  18.          I2CWrByte(Numoff); //送數(shù)據(jù)
  19.          I2CStop();
  20.          I2CStart();
  21.          I2CWrByte(0xc3); //設(shè)置 地址,
  22.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  23.          I2CStop();
  24.          I2CStart();
  25.          I2CWrByte(0xc4); //設(shè)置 地址,
  26.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  27.          I2CStop();
  28.          I2CStart();
  29.          I2CWrByte(0xc5); //設(shè)置 地址,
  30.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  31.          I2CStop();
  32.          I2CStart();       
  33.         }
  34.         if(Wei==2)
  35.         {
  36.          I2CWrByte(0xc0); //設(shè)置 地址,
  37.          I2CWrByte(Numoff); //送數(shù)據(jù)
  38.          I2CStop();
  39.          I2CStart();
  40.          I2CWrByte(0xc1); //設(shè)置 地址,
  41.          I2CWrByte(Num[i]); //送數(shù)據(jù)
  42.          I2CStop();
  43.          I2CStart();
  44.          I2CWrByte(0xc2); //設(shè)置 地址,
  45.          I2CWrByte(Numoff); //送數(shù)據(jù)
  46.          I2CStop();
  47.          I2CStart();
  48.          I2CWrByte(0xc3); //設(shè)置 地址,
  49.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  50.          I2CStop();
  51.          I2CStart();
  52.          I2CWrByte(0xc4); //設(shè)置 地址,
  53.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  54.          I2CStop();
  55.          I2CStart();
  56.          I2CWrByte(0xc5); //設(shè)置 地址,
  57.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  58.          I2CStop();
  59.          I2CStart();       
  60.         }
  61.         if(Wei==3)
  62.         {
  63.          I2CWrByte(0xc0); //設(shè)置 地址,
  64.          I2CWrByte(Numoff); //送數(shù)據(jù)
  65.          I2CStop();
  66.          I2CStart();
  67.          I2CWrByte(0xc1); //設(shè)置 地址,
  68.          I2CWrByte(Numoff); //送數(shù)據(jù)
  69.          I2CStop();
  70.          I2CStart();
  71.          I2CWrByte(0xc2); //設(shè)置 地址,
  72.          I2CWrByte(Num[i]); //送數(shù)據(jù)
  73.          I2CStop();
  74.          I2CStart();
  75.          I2CWrByte(0xc3); //設(shè)置 地址,
  76.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  77.          I2CStop();
  78.          I2CStart();
  79.          I2CWrByte(0xc4); //設(shè)置 地址,
  80.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  81.          I2CStop();
  82.          I2CStart();
  83.          I2CWrByte(0xc5); //設(shè)置 地址,
  84.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  85.          I2CStop();
  86.          I2CStart();       
  87.         }
  88.         if(Wei==4)
  89.         {
  90.          I2CWrByte(0xc0); //設(shè)置 地址,
  91.          I2CWrByte(Numoff); //送數(shù)據(jù)
  92.          I2CStop();
  93.          I2CStart();
  94.          I2CWrByte(0xc1); //設(shè)置 地址,
  95.          I2CWrByte(Numoff); //送數(shù)據(jù)
  96.          I2CStop();
  97.          I2CStart();
  98.          I2CWrByte(0xc2); //設(shè)置 地址,
  99.          I2CWrByte(Numoff); //送數(shù)據(jù)
  100.          I2CStop();
  101.          I2CStart();
  102.          I2CWrByte(0xc3); //設(shè)置 地址,
  103.          I2CWrByte(Num[i]); //送數(shù)據(jù)       
  104.          I2CStop();
  105.          I2CStart();
  106.          I2CWrByte(0xc4); //設(shè)置 地址,
  107.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  108.          I2CStop();
  109.          I2CStart();
  110.          I2CWrByte(0xc5); //設(shè)置 地址,
  111.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  112.          I2CStop();
  113.          I2CStart();       
  114.         }
  115.         if(Wei==5)
  116.         {
  117.          I2CWrByte(0xc0); //設(shè)置 地址,
  118.          I2CWrByte(Numoff); //送數(shù)據(jù)
  119.          I2CStop();
  120.          I2CStart();
  121.          I2CWrByte(0xc1); //設(shè)置 地址,
  122.          I2CWrByte(Numoff); //送數(shù)據(jù)
  123.          I2CStop();
  124.          I2CStart();
  125.          I2CWrByte(0xc2); //設(shè)置 地址,
  126.          I2CWrByte(Numoff); //送數(shù)據(jù)
  127.          I2CStop();
  128.          I2CStart();
  129.          I2CWrByte(0xc3); //設(shè)置 地址,
  130.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  131.          I2CStop();
  132.          I2CStart();
  133.          I2CWrByte(0xc4); //設(shè)置 地址,
  134.          I2CWrByte(Num[i]); //送數(shù)據(jù)       
  135.          I2CStop();
  136.          I2CStart();
  137.          I2CWrByte(0xc5); //設(shè)置 地址,
  138.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  139.          I2CStop();
  140.          I2CStart();       
  141.         }
  142.         if(Wei==6)
  143.         {
  144.          I2CWrByte(0xc0); //設(shè)置 地址,
  145.          I2CWrByte(Numoff); //送數(shù)據(jù)
  146.          I2CStop();
  147.          I2CStart();
  148.          I2CWrByte(0xc1); //設(shè)置 地址,
  149.          I2CWrByte(Numoff); //送數(shù)據(jù)
  150.          I2CStop();
  151.          I2CStart();
  152.          I2CWrByte(0xc2); //設(shè)置 地址,
  153.          I2CWrByte(Numoff); //送數(shù)據(jù)
  154.          I2CStop();
  155.          I2CStart();
  156.          I2CWrByte(0xc3); //設(shè)置 地址,
  157.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  158.          I2CStop();
  159.          I2CStart();
  160.          I2CWrByte(0xc4); //設(shè)置 地址,
  161.          I2CWrByte(Numoff); //送數(shù)據(jù)       
  162.          I2CStop();
  163.          I2CStart();
  164.          I2CWrByte(0xc5); //設(shè)置 地址,
  165.          I2CWrByte(Num[i]); //送數(shù)據(jù)       
  166.          I2CStop();
  167.          I2CStart();       
  168.         }       
  169. I2CWrByte(0x8f); //開(kāi)顯示 ,最大亮度

  170. I2CStop();
復(fù)制代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

地板
ID:1010435 發(fā)表于 2022-9-23 15:54 | 只看該作者
閑來(lái)無(wú)事,優(yōu)化了一下,現(xiàn)在好點(diǎn)了。

  1.         for(j=0;j<6;j++)
  2.         {
  3.                 if(Wei==j)
  4.                 {
  5.                  I2CWrByte(0xc0+j); //設(shè)置 地址,
  6.                  I2CWrByte(Num[i]); //送數(shù)據(jù)
  7.                  I2CStop();
  8.                  I2CStart();               
  9.                 }
  10.                 else
  11.                 {
  12.                  I2CWrByte(0xc0+j); //設(shè)置 地址,
  13.                  I2CWrByte(Numoff); //送數(shù)據(jù)
  14.                  I2CStop();
  15.                  I2CStart();                
  16.                 }

  17.         }
復(fù)制代碼
回復(fù)

使用道具 舉報(bào)

板凳
ID:624769 發(fā)表于 2022-9-8 00:07 | 只看該作者
要優(yōu)化的話……
第一步就是 改成 地址+1 模式。
你還想優(yōu)化么?
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:404160 發(fā)表于 2022-9-6 17:17 | 只看該作者
可以用do。。。while循環(huán)或for循環(huán)語(yǔ)句簡(jiǎn)化。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表