金牌会员
 
- 积分
- 2099
- 金钱
- 2099
- 注册时间
- 2017-2-11
- 在线时间
- 306 小时
|
发表于 2021-1-14 08:35:38
|
显示全部楼层
- #define RGB_H (NRF_GPIO->OUTSET = (1UL << RGB_LED)) //RGB 对应管脚设置 高电平
- #define RGB_L (NRF_GPIO->OUTCLR = (1UL << RGB_LED)) //RGB 对应管脚设置 高电平
- /*
- 初始化RGB_LED
- */
- void LED_GPIO_Configuration(void)
- {
- nrf_gpio_cfg(
- RGB_LED,
- NRF_GPIO_PIN_DIR_OUTPUT,
- NRF_GPIO_PIN_INPUT_DISCONNECT,
- NRF_GPIO_PIN_PULLUP,
- NRF_GPIO_PIN_S0S1,
- NRF_GPIO_PIN_NOSENSE);
- }
- /*
- 写 0码 函数
- 根据RGB灯手册查得 :RGB_H 延时 300ns,RGB_L 延时 900ns
- RGB_H,RGB_L之间的延时,根据不同芯片的主频实际调节__nop()函数的个数(以下nop个数未知)
- */
- void Write0(void)
- {
- RGB_H;
- __nop();__nop();__nop();
-
- RGB_L;
- __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
- __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
- }
- /*
- 写 1码 函数
- 根据RGB灯手册查得 :RGB_H 延时 600ns,RGB_L 延时 600ns
- RGB_H,RGB_L之间的延时,根据不同芯片的主频实际调节__nop()函数的个数
- */
- void Write1(void)
- {
- RGB_H;
- __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
- __nop();__nop();__nop();_
-
- RGB_L;
- __nop();__nop();__nop();__nop();__nop();__nop();
- }
- /*
- 写一个字节(8bit)数据
- 备 注: RGB的亮度通过更改 0x01 处的值进行调节
- */
- void RGB_WByte(uint8_t byte)
- {
- uint8_t i=0;
- for(i=0;i<8;i++)
- {
- if((byte<<i)&0x01)
- Write1();
- else
- Write0();
- }
- }
- /*
- 设置一个RGB灯的色彩
- green red blue,红绿蓝光所占比例大小,范围0~255
- 灯亮的顺序为GRB,每种颜色占8位数据,因此一个灯需要写24位数据
- */
- void Write24Bit(uint8_t green, uint8_t red, uint8_t blue)
- {
- RGB_WByte(green);
- RGB_WByte(red);
- RGB_WByte(blue);
- }
- /*
- 红灯
- */
- void RGB_LED_Red(void)
- {
- Write24Bit(0,0xff,0);
- }
- /*
- 橙灯
- */
- void RGB_LED_Orange(void)
- {
- for(i=0;i<4;i++) //4个灯
- {
- Write24Bit(0xa5,0xff,0x00);
- }
- }
- /*
- 蓝灯
- */
- void RGB_LED_Off(void)
- {
- uint8_t i;
- for(i=0;i<4;i++) //四个灯
- {
- Write24Bit(0,0,0);
- }
- }
- //.......
复制代码 |
|