芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

IC解密STM32控制PCA9685程序源码

IC解密PCA9685 在stm32下的程序设计


  1. IC解密#include "pca9685.h"
  2. IC解密#include "pca9685_reg.h"    /* Light Driver Chip */
  3. IC解密#include "bsp_i2c_gpio.h"
  4. IC解密#define MAX_OUTPUT_INDEX        15
  5. IC解密#define MAX_OUTPUT_VALUE        0xFFF
  6. /******************************************/
  7. /*                                        */
  8. /*   Probe the I2C bus, and show the      */
  9. /*   user what we have found              */
  10. /*                                        */
  11. /*                                        */
  12. /*                                        */
  13. /******************************************/

  14. /******************************************/
  15. /*                                        */
  16. /* Philips PCA9685 I2C Driver, 16 channel */
  17. /* Lighting controler chip                */
  18. /*                                        */
  19. /*                                        */
  20. /******************************************/

  21. /******************************************/
  22. /*                                        */
  23. /* Init code for the PCA9685              */
  24. /*                                        */
  25. /******************************************/

  26. void init_pca9685(unsigned char address)
  27. {
  28.     unsigned char buf[30];
  29.    
  30.     printf("Setting up channel %d\n\r",address);
  31.    
  32.     buf[0] = PCA9685_MODE1;
  33.     buf[1] = PCA9685_AI;
  34.    // buf[2] = PCA9685_OUTDRV;
  35.     buf[2] = PCA9685_INVRT;
  36.     i2c_WriteBuffer(address,(char *) buf, 3);
  37. }

  38. /******************************************/
  39. /*                                        */
  40. /* Send data to a given channel of a      */
  41. /* given PCA9685 chip                     */
  42. /*                                        */
  43. /******************************************/

  44. void pca9685_led(unsigned char addr, int led, unsigned char *values)
  45. {
  46.     unsigned char buf[5];
  47.    
  48.     if (led == PCA9685_ALL_LEDS) {
  49.         buf[0] = PCA9685_ALL_LED_ON_L;
  50.     } else {
  51.         buf[0] = PCA9685_BASE(led);
  52.     }

  53.     buf[1] = values[0];
  54.     buf[2] = values[1];
  55.     buf[3] = values[2];
  56.     buf[4] = values[3];
  57.     i2c_WriteBuffer(addr, (char *)buf, 5);
  58. }

  59. /******************************************/
  60. /*                                        */
  61. /* Send all the data to a single rgba led */
  62. /* at once to the PCA9685 chip            */
  63. /*                                        */
  64. /*                                        */
  65. /*                                        */
  66. /* color[0] = red (0-255)                 */
  67. /* color[1] = green (0-255)               */
  68. /* color[2] = blue (0-255)                */
  69. /* color[3] = amber (0-100%)              */
  70. /* total brightness = level (0-100%)      */
  71. /******************************************/
  72. void pca9685_rgba_led(unsigned char addr, int rgba_led, unsigned char *color, unsigned char level)
  73. {
  74.     int led;
  75.     unsigned int on, off;
  76.     unsigned char buf[17];
  77.    
  78.     if (level > 100){
  79.         //printf("Level percentage range 0 - 100 (Trying for %d)\n\r",level);
  80.         return;
  81.         }
  82.     if (color[3] > 100) {
  83.         //printf("Amber percentage range 0 - 100 (Trying for %d)\n\r",color[3]);
  84.         return;
  85.         }
  86.     on=0;
  87.     if (rgba_led == PCA9685_ALL_LEDS) {
  88.         buf[0] = PCA9685_ALL_LED_ON_L;
  89.         if (color[0]==0 || level==0){
  90.             buf[1]=0;
  91.             buf[1+PCA9685_LED_ON_H] = 0;//buf[2]
  92.             buf[3]=0;
  93.             buf[1+PCA9685_LED_OFF_H] = PCA9685_LED_OFF;//buf[4]
  94.             //printf("all on, zero brightness\r\n");
  95.         }
  96.         else if (color[0]==0xff && level==100){
  97.             buf[1]=0;
  98.             buf[1+PCA9685_LED_ON_H] = PCA9685_LED_ON;//buf[2]
  99.             buf[3]=0;
  100.             buf[1+PCA9685_LED_OFF_H] = 0;//buf[4]
  101.             //printf("all on, full brightness\r\n");
  102.         }
  103.         else{
  104.             off = (4096 * color[0]*level) / 0xff / 100;
  105.             buf[1+PCA9685_LED_ON_L] = on & 0xff;//buf[1]
  106.             buf[1+PCA9685_LED_ON_H] = (on >> 8) & 0xf;//buf[2]
  107.             buf[1+PCA9685_LED_OFF_L] = off & 0xff;//buf[3]
  108.             buf[1+PCA9685_LED_OFF_H] = (off >> 8) & 0xf;//buf[4]
  109.         }
  110.         i2c_WriteBuffer(addr, (char *)buf, 5);
  111.         //printf("All leds on\r\n");
  112.         return;
  113.     } else {
  114.         buf[0] = PCA9685_BASE(rgba_led);
  115.     }   



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.feixindz.com
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信