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

標題: STC15W204S單片機control ws2812B七彩流水燈程序(36燈) [打印本頁]

作者: yuren1984    時間: 2019-1-5 14:30
標題: STC15W204S單片機control ws2812B七彩流水燈程序(36燈)
STC15W204S-SOP16郔苤炵苀啣-v1.0萇繚芞.pdf (23.23 KB, 下載次數: 234) 上次程序更新后,STC15W204s控制ws2812B七彩流水燈,發現一個問題,就是keil C編譯時,燈數調整為37時,一直報錯說內存超出,希望高手能指點迷津,現在將36燈程序分享給大家:

單片機源碼:
  1. #include<stc15.h>
  2. #include"intrins.h"
  3. sbit WS2812 = P1^0;
  4. #define numLEDs 36  //燈的個數
  5. unsigned char buf_R[numLEDs] = {0};//顏色緩存
  6. unsigned char buf_G[numLEDs] = {0};
  7. unsigned char buf_B[numLEDs] = {0};
  8. void RGB_Set_Up();  //送0碼
  9. void RGB_Set_Down(); //送1碼
  10. void HAL_Delay(unsigned long t)
  11. {
  12.     unsigned int x,y;
  13.     for(x=114;x>0;x--)
  14.    for(y=t;y>0;y--);
  15. }
  16.    //復位延時
  17. void Delay50us()  [url=]//@22.1184MHz[/url]
  18. {
  19. unsigned char i, j;

  20. _nop_();
  21. _nop_();
  22. i = 2;
  23. j = 15;
  24. do
  25. {
  26.   while (--j);
  27. } while (--i);
  28. }
  29. //1碼,高電平850ns 低電平400ns 誤差正負150ns
  30. void RGB_Set_Up()
  31. {
  32.   WS2812 = 1;
  33.    //經過邏輯分析儀調試的的延時
  34.   _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
  35.    _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
  36.   WS2812 = 0;
  37. }
  38. //1碼,高電平400ns 低電平850ns 誤差正負150ns
  39. void RGB_Set_Down()
  40. {
  41.    WS2812 = 1;
  42.    //經過邏輯分析儀調試的的延時
  43.   _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();  
  44.   WS2812 = 0;
  45. }
  46. //發送24位數據
  47. void Send_2812_24bits(unsigned char G8,unsigned char R8,unsigned char B8)
  48. {
  49.      unsigned int n = 0;
  50.      //發送G8位
  51.     for(n=0;n<8;n++)
  52.     {
  53.         G8<<=n;
  54.      if(G8&0x80 == 0x80)
  55.      {
  56.         RGB_Set_Up();
  57.      }
  58.      else
  59.      {
  60.        RGB_Set_Down();
  61.      }
  62.     }
  63.     //發送R8位
  64.     for(n=0;n<8;n++)
  65.     {
  66.         R8<<=n;
  67.      if(R8&0x80 == 0x80)
  68.      {
  69.         RGB_Set_Up();
  70.      }
  71.      else
  72.      {
  73.        RGB_Set_Down();
  74.      }
  75.     }
  76.    //發送B8位
  77.       for(n=0;n<8;n++)
  78.     {
  79.         B8<<=n;
  80.      if(B8&0x80 == 0x80)
  81.      {
  82.         RGB_Set_Up();
  83.      }
  84.      else
  85.      {
  86.        RGB_Set_Down();
  87.       }
  88.     }
  89. }   
  90. //復位碼
  91. void RGB_Rst()
  92. {
  93.      WS2812 = 0;
  94.    Delay50us();
  95. }

  96. //顏色交換24位不拆分發
  97. void SetPixelColor(unsigned char num,unsigned long c)
  98. {
  99.     unsigned char i;
  100.        for(i=0;i<numLEDs;i++)
  101.     {
  102.        buf_R[num] = (unsigned char)(c>>16);
  103.      buf_G[num] = (unsigned char)(c>>8);
  104.      buf_B[num] = (unsigned char)(c);
  105.     }
  106.    for(i=0;i<numLEDs;i++)
  107.   {
  108.    Send_2812_24bits(buf_G[i],buf_R[i],buf_B[i]);
  109.   }
  110. }
  111. //復位
  112. void PixelUpdate()
  113. {
  114. RGB_Rst();
  115. }

  116. // Fill the dots one after the other with a color
  117. //用一種顏色填充這些圓點
  118. void colorWipe(unsigned long c, unsigned int wait)
  119. {
  120.   unsigned char i=0;
  121.   for( i=0; i<numLEDs; i++)
  122. {
  123.     SetPixelColor(i, c);
  124.     PixelUpdate();
  125.     HAL_Delay(wait*5);
  126.   }
  127. }
  128. //單燈流水
  129. void Watercolor(unsigned long c, unsigned int wait)
  130. {
  131.   unsigned char i=0;
  132.   for( i=0; i<numLEDs; i++)
  133. {
  134.     SetPixelColor(i, c);
  135.   PixelUpdate();
  136.     HAL_Delay(wait*5);
  137. SetPixelColor(i, 0);
  138.    PixelUpdate();
  139.     HAL_Delay(wait);
  140.   }
  141. }


  142. void main()
  143. {
  144.   while(1)
  145.   {   
  146.    
  147.       
  148.        colorWipe(0xff0000,1); //紅色全亮
  149.       HAL_Delay(10000);
  150.        colorWipe(0xff00,1);  //綠色全亮
  151.      HAL_Delay(10000);
  152.        colorWipe(0xff,1);//藍色全亮
  153.      HAL_Delay(10000);
  154.        colorWipe(0xffff00,1); //黃色全亮
  155.       HAL_Delay(10000);
  156.        colorWipe(0xffff,1); //青色全亮
  157.       HAL_Delay(10000);
  158.        colorWipe(0xff00ff,1); //紫色全亮
  159.       HAL_Delay(10000);
  160.        colorWipe(0xffffff,1); //白色全亮
  161.       HAL_Delay(10000);
  162.        colorWipe(0x00,1); //off
  163.       HAL_Delay(10000);
  164.         Watercolor(0xff0000, 100);//紅色單燈流水
  165.       HAL_Delay(1000);
  166.      Watercolor(0xff00, 100);//綠色單燈流水
  167.       HAL_Delay(1000);
  168.      Watercolor(0xff, 100);//藍色單燈流水
  169.       HAL_Delay(1000);
  170.      Watercolor(0xffff00, 100); //黃色單燈流水
  171.       HAL_Delay(1000);
  172.      Watercolor(0xffff, 100);//青色單燈流水
  173.       HAL_Delay(1000);
  174.      Watercolor(0xff00ff, 100); //紫色單燈流水
  175.       HAL_Delay(1000);
  176.      Watercolor(0xffffff, 100); //白色單燈流水
  177.       HAL_Delay(1000);
  178.       
  179.      colorWipe(0x00,1); //off
  180.       HAL_Delay(10000);
  181.      colorWipe(0xff0000,100); //紅色逐個點亮
  182.       HAL_Delay(1000);
  183.      colorWipe(0x00,100); //0ff
  184.       HAL_Delay(1000);
  185.      colorWipe(0xff00,100);  //綠色逐個點亮
  186.       HAL_Delay(1000);
  187.      colorWipe(0x00,100); //0ff
  188.       HAL_Delay(1000);
  189.      colorWipe(0xff,100);//藍色逐個點亮
  190.       HAL_Delay(1000);
  191.         colorWipe(0x00,100); //0ff
  192.       HAL_Delay(1000);
  193.         colorWipe(0xffff00,100); //黃色逐個點亮
  194.       HAL_Delay(1000);
  195.      colorWipe(0x00,100); //0ff
  196.       HAL_Delay(1000);
  197.      colorWipe(0xffff,100); //青色逐個點亮
  198.       HAL_Delay(1000);
  199.      colorWipe(0x00,100); //0ff
  200.       HAL_Delay(1000);
  201.      colorWipe(0xff00ff,100); //紫色逐個點亮
  202.       HAL_Delay(1000);
  203.       colorWipe(0x00,100); //0ff
  204.       HAL_Delay(1000);
  205.         colorWipe(0xffffff,100); //白色逐個點亮
  206.       HAL_Delay(1000);
  207.      colorWipe(0x00,100); //0ff
  208.        HAL_Delay(1000);


  209.       
  210.   }
  211. }
復制代碼



setfrequence.jpg (247.03 KB, 下載次數: 225)

下載時STCisp設置頻率

下載時STCisp設置頻率

frequence.jpg (79.32 KB, 下載次數: 226)

keil設置頻率

keil設置頻率

fail.jpg (195.8 KB, 下載次數: 217)

設置37燈內存地址空間滿

設置37燈內存地址空間滿

fenweideng.rar

34.1 KB, 下載次數: 445, 下載積分: 黑幣 -5


作者: June1210    時間: 2019-1-7 15:12
樓主 可以加個好友么  我也學STC15W204S
作者: 摯愛梅兒    時間: 2019-1-8 10:05
keil設置target options------memory Model 選擇large:variables in XDATA再編譯一遍試試
作者: yuren1984    時間: 2019-1-10 05:23
已經解unsigned char idata buf_R[numLEDs] = {0};//顏色緩存 unsigned char buf_G[numLEDs] = {0};//顏色緩unsigned char buf_B[numLEDs] = {0};//顏色緩存,這樣修改最多可以點78顆燈,有興趣的朋友可以試一試     
作者: yuren1984    時間: 2019-1-10 05:25
摯愛梅兒 發表于 2019-1-8 10:05
keil設置target options------memory Model 選擇large:variables in XDATA再編譯一遍試試

這樣編譯我試了,程序能編譯能通過,下載單片機里一個燈都不亮,百度了一下說要加外部RAM
作者: yuren1984    時間: 2019-1-10 05:26
June1210 發表于 2019-1-7 15:12
樓主 可以加個好友么  我也學STC15W204S

可以啊,加我QQ 176492137
作者: 陳小手43970    時間: 2019-2-20 12:51
你好,我發現這個程序只能亮ff的顏色,其余0-254的顏色無法顯示哎
作者: LIUYIXIEYANG    時間: 2019-2-21 21:33
陳小手43970 發表于 2019-2-20 12:51
你好,我發現這個程序只能亮ff的顏色,其余0-254的顏色無法顯示哎

你的是不是也只亮白色
作者: 來生只想做頭豬    時間: 2019-3-28 11:25
老兄,你的頭文件是對的,我的改了頭文件就報錯
作者: 煙雨、平生    時間: 2020-3-25 10:01
好東西
作者: 無名之火    時間: 2020-3-25 10:57
晶振頻率太低,要33M,我的可以用
作者: 夕日東    時間: 2020-4-2 09:35
感謝樓主
作者: 1AJ1987402    時間: 2020-5-1 15:42
試程序要以用
作者: 1AJ1987402    時間: 2020-5-3 18:11
樓主,如果第一個燈亮后保持到第二個亮后也保持,第三個亮后也保持,這個怎寫?太感謝了
作者: bsqpcb    時間: 2020-5-22 20:52
我都用臺系類PIC的,16M 2T 一樣的可以做到完美時序
作者: bababibu    時間: 2020-10-20 17:25
將idata改為xdata,可以128燈,我用STC15W4K32S4仿真可以成功

#define numLEDs 128  //燈的個數
unsigned char xdata buf_R[numLEDs] = {0};//顏色緩存
unsigned char xdata buf_G[numLEDs] = {0};
unsigned char xdata buf_B[numLEDs] = {0};


作者: 騰飛的龍    時間: 2021-3-23 09:59
yuren1984 發表于 2019-1-10 05:23
已經解unsigned char idata buf_R[numLEDs] = {0};//顏色緩存 unsigned char buf_G[numLEDs] = {0};//顏色 ...

感謝分享,學習啦。這樣修改的確可以驅動60個燈珠
作者: 騰飛的龍    時間: 2021-3-23 11:35
bababibu 發表于 2020-10-20 17:25
將idata改為xdata,可以128燈,我用STC15W4K32S4仿真可以成功

#define numLEDs 128  //燈的個數
...

牛人!。。。。。。。。。。。。。!
作者: nanyexin    時間: 2021-6-16 18:54
bababibu 發表于 2020-10-20 17:25
將idata改為xdata,可以128燈,我用STC15W4K32S4仿真可以成功

#define numLEDs 128  //燈的個數
...

如果要驅動1024個像素點呢?就時候1024個燈,市場上的可以做到,怎么修改……。
作者: tzs233    時間: 2021-7-10 14:02
nanyexin 發表于 2021-6-16 18:54
如果要驅動1024個像素點呢?就時候1024個燈,市場上的可以做到,怎么修改……。

算一下理論時間,數據手冊上發送一個bit需要1.25us左右,一個RGB像素點24bit。共需要時間 1024*1.25*24 = 30720us,即光驅動這1024顆燈需要30ms以上,這個時間已經很長了。發送過程中還不能被其他任務打斷。然后你的ram資源要足夠 (1024*3個byte,即3kb以上,想實現復雜花樣效果就要考慮算法、硬件設計,全亮這電源起碼都60安的電流了) ,
作者: lx8238157    時間: 2022-9-29 13:31
非常感謝,正好需要,我目前控制30燈珠
作者: nuomistudio    時間: 2022-10-3 14:14
mark一下,后面玩的時候再來看看




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