本帖最后由 好学天上 于 2024-8-5 18:25 编辑
- <ol class="code_ol_R87" style="list-style-position: initial; list-style-image: initial; font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"><li style="padding-left: 5px; list-style-position: initial; list-style-image: initial; border-left: 1px solid rgb(205, 205, 205) !important;"><div class="blockcode"><blockquote>void send_L(void)
- {
- WS2812=1;
- _nop_();
- _nop_();
- _nop_();
- WS2812=0;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- void send_H(void)
- {
- WS2812=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- WS2812=0;
- _nop_();
- _nop_();
- _nop_();
- }void send_one_byte(unsigned char in_data)
- {
- unsigned char temp1=0;
- unsigned char temp2=0;
- unsigned char temp3=0;
- unsigned char i=0;
- temp1=in_data;
- for(i=0;i<8;i++) //八位,循环八次
- {
- if(temp1&0x01)
- send_H();
- else
- send_L();
- temp1 >>= 1; //从最低位到最高位
- }
- }
-
- void set_one_led(unsigned char R_data,unsigned char G_data,unsigned char B_data)
- {
- send_one_byte(R_data);
- send_one_byte(G_data);
- send_one_byte(B_data);
- }
-
- void WS2812_Write(void)
-
- {
- unsigned int i;
- WS2812_Reset();
- i=0;
-
- while(1)
- {
- if(i==LED_ON)
- {
- set_one_led(RED,GREEN,BLUE);
- break;
-
- }
- else
- {
- set_one_led(0,0,0);
- i++;
- }
- }
- }
-
- void Init(void)
- {
- P5M0 = 0x10;
- P5M1 = 0x00;
-
- }
-
- void main(void)
- {
- Init();
- WS2812_Reset();
- while(1)
- {
-
-
- // RED=255; //红 0~255
- // GREEN=0; //绿 0~255
- // BLUE=0; //蓝 0~255
- set_one_led(0,255,255);
- set_one_led(0,0,0);
- WS2812_Reset();
- }
- }void WS2812_Reset(void)
- {
- WS2812=0;
- Delay_x10us(10);
- }
复制代码
这样还是不行 |