Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 341 → Rev 342

/PIC Projects/PICX_16F1829_Controller/defines.h
0,0 → 1,133
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
/* Pins Mapping
* 2 - RA5 - LSM303_DRDY
* 3 - RA4 - L3GD20_DRDY
* 5 - RC5 - UART_RX
* 6 - RC4 - UART TX
* 7 - RC3 - ADDR_3
* 8 - RC6 - BTN_CAP_0
* 9 - RC7 - BTN_CAP_1
* 10 - RB7 - SCL_2
* 11 - RB6 - SCL_1
* 12 - RB5 - SDA_2
* 13 - RB4 - SDA_1
* 14 - RC2 - ADDR_2
* 15 - RC1 - ADDR_1
* 16 - RC0 - ADDR_0
* 17 - RA2 - BTN_INT
*/
#define LSM303_INT_TRIS TRISAbits.TRISA5
#define L3GD20_INT_TRIS TRISAbits.TRISA4
#define UART_RX_TRIS TRISCbits.TRISC5
#define UART_TX_TRIS TRISCbits.TRISC4
 
#define BTN_INT_TRIS TRISAbits.TRISA2
 
#define I2C_ADDR_3_TRIS TRISCbits.TRISC3
#define I2C_ADDR_2_TRIS TRISCbits.TRISC2
#define I2C_ADDR_1_TRIS TRISCbits.TRISC1
#define I2C_ADDR_0_TRIS TRISCbits.TRISC0
 
#define I2C_ADDR_3_WPU WPUCbits.WPUC3
#define I2C_ADDR_2_WPU WPUCbits.WPUC2
#define I2C_ADDR_1_WPU WPUCbits.WPUC1
#define I2C_ADDR_0_WPU WPUCbits.WPUC0
 
#define I2C_ADDR_3_PORT PORTCbits.RC3
#define I2C_ADDR_2_PORT PORTCbits.RC2
#define I2C_ADDR_1_PORT PORTCbits.RC1
#define I2C_ADDR_0_PORT PORTCbits.RC0
 
#define I2C_1_CLK_TRIS TRISBbits.TRISB6
#define I2C_1_DAT_TRIS TRISBbits.TRISB4
 
#define I2C_2_CLK_TRIS TRISBbits.TRISB7
#define I2C_2_DAT_TRIS TRISBbits.TRISB5
 
#define CPS_R_TRIS TRISCbits.TRISC6
#define CPS_L_TRIS TRISCbits.TRISC7
#define CPS_R_ANSL ANSELCbits.ANSC6
#define CPS_L_ANSL ANSELCbits.ANSC7
#define CPS_R_WPU WPUCbits.WPUC6
#define CPS_L_WPU WPUCbits.WPUC7
 
// </editor-fold>
 
#define _XTAL_FREQ 32000000
 
#define CMD_QUERY_BTN 0x0A
#define CMD_SET_LEDS 0x0B
#define CMD_RESET 0x0C
#define CMD_ACTIVE 0x0D
 
#define OP_STATE_IDLE 0x10
#define OP_STATE_ACTIVE 0x20
 
#define RESET_POR 0x0
#define RESET_BOR 0x1
#define RESET_MCLR 0x2
#define RESET_WDT 0x3
#define RESET_RST 0x4
#define RESET_STK 0x5
 
#define I2C1_SLAVE_PREFIX 0x10
 
#define DIR_BRIGHTNESS 0x40
#define DIR_S 0x00
#define DIR_W 0x01
#define DIR_N 0x02
#define DIR_E 0x03
 
typedef union {
struct {
unsigned BTN_L_N :1;
unsigned BTN_L_E :1;
unsigned BTN_R_E :1;
unsigned BTN_R_N :1;
unsigned BTN_R_S :1;
unsigned BTN_R_W :1;
unsigned BTN_L_S :1;
unsigned BTN_L_W :1;
};
uint8_t w;
} BTN_STATUS;
 
typedef union {
struct {
uint8_t LED_0;
uint8_t LED_1;
uint8_t LED_2;
uint8_t LED_3;
uint8_t LED_4;
uint8_t LED_5;
uint8_t LED_6;
uint8_t LED_7;
uint8_t LED_N;
uint8_t LED_W;
uint8_t LED_E;
uint8_t LED_S;
uint8_t LED_A;
uint8_t LED_B;
uint8_t LED_C;
uint8_t LED_D;
} single;
uint8_t w[16];
} LED_VALUES;
 
void Reset_Board(uint8_t next_state);
uint8_t Get_Last_Reset(void);
 
void Check_I2C_Idle(void);
void Idle_Animation(void);
 
uint8_t Direction_Rotate_Clockwise(uint8_t);
uint8_t Direction_Rotate_CClockwise(uint8_t);
 
#endif /* DEFINES_H */