非常感谢南京中科微 联合电子发烧友 平台提供的开发板
1.硬件介绍![cgi-bin_mmwebwx-bin_webwxgetmsgimg_&MsgID=2717589913215941870&skey=@crypt_31e4601d_353f3bf8cfc6d99de44d48b19593b3e4&mmweb_appid=wx_webfilehelper.jpg](//file.elecfans.com/web2/M00/52/A4/poYBAGLOdfGAIyp4AAH-PIFrj-0811.jpg)
2.原理图![default (1).jpg](//file.elecfans.com/web2/M00/53/4C/pYYBAGLOeeuALKe-AAFnq1u9H4w608.jpg)
3.新建项目![default (2).jpg](//file.elecfans.com/web2/M00/52/B1/poYBAGLOeieATjf0AAEQL6nzsfs905.jpg)
4.加载代码![cgi-bin_mmwebwx-bin_webwxgetmsgimg_&MsgID=6839956271048537450&skey=@crypt_31e4601d_353f3bf8cfc6d99de44d48b19593b3e4&mmweb_appid=wx_webfilehelper.jpg](//file.elecfans.com/web2/M00/53/4E/pYYBAGLOel-ATo0VAAE38WQQrVI982.jpg)
5.WS2812介绍![捕获000.jpg](//file.elecfans.com/web2/M00/53/68/pYYBAGLOgxSATCs2AADsuhEvbLU124.jpg)
![捕获111.jpg](//file.elecfans.com/web2/M00/52/CD/poYBAGLOgx2ADDaHAAE81qOJWu0675.jpg)
6.代码
void u_delay(uint32_t i)
{
while(i--)
{
NOP;
}}
void u_pa0_low(void)
{
GPIO_Write(GPIOA,PIN0,GPIO_SET); //GPIO 输出
NOP;NOP;NOP;NOP;NOP;
GPIO_Write(GPIOA,PIN0,GPIO_RESET); //GPIO 输出
NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
}
void u_pa0_high(void)
{
GPIO_Write(GPIOA,PIN0,GPIO_SET); //GPIO 输出
NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;
GPIO_Write(GPIOA,PIN0,GPIO_RESET); //GPIO 输出
NOP;NOP;NOP;NOP;NOP;
}
void u_pa0_reset(void)
{
GPIO_Write(GPIOA,PIN0,GPIO_RESET); //GPIO 输出
u_delay(1000);
}
void u_pa0_send_data(uint8_t dat)
{
uint8_t i;
for(i=0;i<8;i++)
{
if(dat&0x80){u_pa0_high();}
else{u_pa0_low();}
dat <<= 1;
}
}
void u_pa0_send_RGB(uint8_t G,uint8_t R,uint8_t B)
{
uint8_t i;
SYS_Interrupt_Disable();
for(i=0;i<60;i++)
{
u_pa0_send_data(G);
u_pa0_send_data(R);
u_pa0_send_data(B);
}
SYS_Interrupt_Enable();//CLIC开总中断
u_pa0_reset();
}
注意:
1.WS2812采用单极性归零码,对时序要求比较高,发送数据时尽量关闭中断。
2.库函数比寄存器操作慢。
3.开发板带有保险丝,输出功率受限。
|