CH32X035 芯片 PIOC 参考应用例程使用说明
引言:
CH32X035 芯片内,嵌入了一个可编程协议 I/O 微控制器 PIOC,即 eMCU,该 eMCU 基于单时钟周期精简指令集的 RISC8B 内核,运行于系统主频,具有 2K 指令的程序 ROM 和 49 个 SFR 寄存器及 PWM 定时/计数器,支持 2 个 I/O 引脚的协议控制。
在 EVT 中,我们提供了 PIOC 的参考工程,这里仅以 WS2812 为例,简单介绍代码结构及实际使用方法。
代码结构:
在参考工程中,我们需要关注 User 文件夹中 main.c 与 RGB1W.c 两个文件。
RGB1W.c 文件中,PIOC_1W_CODE 数组,为使用汇编语言实现的 PIOC 操作 DS1820 与 WS2812 两种器件编译后的二进制数据;RGB1W_Init 函数用于初始化 PIOC 功能,对于具有 PC7 引脚的 X035 芯片可以在此进行选择。
1. const unsigned char PIOC_1W_CODE[] ={
2. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x60,0x00,0x00,0x00,0x00,0x00,0x00,
3. 0x00,0x00,0x0A,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4. 0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x1C,0x5E,0x1C,0x47,
5. 0x1C,0x5D,0x16,0x60,0x1C,0x47,0x1E,0x02,0x09,0x10,0x31,0xC1,0x3E,0xC2,0x34,0xC3,
6. 0x2F,0x80,0x20,0x2F,0x41,0x38,0x87,0x2F,0x2F,0x38,0xFC,0x2F,0x93,0x38,0x00,0x00,
7. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x28,
8. 0x8E,0x60,0x00,0x00,0x2C,0x71,0x8E,0x60,0x00,0x00,0x2C,0x71,0x8E,0x30,0x4B,0x24,
9. 0x28,0x22,0xE9,0x70,0x04,0x15,0x39,0x30,0x09,0x15,0x38,0x30,0x00,0x00,0x38,0x71,
10. 0x8E,0x60,0x00,0x00,0x08,0x01,0x0B,0x40,0x0A,0x48,0x0C,0x01,0x06,0x28,0x0B,0x54,
11. 0x8E,0x60,0x09,0x02,0x04,0x10,0x20,0x24,0x00,0x00,0x0B,0x48,0x0B,0x70,0x01,0x5F,
12. 0x0B,0x40,0x08,0x70,0x0B,0x40,0x0A,0x70,0x0B,0x48,0x0B,0x70,0x01,0x5E,0x0B,0x40,
13. 0x08,0x70,0x0B,0x40,0x0A,0x70,0x0B,0x48,0x0B,0x70,0x01,0x5D,0x0B,0x40,0x08,0x70,
14. 0x0B,0x40,0x0A,0x70,0x0B,0x48,0x0B,0x70,0x01,0x5C,0x0B,0x40,0x08,0x70,0x0B,0x40,
15. 0x0A,0x70,0x0B,0x48,0x0B,0x70,0x01,0x5B,0x0B,0x40,0x08,0x70,0x0B,0x40,0x0A,0x70,
16. 0x0B,0x48,0x0B,0x70,0x01,0x5A,0x0B,0x40,0x08,0x70,0x0B,0x40,0x0A,0x70,0x0B,0x48,
17. 0x0B,0x70,0x01,0x59,0x0B,0x40,0x08,0x70,0x0B,0x40,0x0A,0x70,0x0B,0x48,0x0B,0x70,
18. 0x01,0x58,0x0B,0x40,0x09,0x70,0x01,0x02,0x0B,0x40,0x0D,0x70,0x04,0x15,0x4D,0x30,
19. 0x1E,0x28,0xEE,0x70,0xEE,0x70,0x04,0x00,0x0B,0x54,0x04,0x28,0x1D,0x10,0x1C,0x4F,
20. 0x16,0x60,0x02,0x28,0x8E,0x60,0x00,0x00,0x08,0x01,0x0B,0x40,0x80,0x28,0x0C,0x10,
21. 0x20,0x02,0x21,0x0A,0x91,0x34,0x0A,0x48,0x09,0x47,0x3E,0x01,0x04,0x01,0x06,0x28,
22. 0x0B,0x54,0x8E,0x60,0x02,0x28,0x3F,0x10,0x18,0x00,0x1F,0x10,0x80,0x29,0x09,0x0A,
23. 0x00,0x00,0x08,0x10,0x13,0x00,0xAE,0x00,0x13,0x00,0xAD,0x00,0x13,0x00,0xAC,0x00,
24. 0x13,0x00,0xAB,0x00,0x13,0x00,0xAA,0x00,0x13,0x00,0x20,0x15,0x20,0x04,0x03,0x52,
25. 0x21,0x15,0xA9,0x00,0x13,0x00,0x20,0x02,0x21,0x0A,0xE3,0x34,0xA8,0x00,0x13,0x00,
26. 0x04,0x02,0x1F,0x10,0xAF,0x00,0x13,0x00,0xAE,0x00,0x13,0x00,0xAD,0x00,0x13,0x00,
27. 0xAC,0x00,0x13,0x00,0x20,0x15,0x20,0x04,0x03,0x52,0x21,0x15,0xAB,0x00,0x13,0x00,
28. 0x3E,0x14,0x03,0x52,0x3F,0x14,0xAA,0x00,0x13,0x00,0x3E,0x02,0x04,0x10,0xA9,0x00,
29. 0x13,0x00,0x20,0x02,0x21,0x0A,0xE3,0x34,0x3F,0x02,0xA8,0x00,0x13,0x00,0x18,0x00,
30. 0x1F,0x10,0xAF,0x00,0xAA,0x60,0xA8,0x00,0x13,0x00,0x08,0x47,0x12,0x00,0x08,0x01,
31. 0x88,0x60,0xFA,0x28,0xEE,0x60,0x41,0x28,0xEE,0x60,0x02,0x28,0x0D,0x70,0x00,0x00,
32. 0x0D,0x70,0x00,0x00,0x0D,0x70,0x00,0x00,0x0D,0x70,0x00,0x00,0xFF,0x2C,0x00,0x00,
33. 0xEE,0x30,0x30,0x00,0x0A,0x40,0x08,0x01,0x0C,0x01,0x05,0x28,0xEE,0x70,0x0B,0x40,
34. 0x0A,0x48,0xE9,0x70,0xE9,0x70,0x0A,0x40,0xEB,0x70,0x09,0x01,0x0B,0x54,0x04,0x24,
35. 0xE9,0x70,0x09,0x02,0x30,0x00,0x09,0x10,0x08,0x22,0x0B,0x40,0x0A,0x48,0xED,0x70,
36. 0x09,0x50,0x0A,0x40,0xEB,0x70,0x0A,0x40,0x05,0x28,0x09,0x58,0xEE,0x70,0x09,0x1F,
37. 0x04,0x15,0x0D,0x31,0x30,0x00,0x08,0x22,0x0B,0x40,0x0A,0x48,0xED,0x70,0x0A,0x40,
38. 0x0A,0x28,0xEE,0x70,0x09,0x1F,0x09,0x47,0x0B,0x54,0x09,0x4F,0x37,0x28,0xEE,0x70,
39. 0x04,0x15,0x1C,0x31,0x09,0x02,0x30,0x00,0xFA,0x70,0x37,0x31,0xCC,0x28,0x0B,0x71,
40. 0x44,0x28,0x0B,0x71,0x1C,0x5C,0x36,0x61,0x0B,0x48,0x0A,0x48,0x04,0x00,0x30,0x00,
41. 0xFA,0x70,0x43,0x31,0xCC,0x28,0x0B,0x71,0xBE,0x28,0x0B,0x71,0x1B,0x71,0x20,0x10,
42. 0x1B,0x71,0x21,0x10,0xFA,0x70,0x30,0x00,0x00,0x00};
main.c 文件中,RGBpbuf 数组,按 GRB 的顺序,保存了每颗灯珠的每种颜色所需显示的亮度信息;宏定义 rgb_data_bytes 使用 sizeof 函数,根据 RGBpbuf 数组的大小,自动获取所需驱动的灯珠个数。在 while 循环中,根据标志位的转换,使用 RGB1W_SendRAM 函数,通过 PIOC 引脚,将三个 RGBpbuf 数组循环发送,以此实现灯带的动态效果。
1. u8 RGBpbuf[] = {
2. 0x00, 0xFF, 0x00,
3. 0x00, 0x00, 0xFF,
4. 0xFF, 0x00, 0x00,
5. 0x00, 0xFF, 0x00,
6. 0x00, 0x00, 0xFF,
7. 0xFF, 0x00, 0x00,
8. 0x00, 0xFF, 0x00,
9. 0x00, 0x00, 0xFF,
10. 0xFF, 0x00, 0x00,
11. 0x00, 0xFF, 0x00,
12. };
13.
14. #define rgb_data_bytes sizeof(RGBpbuf)
使用方法:
以 X035F8U6 芯片为例,PIOC 占用 PC18 引脚,因此在初始化的过程中,关闭了芯片的 SWD 功能。这一操作将导致再次使用 SWD 接口下载时出现失败的问题,可以在下载前,使用 MRS 或 Utility 中的代码擦除功能,抹除片内 Flash 的全部数据,或使用 PC17 引脚,在复位后触发单片机跳转至 BOOT 区域,在其超时退出前(即未执行用户区代码前)使用 SWD 接口完成固件的更新。
RGBpbuf 数组,保存了 WS2812 灯珠的亮度信息,以蓝色为例,如果需要调整灯珠的发光强度,应在对应灯珠蓝色数据所在的位置,填入 0x00~0xFF 范围内的数值(十进制0~255);如果需要混光,可以首先确定某一颜色对应的 RGB 亮度值,再将数值转换为十六进制写入数组。在参考应用例程的基础上,可以根据实际的需求,灵活运用 RGB1W_SendRAM 函数,实现最大1024颗 WS2812 的动态刷新。
标签:0x28,参考,例程,PIOC,0x00,0x40,0x70,0x0A,0x0B From: https://www.cnblogs.com/wchmcu/p/17678765.html