/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.0.0
* Date : 2023/04/06
* Description : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/* 1-wire example: 1W-RGB_WS2812, 1W-DS1820
* PC18 or PC7 needs to connected a 4.7k pull-up resistor when chip drives DS1820 mode.
* RAM--
* PIOC-4K
* User-16K
*/
#include "debug.h"
#include "RGB1W.h"
#define RGB 0
#define RGB_LED_NUM 48
#define Mode RGB_WS2812
__IO uint16_t temper;
u8 RGBpbuf[] = {
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
};
u8 RGBpbuf1[] = {
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
};
u8 RGBpbuf2[] = {
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF,
0xFF, 0x00, 0x00,
0x00, 0xFF, 0x00,
};
/* Global define */
#define rgb_source_addr ((uint8_t *)RGBpbuf2)
#define rgb_data_bytes (RGB_LED_NUM*3) // 10 RGB LEDs, 30 bytes data
#define timer_to_run 1 // start by timer
u8 RGBpbuf3[rgb_data_bytes];
void rgb_all_led(u8 color_r,u8 color_g,u8 color_b);
void rgb_set_pixel(u8 n,u8 color_r,u8 color_g,u8 color_b);
/*********************************************************************
* @fn main
*
* [url=home.php?mod=space&uid=247401]@brief[/url] Main program.
*
* [url=home.php?mod=space&uid=266161]@return[/url] none
*/
int main(void)
{
uint16_t total_bytes;
uint8_t t1=0;
u8* RGB_RAM;
Delay_Init();
Delay_Ms(1000);
Delay_Ms(1000);
USART_Printf_Init(115200);
printf("SystemClk:%d\r\n", SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
RGB1W_Init( );
stat = 0x80; //free
while ( 1 )
{
total_bytes = rgb_data_bytes;
// rgb_all_led(23,23,70);
//// rgb_set_pixel(1,5,100,50);
// RGB_RAM = RGBpbuf3;
// RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
// Delay_Ms(500);
//
// rgb_all_led(20,20,10);
// RGB_RAM = RGBpbuf3;
// RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
// Delay_Ms(500);
// t1+=5;
// t1%=70;
// rgb_all_led(t1,t1,t1);
// rgb_set_pixel(1,5,100,50);
//
// RGB_RAM = RGBpbuf3;
// RGB1W_SendRAM_Wait( rgb_data_bytes, RGB_RAM );
//
//// long data
Delay_Ms(200);
stat = 0x80;//free
if ( stat != 0xFF ) {//RGB1W completed
if ( stat < 0x80 ) {//got status in interrupt
if ( stat == RGB1W_ERR_OK ) printf("1-wire finished\r\n")/**/;
else printf("1-wire error %02x\r\n", stat)/* */;
stat = 0x80;//free
}
if ( stat == 0x80 && total_bytes && timer_to_run ) {//RAM mode for 1~3072 bytes data
stat = 0xFF;//wait
if(t1==0){
t1 = 1;
RGB_RAM = RGBpbuf;
}
else if(t1==1){
t1 = 2;
RGB_RAM = RGBpbuf1;
}
else if(t1==2){
t1 = 0;
RGB_RAM = RGBpbuf2;
}
RGB1W_SendRAM( total_bytes, RGB_RAM );
total_bytes = 0;
}
}
if ( PIOC->D8_SYS_CFG & RB_INT_REQ ) {//query if disable interrupt
stat = PIOC->D8_CTRL_RD;//auto remove interrupt request after reading
}
}
}
void rgb_all_led(u8 color_r,u8 color_g,u8 color_b)
{
u8 i;
for(i=0;i<RGB_LED_NUM;i++)
{
RGBpbuf3[3*i] =color_r;
RGBpbuf3[3*i+1] =color_g;
RGBpbuf3[3*i+2] =color_b;
}
}
void rgb_set_pixel(u8 n,u8 color_r,u8 color_g,u8 color_b)
{
RGBpbuf3[3*(n-1)] =color_r;
RGBpbuf3[3*(n-1)+1] =color_g;
RGBpbuf3[3*(n-1)+2] =color_b;
}
测试结果:
不错,赞一个