久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1431|回復: 3
打印 上一主題 下一主題
收起左側

這個單片機程序老是說編譯錯誤,哪位大神指點一下

[復制鏈接]
跳轉到指定樓層
樓主
ID:735961 發表于 2020-10-4 20:40 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #include <STC15F2K60S2.H>
  2. #include "intrins.h"

  3. sbit WS2812 = P1^7;

  4. #define numLEDs 8   //燈的個數
  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 int t)
  11. {
  12.                 unsigned int x,y;
  13.           for(x=114;x>0;x--)
  14.           for(y=t;y>0;y--);
  15. }


  16.          
  17. //復位延時
  18. void Delay50us()                //@22.1184MHz
  19. {
  20.         unsigned char i, j;

  21.         _nop_();
  22.         _nop_();
  23.         i = 2;
  24.         j = 15;
  25.         do
  26.         {
  27.                 while (--j);
  28.         } while (--i);
  29. }


  30. //1碼,高電平850ns 低電平400ns 誤差正負150ns
  31. void RGB_Set_Up()
  32. {
  33.                 WS2812 = 1;
  34.           //經過邏輯分析儀調試的的延時
  35.                 _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
  36.           _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();_nop_();
  37.                 WS2812 = 0;
  38. }

  39. //1碼,高電平400ns 低電平850ns 誤差正負150ns
  40. void RGB_Set_Down()
  41. {
  42.                 WS2812 = 1;
  43.           //經過邏輯分析儀調試的的延時
  44.                 _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();  
  45.                 WS2812 = 0;
  46. }

  47. //發送24位數據
  48. void Send_2811_24bits(unsigned char G8,unsigned char R8,unsigned char B8)
  49. {
  50.          
  51.           unsigned int n = 0;
  52.           //發送G8位
  53.                 for(n=0;n<8;n++)
  54.                 {
  55.                         G8<<=n;
  56.                         if(G8&0x80 == 0x80)
  57.                         {
  58.                                 RGB_Set_Up();
  59.                         }
  60.                         else  
  61.                         {
  62.                           RGB_Set_Down();
  63.                         }
  64.                 }
  65.                 //發送R8位
  66.                 for(n=0;n<8;n++)
  67.                 {
  68.                         R8<<=n;
  69.                         if(R8&0x80 == 0x80)
  70.                         {
  71.                                 RGB_Set_Up();
  72.                         }
  73.                         else  
  74.                         {
  75.                                 RGB_Set_Down();
  76.                         }
  77.                         
  78.                 }
  79.                 //發送B8位
  80.           for(n=0;n<8;n++)
  81.                 {
  82.                         B8<<=n;
  83.                         if(B8&0x80 == 0x80)
  84.                         {
  85.                                 RGB_Set_Up();
  86.                         }
  87.                         else  
  88.                         {
  89.                           RGB_Set_Down();
  90.                         }
  91.                 }
  92. }
  93. //復位碼
  94. void RGB_Rst()
  95. {
  96.                 WS2812 = 0;
  97.                 Delay50us();
  98. }
  99. //把24位數據GRB碼轉RGB
  100. void Set_Colour(unsigned char r,unsigned char g,unsigned char b)
  101. {
  102.           unsigned char i;
  103.                 for(i=0;i<numLEDs;i++)
  104.           {
  105.                                 buf_R[i] = r; //緩沖
  106.                           buf_G[i] = g;
  107.                           buf_B[i] = b;
  108.                 }
  109.                 for(i=0;i<numLEDs;i++)
  110.                 {
  111.                         Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);//發送顯示
  112.                 }
  113. }
  114. //某一個點顯示的顏色
  115. void SetPointColour(unsigned int num,unsigned char r,unsigned char g,unsigned char b)
  116. {
  117.           unsigned char i;
  118.                 for(i=0;i<numLEDs;i++)
  119.           {
  120.                                 buf_R[num] = r;//緩沖
  121.                           buf_G[num] = g;
  122.                           buf_B[num] = b;
  123.                 }
  124.                 for(i=0;i<numLEDs;i++)
  125.                 {
  126.                         Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);//發送顯示
  127.                 }
  128. }

  129. //顏色交換24位不拆分發
  130. void SetPixelColor(unsigned char num,unsigned long c)
  131. {
  132.           unsigned char i;
  133.                 for(i=0;i<numLEDs;i++)
  134.           {
  135.                                 buf_R[num] = (unsigned char)(c>>16);
  136.                           buf_G[num] = (unsigned char)(c>>8);
  137.                           buf_B[num] = (unsigned char)(c);
  138.                 }
  139.                 for(i=0;i<numLEDs;i++)
  140.                 {
  141.                         Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);
  142.                 }
  143. }

  144. //復位
  145. void PixelUpdate()
  146. {
  147.         RGB_Rst();
  148. }
  149. //顏色
  150. unsigned long Color(unsigned char r, unsigned char g, unsigned char b)
  151. {
  152.   return ((unsigned long)r << 16) | ((unsigned long)g <<  8) | b;
  153. }

  154. //顏色算法
  155. unsigned long Wheel(unsigned char WheelPos)
  156. {
  157.   WheelPos = 255 - WheelPos;
  158.   if(WheelPos < 85)
  159.         {
  160.     return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  161.   }
  162.   if(WheelPos < 170) {
  163.     WheelPos -= 85;
  164.     return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  165.   }
  166.   WheelPos -= 170;
  167.   return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  168. }

  169. //彩虹
  170. void rainbow(unsigned int wait)
  171. {
  172.   unsigned int i, j;

  173.   for(j=0; j<256; j++)
  174.         {
  175.     for(i=0; i<numLEDs; i++)
  176.                 {
  177.       SetPixelColor(i, Wheel((i+j) & 255));
  178.     }
  179.                 PixelUpdate();
  180.     HAL_Delay(wait);
  181.   }
  182. }

  183. //稍微不同的是,這使得彩虹均勻分布
  184. void rainbowCycle(unsigned int wait)
  185. {
  186.   unsigned int i, j;

  187.   for(j=0;j<256*5;j++)
  188.         { // 5 cycles of all colors on wheel  車輪上所有顏色的5個循環
  189.     for(i=0;i<numLEDs;i++)
  190.          {
  191.      SetPixelColor(i, Wheel(((i * 256 / numLEDs) + j) & 255));
  192.     }
  193.           PixelUpdate();
  194.     HAL_Delay (wait);
  195.   }
  196. }

  197. //Theatre-style crawling lights.呼吸燈
  198. void theaterChase(unsigned long c, unsigned int wait)
  199. {
  200.         int j,q;
  201.         unsigned int i;
  202.   for (j=0; j<10; j++)
  203.         {  //do 10 cycles of chasing  做10個循環
  204.     for (q=0; q < 3; q++)
  205.                 {
  206.       for (i=0; i<numLEDs; i=i+3)
  207.                         {
  208.         SetPixelColor(i+q, c);    //turn every third pixel on  把每一個第三個像素
  209.       }
  210.                         PixelUpdate();
  211.       HAL_Delay(wait);

  212.       for (i=0; i<numLEDs; i=i+3)
  213.                         {
  214.        SetPixelColor(i+q, 0);        //turn every third pixel off   把每一個第三個像素關掉
  215.       }
  216.                         PixelUpdate();
  217.     }
  218.   }
  219. }

  220. //Theatre-style crawling lights with rainbow effect
  221. //帶有彩虹效果的戲劇式爬行燈
  222. void theaterChaseRainbow(unsigned int wait)
  223. {
  224.         int j,q;
  225.         unsigned int i;
  226.   for (j=0; j < 256; j++)
  227.         {     // cycle all 256 colors in the wheel 在輪子上循環所有256色
  228.     for (q=0; q < 3; q++)
  229.                 {
  230.       for (i=0; i < numLEDs; i=i+3)
  231.                         {
  232.         SetPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel off 把每一個第三個像素
  233.       }
  234.       PixelUpdate();

  235.       HAL_Delay(wait);

  236.       for (i=0; i < numLEDs; i=i+3)
  237.                         {
  238.         SetPixelColor(i+q, 0);        //turn every third pixel off  把每一個第三個像素關掉
  239.       }
  240.     }
  241.   }
  242. }

  243. // Fill the dots one after the other with a color
  244. //用一種顏色填充這些圓點
  245. void colorWipe(unsigned long c, unsigned int wait)
  246. {
  247.         unsigned int i=0;
  248.   for( i=0; i<numLEDs; i++)
  249.         {
  250.     SetPixelColor(i, c);
  251.     PixelUpdate();
  252.     HAL_Delay(wait);
  253.   }
  254. }

  255. void main()
  256. {
  257.          
  258.                 while(1)
  259.                 {
  260.                           rainbow(45);
  261.         rainbowCycle(40);
  262.         theaterChase(Color(0,0,255),80); // Blue
  263.                           theaterChase(Color(0,255,0),80); // Blue
  264.                           theaterChase(Color(255,0,0),80); // Blue
  265.                     theaterChaseRainbow(40);
  266.                                 colorWipe(255,255);
  267.                 }
復制代碼
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:342822 發表于 2020-10-5 00:17 | 只看該作者
295 行加右花括弧
回復

使用道具 舉報

板凳
ID:743654 發表于 2020-10-5 16:24 | 只看該作者
編譯提示什么錯誤?同一樓 貌似主程序少了個}
回復

使用道具 舉報

地板
ID:453974 發表于 2020-10-7 08:17 | 只看該作者
#include <reg52.H>
#include "intrins.h"

sbit WS2812 = P1^7;

#define numLEDs 8   //????
unsigned char buf_R[numLEDs] = {0};//????
unsigned char buf_G[numLEDs] = {0};
unsigned char buf_B[numLEDs] = {0};

void RGB_Set_Up();  //?0?
void RGB_Set_Down(); //?1?



void HAL_Delay(unsigned int t)
{
                unsigned int x,y;
          for(x=114;x>0;x--)
          for(y=t;y>0;y--);
}


         
//????
void Delay50us()                //@22.1184MHz
{
        unsigned char i, j;

        _nop_();
        _nop_();
        i = 2;
        j = 15;
        do
        {
                while (--j);
        } while (--i);
}


//1?,???850ns ???400ns ????150ns
void RGB_Set_Up()
{
                WS2812 = 1;
          //?????????????
                _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
          _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();_nop_();
                WS2812 = 0;
}

//1?,???400ns ???850ns ????150ns
void RGB_Set_Down()
{
                WS2812 = 1;
          //?????????????
                _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();  
                WS2812 = 0;
}

//??24???
void Send_2811_24bits(unsigned char G8,unsigned char R8,unsigned char B8)
{
         
          unsigned int n = 0;
          //??G8?
                for(n=0;n<8;n++)
                {
                        G8<<=n;
                        if(G8&0x80 == 0x80)
                        {
                                RGB_Set_Up();
                        }
                        else  
                        {
                          RGB_Set_Down();
                        }
                }
                //??R8?
                for(n=0;n<8;n++)
                {
                        R8<<=n;
                        if(R8&0x80 == 0x80)
                        {
                                RGB_Set_Up();
                        }
                        else  
                        {
                                RGB_Set_Down();
                        }
                        
                }
                //??B8?
          for(n=0;n<8;n++)
                {
                        B8<<=n;
                        if(B8&0x80 == 0x80)
                        {
                                RGB_Set_Up();
                        }
                        else  
                        {
                          RGB_Set_Down();
                        }
                }
}
//???
void RGB_Rst()
{
                WS2812 = 0;
                Delay50us();
}
//?24???GRB??RGB
void Set_Colour(unsigned char r,unsigned char g,unsigned char b)
{
          unsigned char i;
                for(i=0;i<numLEDs;i++)
          {
                                buf_R[i] = r; //??
                          buf_G[i] = g;
                          buf_B[i] = b;
                }
                for(i=0;i<numLEDs;i++)
                {
                        Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);//????
                }
}
//?????????
void SetPointColour(unsigned int num,unsigned char r,unsigned char g,unsigned char b)
{
          unsigned char i;
                for(i=0;i<numLEDs;i++)
          {
                                buf_R[num] = r;//??
                          buf_G[num] = g;
                          buf_B[num] = b;
                }
                for(i=0;i<numLEDs;i++)
                {
                        Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);//????
                }
}

//????24?????
void SetPixelColor(unsigned char num,unsigned long c)
{
          unsigned char i;
                for(i=0;i<numLEDs;i++)
          {
                                buf_R[num] = (unsigned char)(c>>16);
                          buf_G[num] = (unsigned char)(c>>8);
                          buf_B[num] = (unsigned char)(c);
                }
                for(i=0;i<numLEDs;i++)
                {
                        Send_2811_24bits(buf_G[i],buf_R[i],buf_B[i]);
                }
}

//??
void PixelUpdate()
{
        RGB_Rst();
}
//??
unsigned long Color(unsigned char r, unsigned char g, unsigned char b)
{
  return ((unsigned long)r << 16) | ((unsigned long)g <<  8) | b;
}

//????
unsigned long Wheel(unsigned char WheelPos)
{
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85)
        {
    return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

//??
void rainbow(unsigned int wait)
{
  unsigned int i, j;

  for(j=0; j<256; j++)
        {
    for(i=0; i<numLEDs; i++)
                {
      SetPixelColor(i, Wheel((i+j) & 255));
    }
                PixelUpdate();
    HAL_Delay(wait);
  }
}

//??????,?????????
void rainbowCycle(unsigned int wait)
{
  unsigned int i, j;

  for(j=0;j<256*5;j++)
        { // 5 cycles of all colors on wheel  ????????5???
    for(i=0;i<numLEDs;i++)
         {
     SetPixelColor(i, Wheel(((i * 256 / numLEDs) + j) & 255));
    }
          PixelUpdate();
    HAL_Delay (wait);
  }
}

//Theatre-style crawling lights.???
void theaterChase(unsigned long c, unsigned int wait)
{
        int j,q;
        unsigned int i;
  for (j=0; j<10; j++)
        {  //do 10 cycles of chasing  ?10???
    for (q=0; q < 3; q++)
                {
      for (i=0; i<numLEDs; i=i+3)
                        {
        SetPixelColor(i+q, c);    //turn every third pixel on  ?????????
      }
                        PixelUpdate();
      HAL_Delay(wait);

      for (i=0; i<numLEDs; i=i+3)
                        {
       SetPixelColor(i+q, 0);        //turn every third pixel off   ???????????
      }
                        PixelUpdate();
    }
  }
}

//Theatre-style crawling lights with rainbow effect
//?????????????
void theaterChaseRainbow(unsigned int wait)
{
        int j,q;
        unsigned int i;
  for (j=0; j < 256; j++)
        {     // cycle all 256 colors in the wheel ????????256?
    for (q=0; q < 3; q++)
                {
      for (i=0; i < numLEDs; i=i+3)
                        {
        SetPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel off ?????????
      }
      PixelUpdate();

      HAL_Delay(wait);

      for (i=0; i < numLEDs; i=i+3)
                        {
        SetPixelColor(i+q, 0);        //turn every third pixel off  ???????????
      }
    }
  }
}

// Fill the dots one after the other with a color
//???????????
void colorWipe(unsigned long c, unsigned int wait)
{
        unsigned int i=0;
  for( i=0; i<numLEDs; i++)
        {
    SetPixelColor(i, c);
    PixelUpdate();
    HAL_Delay(wait);
  }
}

void main()
{
         
                while(1)
                {
                          rainbow(45);
        rainbowCycle(40);
        theaterChase(Color(0,0,255),80); // Blue
                          theaterChase(Color(0,255,0),80); // Blue
                          theaterChase(Color(255,0,0),80); // Blue
                    theaterChaseRainbow(40);
                                colorWipe(255,255);
                }
}
確實是缺了},這里面有警告,應該是有程序沒調用吧?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品国产乱码久久久久久a丨 | 亚洲欧美综合 | 国产乱码精品1区2区3区 | av在线播放网站 | 91精品国产综合久久久久久漫画 | 国产精品成人一区二区三区 | 国产精品久久久久久中文字 | 综合久久99 | www.99热.com | 色屁屁在线观看 | 日本成人中文字幕在线观看 | 中文字幕精品一区 | 欧美在线a | 欧美午夜视频 | 日韩图区 | 久久久91精品国产一区二区三区 | 一区二区三区四区电影 | 欧美三级网站 | 精品久久久久久久 | 综合色站导航 | 亚洲成人av在线播放 | 黄色欧美 | 亚洲人久久 | 久久综合激情 | 一区二区三区免费观看 | 成人动漫视频网站 | 久久久91精品国产一区二区三区 | 中文字幕免费视频 | 一级片毛片 | 久久大| 亚洲国产精品成人综合久久久 | 精品无码久久久久久久动漫 | 欧美精品久久久久久久久久 | 欧美偷偷 | 亚洲一区免费 | 亚洲欧美日韩一区 | 午夜免费观看体验区 | 欧美一区二区三区在线观看 | 一区二区三区视频在线 | 国产精品美女久久久久aⅴ国产馆 | 在线成人|