phillip_bourdon234

SkittleSorterConfigBits.h

Jul 1st, 2020 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.52 KB | None | 0 0
  1. // A video demonstration of this project can be found here: https://bit.ly/2Wfsdqs
  2.  
  3. #ifndef XC_SKITTLE_SORTER_H
  4. #define XC_SKITTLE_SORTER_H
  5.  
  6. #include <xc.h> // include processor files - each processor file is guarded.  
  7.  
  8. #define _XTAL_FREQ 500000
  9.  
  10. #define TCS34725_READ_ADDRESS (0x53)
  11. #define TCS34725_WRITE_ADDRESS (0x52)     /**< I2C address **/
  12. #define TCS34725_COMMAND_BIT (0x80) /**< Command bit **/
  13. #define TCS34725_ENABLE (0x00)      /**< Interrupt Enable register */
  14. #define TCS34725_ENABLE_AIEN (0x10) /**< RGBC Interrupt Enable */
  15. #define TCS34725_ENABLE_WEN                                                    \
  16.   (0x08) /**< Wait Enable - Writing 1 activates the wait timer */
  17. #define TCS34725_ENABLE_AEN                                                    \
  18.   (0x02) /**< RGBC Enable - Writing 1 actives the ADC, 0 disables it */
  19. #define TCS34725_ENABLE_PON                                                    \
  20.   (0x01) /**< Power on - Writing 1 activates the internal oscillator, 0        \
  21.             disables it */
  22. #define TCS34725_ATIME (0x01) /**< Integration time */
  23. #define TCS34725_WTIME                                                         \
  24.   (0x03) /**< Wait time (if TCS34725_ENABLE_WEN is asserted) */
  25. #define TCS34725_WTIME_2_4MS (0xFF) /**< WLONG0 = 2.4ms   WLONG1 = 0.029s */
  26. #define TCS34725_WTIME_204MS (0xAB) /**< WLONG0 = 204ms   WLONG1 = 2.45s  */
  27. #define TCS34725_WTIME_614MS (0x00) /**< WLONG0 = 614ms   WLONG1 = 7.4s   */
  28. #define TCS34725_AILTL                                                         \
  29.   (0x04) /**< Clear channel lower interrupt threshold (lower byte) */
  30. #define TCS34725_AILTH                                                         \
  31.   (0x05) /**< Clear channel lower interrupt threshold (higher byte) */
  32. #define TCS34725_AIHTL                                                         \
  33.   (0x06) /**< Clear channel upper interrupt threshold (lower byte) */
  34. #define TCS34725_AIHTH                                                         \
  35.   (0x07) /**< Clear channel upper interrupt threshold (higher byte) */
  36. #define TCS34725_PERS                                                          \
  37.   (0x0C) /**< Persistence register - basic SW filtering mechanism for          \
  38.             interrupts */
  39. #define TCS34725_PERS_NONE                                                     \
  40.   (0b0000) /**< Every RGBC cycle generates an interrupt */
  41. #define TCS34725_PERS_1_CYCLE                                                  \
  42.   (0b0001) /**< 1 clean channel value outside threshold range generates an     \
  43.               interrupt */
  44. #define TCS34725_PERS_2_CYCLE                                                  \
  45.   (0b0010) /**< 2 clean channel values outside threshold range generates an    \
  46.               interrupt */
  47. #define TCS34725_PERS_3_CYCLE                                                  \
  48.   (0b0011) /**< 3 clean channel values outside threshold range generates an    \
  49.               interrupt */
  50. #define TCS34725_PERS_5_CYCLE                                                  \
  51.   (0b0100) /**< 5 clean channel values outside threshold range generates an    \
  52.               interrupt */
  53. #define TCS34725_PERS_10_CYCLE                                                 \
  54.   (0b0101) /**< 10 clean channel values outside threshold range generates an   \
  55.               interrupt*/
  56. #define TCS34725_PERS_15_CYCLE                                                  \
  57.   (0b0110) /**< 15 clean channel values outside threshold range generates an   \
  58.               interrupt*/
  59. #define TCS34725_PERS_20_CYCLE                                                 \
  60.   (0b0111) /**< 20 clean channel values outside threshold range generates an   \
  61.               interrupt*/
  62. #define TCS34725_PERS_25_CYCLE                                                 \
  63.   (0b1000) /**< 25 clean channel values outside threshold range generates an   \
  64.               interrupt*/
  65. #define TCS34725_PERS_30_CYCLE                                                 \
  66.   (0b1001) /**< 30 clean channel values outside threshold range generates an   \
  67.               interrupt*/
  68. #define TCS34725_PERS_35_CYCLE                                                 \
  69.   (0b1010) /**< 35 clean channel values outside threshold range generates an   \
  70.               interrupt*/
  71. #define TCS34725_PERS_40_CYCLE                                                 \
  72.   (0b1011) /**< 40 clean channel values outside threshold range generates an   \
  73.               interrupt*/
  74. #define TCS34725_PERS_45_CYCLE                                                 \
  75.   (0b1100) /**< 45 clean channel values outside threshold range generates an   \
  76.               interrupt*/
  77. #define TCS34725_PERS_50_CYCLE                                                 \
  78.   (0b1101) /**< 50 clean channel values outside threshold range generates an   \
  79.               interrupt*/
  80. #define TCS34725_PERS_55_CYCLE                                                 \
  81.   (0b1110) /**< 55 clean channel values outside threshold range generates an   \
  82.               interrupt*/
  83. #define TCS34725_PERS_60_CYCLE                                                 \
  84.   (0b1111) /**< 60 clean channel values outside threshold range generates an   \
  85.               interrupt*/
  86. #define TCS34725_CONFIG (0x0D) /**< Configuration **/
  87. #define TCS34725_CONFIG_WLONG                                                  \
  88.   (0x02) /**< Choose between short and long (12x) wait times via               \
  89.             TCS34725_WTIME */
  90. #define TCS34725_CONTROL (0x0F) /**< Set the gain level for the sensor */
  91. #define TCS34725_ID                                                            \
  92.   (0x12) /**< 0x44 = TCS34721/TCS34725, 0x4D = TCS34723/TCS34727 */
  93. #define TCS34725_STATUS (0x13)      /**< Device status **/
  94. #define TCS34725_STATUS_AINT (0x10) /**< RGBC Clean channel interrupt */
  95. #define TCS34725_STATUS_AVALID                                                 \
  96.   (0x01) /**< Indicates that the RGBC channels have completed an integration   \
  97.             cycle */
  98. #define TCS34725_CDATAL (0x14) /**< Clear channel data low byte */
  99. #define TCS34725_CDATAH (0x15) /**< Clear channel data high byte */
  100. #define TCS34725_RDATAL (0x16) /**< Red channel data low byte */
  101. #define TCS34725_RDATAH (0x17) /**< Red channel data high byte */
  102. #define TCS34725_GDATAL (0x18) /**< Green channel data low byte */
  103. #define TCS34725_GDATAH (0x19) /**< Green channel data high byte */
  104. #define TCS34725_BDATAL (0x1A) /**< Blue channel data low byte */
  105. #define TCS34725_BDATAH (0x1B) /**< Blue channel data high byte */
  106.  
  107. #define SERVO_BASE 2
  108. #define SERVO_SLIDE 1
  109.  
  110. // CONFIG1H
  111. #pragma config OSC = INTIO67    // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
  112. #pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
  113. #pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
  114.  
  115. // CONFIG2L
  116. #pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
  117. #pragma config BOREN = OFF      // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
  118. #pragma config BORV = 3         // Brown Out Reset Voltage bits (Minimum setting)
  119.  
  120. // CONFIG2H
  121. #pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
  122. #pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)
  123.  
  124. // CONFIG3H
  125. #pragma config CCP2MX = PORTC   // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
  126. #pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
  127. #pragma config LPT1OSC = OFF    // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
  128. #pragma config MCLRE = OFF      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)
  129.  
  130. // CONFIG4L
  131. #pragma config STVREN = OFF      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
  132. #pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
  133. #pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
  134.  
  135. // CONFIG5L
  136. #pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
  137. #pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
  138. #pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
  139. #pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)
  140.  
  141. // CONFIG5H
  142. #pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
  143. #pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
  144.  
  145. // CONFIG6L
  146. #pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
  147. #pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
  148. #pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
  149. #pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)
  150.  
  151. // CONFIG6H
  152. #pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
  153. #pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
  154. #pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
  155.  
  156. // CONFIG7L
  157. #pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
  158. #pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
  159. #pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
  160. #pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
  161.  
  162. // CONFIG7H
  163. #pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)
  164.  
  165. // #pragma config statements should precede project file includes.
  166. // Use project enums instead of #define for ON and OFF.
  167.  
  168.  
  169. #endif  /* XC_sKITTLE_SORTER_H */
Add Comment
Please, Sign In to add comment