Subversion Repositories Code-Repo

Compare Revisions

No changes between revisions

Ignore whitespace Rev 341 → Rev 342

/PIC Projects/PICX_12F1840_Pulse_Generator/DEFINES.h
0,0 → 1,27
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include "stdint.h"
 
// UART TX on pin 7
#define UART_TX_TRIS TRISAbits.TRISA0
// UART RX on pin 6
#define UART_RX_TRIS TRISAbits.TRISA1
 
// CCP1 on pin 5
#define CCP1_TRIS TRISAbits.TRISA2
#define CCP1_LAT LATAbits.LATA2
 
// IOC on pin 4
#define IOC_TRIS TRISAbits.TRISA3
#define IOC_PORT PORTAbits.RA3
#define IOC_IOCAP IOCAPbits.IOCAP3
#define IOC_IOCAN IOCANbits.IOCAN3
#define IOC_IOCAF IOCAFbits.IOCAF3
 
// Oscillator on pins 2-3
#define _XTAL_FREQ 20000000
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_12F1840_Pulse_Generator/EUSART.c.c
0,0 → 1,103
#include "DEFINES.h"
#include "EUSART.h"
#include "INTERRUPTS.h"
 
static volatile uint8_t txBuffer[UART_TX_BUFFER_SIZE];
static volatile uint8_t txBufferSize = 0;
static volatile uint8_t txBufferIndex = 0;
 
static volatile uint8_t rxBuffer[UART_RX_BUFFER_SIZE];
static volatile uint8_t rxBufferSize = 0;
static volatile uint8_t rxBufferIndex = 0;
 
void UART_Init() {
UART_TX_TRIS = 0;
UART_RX_TRIS = 1;
 
BAUDCONbits.BRG16 = 0; // 8-bit baud rate generation
SPBRG = 64; // Baud rate of 19.2k
TXSTAbits.BRGH = 1; // High speed mode
 
TXSTAbits.SYNC = 0; // Async mode
RCSTAbits.SPEN = 1; // Serial port enable
 
TXSTAbits.TX9 = 0; // 8 bit transmission
RCSTAbits.RX9 = 0; // 8 bit reception
 
TXSTAbits.TXEN = 1; // Transmission enabled
RCSTAbits.CREN = 1; // Reception enabled
 
PIE1bits.TXIE = 0; // TX interrupt starts disabled
PIE1bits.RCIE = 1; // RX interrupt starts enabled
}
 
void UART_Write(uint8_t *msg, uint8_t length) {
// Check to make sure there is enough space in buffer for message
length = (length > UART_TX_BUFFER_SIZE) ? UART_TX_BUFFER_SIZE : length;
// Wait for previous message to finish sending
while (PIE1bits.TXIE);
 
txBufferSize = length;
txBufferIndex = 1;
for (uint8_t i = 0; i < length; i++) {
txBuffer[i] = msg[i];
}
TXREG = txBuffer[0];
PIE1bits.TXIE = 1;
}
 
void UART_TX_Interrupt_Handler() {
if (txBufferIndex != txBufferSize) {
// Transmit next byte in the buffer
TXREG = txBuffer[txBufferIndex];
txBufferIndex++;
} else {
// Wait for last byte to finish sending
while (!TXSTAbits.TRMT);
PIE1bits.TXIE = 0;
txBufferSize = 0;
txBufferIndex = 0;
}
}
 
void UART_RX_Interrupt_Handler() {
if (PIR1bits.RCIF) {
uint8_t c = RCREG;
 
// Store received byte into buffer and increment write location
rxBuffer[rxBufferIndex] = c;
if (rxBufferIndex == UART_RX_BUFFER_SIZE - 1) {
rxBufferIndex = 0;
} else {
rxBufferIndex++;
}
 
// Increment received byte count
if (rxBufferSize < UART_RX_BUFFER_SIZE) {
rxBufferSize++;
}
}
 
// If UART overrun is detected, reset module
if (RCSTAbits.OERR) {
TXSTAbits.TXEN = 0;
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
}
 
uint8_t UART_Read(uint8_t *buffer) {
// Return values in RX buffer
uint8_t size = rxBufferSize;
for (uint8_t i = 0; i < size; i++) {
buffer[i] = rxBuffer[i];
}
 
return size;
}
 
void UART_Reset_RX() {
rxBufferIndex = 0;
rxBufferSize = 0;
}
/PIC Projects/PICX_12F1840_Pulse_Generator/EUSART.h
0,0 → 1,15
#ifndef EUSART_H
#define EUSART_H
 
#define UART_TX_BUFFER_SIZE 32
#define UART_RX_BUFFER_SIZE 32
 
void UART_Init();
void UART_Write(uint8_t *msg, uint8_t length);
uint8_t UART_Read(uint8_t *buffer);
void UART_Reset_RX();
void UART_TX_Interrupt_Handler();
void UART_RX_Interrupt_Handler();
 
#endif /* EUSART_H */
 
/PIC Projects/PICX_12F1840_Pulse_Generator/INTERRUPTS.c
0,0 → 1,39
#include "DEFINES.h"
#include "INTERRUPTS.h"
#include "IOC.h"
#include "EUSART.h"
 
void Interrupt_Enable() {
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
}
 
void interrupt InterruptHandler(void) {
 
// Check for an IOC interrupt
if (INTCONbits.IOCIF) {
IOC_Interrupt_Handler();
INTCONbits.IOCIF = 0;
return;
}
 
// Check to see if we have an interrupt on USART1 RX
if (PIR1bits.RCIF) {
UART_RX_Interrupt_Handler();
PIR1bits.RCIF = 0;
return;
}
 
// Check to see if we have an interrupt on USART1 TX
if (PIR1bits.TXIF) {
UART_TX_Interrupt_Handler();
// PIR1bits.TXIF = 0;
return;
}
 
}
/PIC Projects/PICX_12F1840_Pulse_Generator/INTERRUPTS.h
0,0 → 1,12
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_12F1840_Pulse_Generator/IOC.c
0,0 → 1,23
#include "DEFINES.h"
#include "IOC.h"
#include "PWM.h"
 
void IOC_Init() {
// Enable global IOC interrupt
INTCONbits.IOCIE = 1;
 
IOC_TRIS = 1;
 
// Enable IOC on rising edge only
IOC_IOCAP = 0;
IOC_IOCAN = 1;
}
 
void IOC_Interrupt_Handler() {
// Transmit the saved pattern
if (IOC_IOCAF)
PWM_Transmit_Pattern();
 
// Clear all status flags
IOC_IOCAF = 0;
}
/PIC Projects/PICX_12F1840_Pulse_Generator/IOC.h
0,0 → 1,8
#ifndef IOC_H
#define IOC_H
 
void IOC_Init();
void IOC_Interrupt_Handler();
 
#endif /* IOC_H */
 
/PIC Projects/PICX_12F1840_Pulse_Generator/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_12F1840_Pulse_Generator/PWM.c
0,0 → 1,355
#include "PWM.h"
#include "INTERRUPTS.h"
 
static volatile uint8_t computedFrequency = 0;
static volatile uint8_t computedDutyCycleHigh_UpperByte = 0;
static volatile uint8_t computedDutyCycleHigh_LowerBits = 0;
static volatile uint8_t computedDutyCycleLow_UpperByte = 0;
static volatile uint8_t computedDutyCycleLow_LowerBits = 0;
static volatile uint8_t savedDutyCycleHigh = PWM_DEFAULT_HIGH_CYCLE;
static volatile uint8_t savedDutyCycleLow = PWM_DEFAULT_LOW_CYCLE;
static volatile uint16_t savedPattern = 0xAAAA;
 
void PWM_Init() {
// Initialize CCP1 / Timer 2
CCP1_TRIS = 1; // PWM output starts disabled
CCP1CONbits.P1M = 0b00; // Single output, P1A modulated only
CCP1CONbits.CCP1M = 0b1100; // PWM Mode, P1A active-high, P1B active-high
PIR1bits.TMR2IF = 0; // Clear Timer 2 interrupt flag
TMR2 = 0x0;
 
Set_PWM_Frequency(PWM_DEFAULT_FREQ);
Set_PWM_Duty_Cycle(PWM_DEFAULT_HIGH_CYCLE, PWM_DEFAULT_LOW_CYCLE);
}
 
void Set_PWM_Frequency(uint32_t frequency) {
// Timer 2 clocked at FOSC/4 (20 Mhz)
// Prescaler 1:1 = minimum frequency of 19,532 Hz
// Prescaler 1:4 = minimum frequency of 4,883 Hz
// Prescaler 1:16 = minimum frequency of 1,221 Hz
// Prescaler 1:64 = minimum frequency of 306 Hz
 
// PWM Period = [PR2 + 1] * 4 * TOSC * Prescale
// = [PR2 + 1] * 4 * (1/FOSC) * Prescale
// = ([PR2 + 1] * 4 * Prescale) / FOSC
// PWM Freq = 1/(PWM Period)
// = 1/(PR2 + 1) * 1/4 * FOSC * 1/Prescale)
// = FOSC / ([PR2 + 1] * 4 * Prescale)
// PR2 = (FOSC / [(PWM Freq) * 4 * Presccale]) - 1
 
uint8_t preScaleValue;
if (frequency > 19532) {
preScaleValue = 1;
T2CONbits.T2CKPS = 0b00;
} else if (frequency > 4883) {
preScaleValue = 4;
T2CONbits.T2CKPS = 0b01;
} else if (frequency > 1221) {
preScaleValue = 16;
T2CONbits.T2CKPS = 0b10;
} else {
preScaleValue = 64;
T2CONbits.T2CKPS = 0b11;
}
 
uint32_t tmp = frequency * 4 * preScaleValue;
computedFrequency = (_XTAL_FREQ / tmp) - 1;
 
// Updated duty cycle
Set_PWM_Duty_Cycle(savedDutyCycleHigh, savedDutyCycleLow);
}
 
void Set_PWM_Duty_Cycle(uint8_t highPercent, uint8_t lowPercent) {
// Duty cycle specified by 10 bit value in CCPR1L:DC1B<1:0>
savedDutyCycleHigh = highPercent;
savedDutyCycleLow = lowPercent;
 
// Compute values to store in register
uint32_t highValue = (computedFrequency + 1) * 4;
highValue *= highPercent;
highValue /= 100;
computedDutyCycleHigh_LowerBits = highValue & 0x3;
computedDutyCycleHigh_UpperByte = (highValue >> 2) & 0xFF;
 
uint32_t lowValue = (computedFrequency + 1) * 4;
lowValue *= lowPercent;
lowValue /= 100;
computedDutyCycleLow_LowerBits = lowValue & 0x3;
computedDutyCycleLow_UpperByte = (lowValue >> 2) & 0xFF;
}
 
void Set_PWM_Pattern(uint16_t pattern) {
savedPattern = pattern;
}
 
void PWM_Transmit_Pattern() {
// Set PWM frequency pre-computed values
PR2 = computedFrequency;
 
// Set duty cycle to 0%
CCP1CONbits.DC1B = 0b00;
CCPR1L = 0x00;
 
// Start timer and wait for it to rollover to latch duty cycle value
T2CONbits.TMR2ON = 1;
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
CCP1_TRIS = 0;
 
// Bit 15
if (savedPattern & 0x8000) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
/* The above section of code disassembles to the following assembly code
* According to the instruction set table, this should take 22 cycles to execute
* 22 cycles corresponds to a maximum of ~227.272 kHz PWM frequency
* If higher PWM frequency is needed, DC1B can be omitted for lower duty cycle accuracy
! if (pattern & 0x8000) {
0x26: BTFSS 0x72, 0x7
0x27: GOTO 0x34
! CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
0x28: MOVLB 0x0
0x29: MOVF computedDutyCycleHigh_LowerBits, W
0x2A: MOVWF 0x73
0x2B: SWAPF 0x73, F
0x2C: MOVLB 0x5
0x2D: MOVF CCP1CON, W
0x2E: XORWF 0x2F3, W
0x2F: ANDLW 0xCF
0x30: XORWF 0x2F3, W
0x31: MOVWF CCP1CON
! CCPR1L = computedDutyCycleHigh_UpperByte;
0x32: MOVF computedDutyCycleHigh_UpperByte, W
0x33: GOTO 0x41
! } else {
! CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
0x34: MOVLB 0x0
0x35: MOVF computedDutyCycleLow_LowerBits, W
0x36: MOVWF 0x73
0x37: SWAPF 0x73, F
0x38: MOVLB 0x5
0x39: MOVF CCP1CON, W
0x3A: XORWF 0x2F3, W
0x3B: ANDLW 0xCF
0x3C: XORWF 0x2F3, W
0x3D: MOVWF CCP1CON
! CCPR1L = computedDutyCycleLow_UpperByte;
0x3E: MOVLB 0x0
0x3F: MOVF computedDutyCycleLow_UpperByte, W
0x40: MOVLB 0x5
0x41: MOVWF CCPR1
! }
! while (!PIR1bits.TMR2IF);
0x42: MOVLB 0x0
0x43: BTFSS PIR1, 0x1
0x44: GOTO 0x42
! PIR1bits.TMR2IF = 0;
0x45: BCF PIR1, 0x1
 
* If DC1B is ignored, the disassembly is as follows:
* According to the instruction set table, this should take 14 cycles to execute
* 14 cycles corresponds to a maximum of ~357.142 kHz PWM frequency
! // Bit 15
! if (pattern & 0x8000) {
0x26: BTFSS 0x72, 0x7
0x27: GOTO 0x2A
! CCPR1L = computedDutyCycleHigh_UpperByte;
0x28: MOVF computedDutyCycleHigh_UpperByte, W
0x29: GOTO 0x2C
! } else {
! CCPR1L = computedDutyCycleLow_UpperByte;
0x2A: MOVLB 0x0
0x2B: MOVF computedDutyCycleLow_UpperByte, W
0x2C: MOVLB 0x5
0x2D: MOVWF CCPR1
! }
! while (!PIR1bits.TMR2IF);
0x2E: MOVLB 0x0
0x2F: BTFSS PIR1, 0x1
0x30: GOTO 0x2E
! PIR1bits.TMR2IF = 0;
0x31: BCF PIR1, 0x1
*/
 
// Bit 14
if (savedPattern & 0x4000) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 13
if (savedPattern & 0x2000) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 12
if (savedPattern & 0x1000) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 11
if (savedPattern & 0x0800) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 10
if (savedPattern & 0x0400) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 9
if (savedPattern & 0x0200) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 8
if (savedPattern & 0x0100) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 7
if (savedPattern & 0x0080) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 6
if (savedPattern & 0x0040) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 5
if (savedPattern & 0x0020) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 4
if (savedPattern & 0x0010) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 3
if (savedPattern & 0x0008) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 2
if (savedPattern & 0x0004) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 1
if (savedPattern & 0x0002) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Bit 0
if (savedPattern & 0x0001) {
CCP1CONbits.DC1B = computedDutyCycleHigh_LowerBits;
CCPR1L = computedDutyCycleHigh_UpperByte;
} else {
CCP1CONbits.DC1B = computedDutyCycleLow_LowerBits;
CCPR1L = computedDutyCycleLow_UpperByte;
}
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
 
// Set next duty cycle to 0% (idle line low)
CCP1CONbits.DC1B = 0b00;
CCPR1L = 0x00;
 
// Wait for timer to rollover, then turn off timer
while (!PIR1bits.TMR2IF);
PIR1bits.TMR2IF = 0;
T2CONbits.TMR2ON = 0;
TMR2 = 0x0;
}
/PIC Projects/PICX_12F1840_Pulse_Generator/PWM.h
0,0 → 1,17
#ifndef PWM_H
#define PWM_H
 
#include "DEFINES.h"
 
#define PWM_DEFAULT_FREQ 50000
#define PWM_DEFAULT_HIGH_CYCLE 80
#define PWM_DEFAULT_LOW_CYCLE 20
 
void PWM_Init();
void Set_PWM_Frequency(uint32_t frequency);
void Set_PWM_Duty_Cycle(uint8_t highPercent, uint8_t lowPercent);
void Set_PWM_Pattern(uint16_t pattern);
void PWM_Transmit_Pattern();
 
#endif /* PWM_H */
 
/PIC Projects/PICX_12F1840_Pulse_Generator/funclist
0,0 → 1,20
_IOC_Interrupt_Handler: CODE, 1756 0 8
_UART_Read: CODE, 1633 0 33
_IOC_Init: CODE, 1771 0 7
_UART_Init: CODE, 1725 0 18
_UART_Reset_RX: CODE, 1790 0 4
_main: CODE, 621 0 398
_Interrupt_Enable: CODE, 1794 0 3
_Set_PWM_Frequency: CODE, 1236 0 158
_Set_PWM_Duty_Cycle: CODE, 1019 0 217
_InterruptHandler: CODE, 4 0 29
___lmul: CODE, 1542 0 48
_UART_TX_Interrupt_Handler: CODE, 1698 0 27
__initialization: CODE, 35 0 44
_Set_PWM_Pattern: CODE, 1764 0 7
___lldiv: CODE, 1394 0 83
_PWM_Transmit_Pattern: CODE, 83 0 538
_UART_RX_Interrupt_Handler: CODE, 1590 0 43
_UART_Write: CODE, 1477 0 65
_PWM_Init: CODE, 1666 0 32
Total: 1762
/PIC Projects/PICX_12F1840_Pulse_Generator/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_12F1840_Pulse_Generator/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_12F1840_Pulse_Generator/main.c
0,0 → 1,120
#include "DEFINES.h"
#include "INTERRUPTS.h"
#include "PWM.h"
#include "IOC.h"
#include "EUSART.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
// CONFIG1
#pragma config FOSC = HS // Oscillator Selection (HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
int main() {
// Initialize oscillator to external crystal (20Mhz)
OSCCONbits.SCS = 0b00;
OSCCONbits.SPLLEN = 0b0;
OSCCONbits.IRCF = 0b1111;
 
// Set all pins to digital I/O
ANSELA = 0x00;
// Disable pull-ups
OPTION_REGbits.nWPUEN = 1;
WPUA = 0x0;
 
// Configure alternate pin function register
APFCONbits.RXDTSEL = 0; // RX on RA1
APFCONbits.TXCKSEL = 0; // TX on RA0
APFCONbits.CCP1SEL = 0; // CCP1 on RA2
// Delay for a bit to ensure oscillator has started
__delay_ms(10);
 
// Configure and enable interrupts
Interrupt_Enable();
 
// Configure and enable peripherals
PWM_Init();
IOC_Init();
UART_Init();
 
uint8_t recvBuffer[32];
uint8_t txOk[] = "Ok!\n";
uint8_t txError[] = "Error!\n";
 
/* Protocol format as follows:
* Byte 0 = OPCODE
* 0x1 = Set frequency
* Bytes 1-4 = 32 bit unsigned value
* 0x2 = Set duty cycle
* Byte 1 = 8 bit unsigned value (high value)
* Byte 2 = 8 bit unsigned value (low value)
* 0x3 = Set pattern
* Bytes 1-2 = 16 bit pattern (transmits MSB first)
* Everything else = nop
*/
 
while(1) {
uint8_t recvBytes = UART_Read(recvBuffer);
if (recvBytes != 0) {
// Process op-code for setting frequency
if (recvBuffer[0] == 0x1 && recvBytes == 5) {
uint32_t byte0 = recvBuffer[1];
byte0 <<= 24;
uint32_t byte1 = recvBuffer[2];
byte1 <<= 16;
uint32_t byte2 = recvBuffer[3];
byte2 <<= 8;
uint32_t freq = 0;
freq |= byte0;
freq |= byte1;
freq |= byte2;
freq |= recvBuffer[4];
// Ensure that received value falls within working bounds
if (freq >= 20000 && freq <= 200000) {
Set_PWM_Frequency(freq);
UART_Write(txOk, 4);
} else {
UART_Write(txError, 7);
}
UART_Reset_RX();
} else if (recvBuffer[0] == 0x2 && recvBytes == 3) {
// Ensure that received value falls within working bounds
if (recvBuffer[1] <= 100 && recvBuffer[2] <= 100) {
Set_PWM_Duty_Cycle(recvBuffer[1], recvBuffer[2]);
UART_Write(txOk, 4);
} else {
UART_Write(txError, 7);
}
UART_Reset_RX();
} else if (recvBuffer[0] == 0x3 && recvBytes == 3) {
uint16_t byte0 = recvBuffer[1];
byte0 <<= 8;
uint16_t pattern = 0;
pattern |= byte0;
pattern |= recvBuffer[2];
Set_PWM_Pattern(pattern);
UART_Reset_RX();
UART_Write(txOk, 4);
} else if (recvBuffer[0] == 0x0 || recvBuffer[0] > 0x03 || recvBytes > 5) {
UART_Reset_RX();
}
}
}
 
}
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Makefile-default.mk
0,0 → 1,207
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c PWM.c IOC.c INTERRUPTS.c EUSART.c.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/PWM.p1 ${OBJECTDIR}/IOC.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/EUSART.c.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/PWM.p1.d ${OBJECTDIR}/IOC.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/EUSART.c.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/PWM.p1 ${OBJECTDIR}/IOC.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/EUSART.c.p1
 
# Source Files
SOURCEFILES=main.c PWM.c IOC.c INTERRUPTS.c EUSART.c.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
ifneq ($(INFORMATION_MESSAGE), )
@echo $(INFORMATION_MESSAGE)
endif
${MAKE} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=12F1840
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/PWM.p1: PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM.p1.d
@${RM} ${OBJECTDIR}/PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/PWM.p1 PWM.c
@-${MV} ${OBJECTDIR}/PWM.d ${OBJECTDIR}/PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/EUSART.c.p1: EUSART.c.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/EUSART.c.p1.d
@${RM} ${OBJECTDIR}/EUSART.c.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/EUSART.c.p1 EUSART.c.c
@-${MV} ${OBJECTDIR}/EUSART.c.d ${OBJECTDIR}/EUSART.c.p1.d
@${FIXDEPS} ${OBJECTDIR}/EUSART.c.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/PWM.p1: PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM.p1.d
@${RM} ${OBJECTDIR}/PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/PWM.p1 PWM.c
@-${MV} ${OBJECTDIR}/PWM.d ${OBJECTDIR}/PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/EUSART.c.p1: EUSART.c.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/EUSART.c.p1.d
@${RM} ${OBJECTDIR}/EUSART.c.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -o${OBJECTDIR}/EUSART.c.p1 EUSART.c.c
@-${MV} ${OBJECTDIR}/EUSART.c.d ${OBJECTDIR}/EUSART.c.p1.d
@${FIXDEPS} ${OBJECTDIR}/EUSART.c.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" --ram=default,-160-16f -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Thu Dec 25 22:06:48 EST 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.33\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=f654f11d585cacf70b570c49f2939b4c
default.languagetoolchain.version=1.33
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=4e74752607bed54c97e500c96f68559c
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_12F1840_Pulse_Generator
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_67/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
MP_AS="C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe"
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.33\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
MP_AS_DIR="C:\Program Files (x86)\Microchip\xc8\v1.33\bin"
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_12F1840_Pulse_Generator.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_12F1840_Pulse_Generator.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx12f1840pulsegenerator.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx12f1840pulsegenerator.tar
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_12F1840_Pulse_Generator.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx12f1840pulsegenerator/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx12f1840pulsegenerator/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx12f1840pulsegenerator.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx12f1840pulsegenerator.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/configurations.xml
0,0 → 1,183
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>DEFINES.h</itemPath>
<itemPath>PWM.h</itemPath>
<itemPath>IOC.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>EUSART.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>PWM.c</itemPath>
<itemPath>IOC.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>EUSART.c.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC12F1840</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.33</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<archiverTool>
</archiverTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<parseOnProdLoad>true</parseOnProdLoad>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-invariant-enable" value="false"/>
<property key="optimization-invariant-value" value="16"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.configurationmemory2" value="true"/>
<property key="memories.dataflash" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0xfff"/>
<property key="memories.programmemory.partition2" value="true"/>
<property key="memories.programmemory.partition2.end"
value="${memories.programmemory.partition2.end.value}"/>
<property key="memories.programmemory.partition2.start"
value="${memories.programmemory.partition2.start.value}"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.donoteraseauxmem" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preservedataflash" value="false"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0xfff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.programcalmem" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Tue Dec 23 16:56:45 EST 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.33\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/private/private.properties
--- PICX_12F1840_Pulse_Generator/nbproject/private/private.xml (nonexistent)
+++ PICX_12F1840_Pulse_Generator/nbproject/private/private.xml (revision 342)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
/PIC Projects/PICX_12F1840_Pulse_Generator/nbproject/project.properties
--- PICX_12F1840_Pulse_Generator/nbproject/project.xml (nonexistent)
+++ PICX_12F1840_Pulse_Generator/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_12F1840_Pulse_Generator</name>
+ <creation-uuid>495ff268-917c-471d-9732-acf0852821c2</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <asminc-extensions/>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/HT16K33.c
0,0 → 1,132
#include "HT16K33.h"
#include "I2C1.h"
 
static const uint8_t numbertable[] = {
0x3F /* 0 */,
0x06 /* 1 */,
0x5B /* 2 */,
0x4F /* 3 */,
0x66 /* 4 */,
0x6D /* 5 */,
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F, /* 9 */
};
 
static const uint8_t alphatable[] = {
0x77, /* a */
0x7C, /* b */
0x39, /* C */
0x5E, /* d */
0x79, /* E */
0x71, /* F */
};
 
static LED_DATA *led_data_p;
 
void LED_Init(LED_DATA *data) {
led_data_p = data;
led_data_p->i2c_address = HT16K33_ADDRESS;
}
 
void LED_Start() {
uint8_t c = 0x21; // Cmd to turn on oscillator
I2C1_Master_Send(led_data_p->i2c_address, &c, 1);
uint8_t result = I2C1_Get_Status();
while (!result) {
result = I2C1_Get_Status();
}
 
LED_Blink_Rate(HT16K33_BLINK_OFF);
LED_Set_Brightness(15); // Max brightness
LED_Clear();
LED_Write_Display();
}
 
void LED_Set_Brightness(uint8_t c) {
if (c > 15) c = 15;
c |= 0xE0;
 
I2C1_Master_Send(led_data_p->i2c_address, &c, 1);
uint8_t result = I2C1_Get_Status();
while (!result) {
result = I2C1_Get_Status();
}
}
 
void LED_Blink_Rate(uint8_t c) {
uint8_t buffer;
 
if (c > 3) c = 0;
 
buffer = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (c << 1);
 
I2C1_Master_Send(led_data_p->i2c_address, &buffer, 1);
buffer = I2C1_Get_Status();
while (!buffer) {
buffer = I2C1_Get_Status();
}
}
 
void LED_Write_Display() {
led_data_p->display_buffer[0] = 0x00; // Start at address 0x00
I2C1_Master_Send(led_data_p->i2c_address, led_data_p->display_buffer, 17);
 
uint8_t result = I2C1_Get_Status();
while (!result) {
result = I2C1_Get_Status();
}
}
 
void LED_Clear() {
for (uint8_t c = 0; c < 17; c++) {
led_data_p->display_buffer[c] = 0;
}
}
 
void LED_Draw_Colon(uint8_t c) {
if (c) {
led_data_p->display_buffer[5] = 0xFF;
} else {
led_data_p->display_buffer[5] = 0;
}
}
 
void LED_Write_Digit_Raw(uint8_t loc, uint8_t bitmask) {
if (loc > 4) return;
led_data_p->display_buffer[(loc<<1)+1] = bitmask;
}
 
void LED_Write_Digit_Num(uint8_t loc, uint8_t num, uint8_t dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, numbertable[num] | dot << 7);
}
 
void LED_Write_Digit_Alpha(uint8_t loc, uint8_t alpha, uint8_t dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, alphatable[alpha] | dot << 7);
}
 
void LED_Write_Num(uint16_t i) {
LED_Write_Digit_Num(0, (i%10000)/1000, 0);
LED_Write_Digit_Num(1, (i%1000)/100, 0);
LED_Write_Digit_Num(2, (i%100)/10, 0);
LED_Write_Digit_Num(3, i%10, 0);
 
if (i < 10) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
LED_Write_Digit_Raw(3, 0);
} else if (i < 100) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
} else if (i < 1000) {
LED_Write_Digit_Raw(0, 0);
}
LED_Write_Display();
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/HT16K33.h
0,0 → 1,36
#ifndef LED_BACKPACK_H
#define LED_BACKPACK_H
 
#include "defines.h"
 
#define HT16K33_ADDRESS 0x70
 
#define HT16K33_BLINK_CMD 0x80
#define HT16K33_BLINK_DISPLAYON 0x01
#define HT16K33_BLINK_OFF 0
#define HT16K33_BLINK_2HZ 1
#define HT16K33_BLINK_1HZ 2
#define HT16K33_BLINK_HALFHZ 3
 
#define HT16K33_CMD_BRIGHTNESS 0x0E
 
typedef struct {
uint8_t i2c_address;
uint8_t display_buffer[17];
} LED_DATA;
 
void LED_Init(LED_DATA *data);
void LED_Start(void);
void LED_Set_Brightness(uint8_t c);
void LED_Blink_Rate(uint8_t c);
void LED_Write_Display(void);
void LED_Clear(void);
void LED_Draw_Colon(uint8_t c);
void LED_Write_Digit_Raw(uint8_t loc, uint8_t bitmask);
void LED_Write_Digit_Num(uint8_t loc, uint8_t num, uint8_t dot);
void LED_Write_Digit_Alpha(uint8_t loc, uint8_t alpha, uint8_t dot);
void LED_Write_Num(uint16_t i);
 
 
#endif /* LED_BACKPACK_H */
 
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/I2C1.c
0,0 → 1,534
#include "defines.h"
#include "I2C1.h"
 
static I2C1_DATA *i2c_data_p;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(I2C1_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint8_t length) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, &c, 1);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C1_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1ADD = addr << 1; // Set the slave address
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x6; // Enable Slave 7-bit address
SSP1STATbits.SMP = 1; // Slew Off
SSP1CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON3bits.PCIE = 1; // Interrupt on stop condition
SSP1CON3bits.SCIE = 0; // Disable interrupt on start condition
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
void I2C1_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C1_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C1_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C1_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSP1BUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C1_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSP1CON1bits.SSPOV == 1) {
SSP1CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP1STATbits.BF == 1) {
received_data = SSP1BUF;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// // Ignore anything except a start
// if (SSP1STATbits.S == 1) {
// i2c_data_p->buffer_in_len_tmp = 0;
// i2c_data_p->operating_state = I2C_STARTED;
// }
// break;
// }
// case I2C_STARTED:
// {
// In this case, we expect either an address or a stop bit
if (SSP1STATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
i2c_data_p->buffer_in_len_tmp = 0;
if (SSP1STATbits.D_nA == 0) {
// Address received
if (SSP1STATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NOADDR;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C1_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP1BUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSP1BUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP1STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP1STATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP1CON1bits.CKP == 0) {
SSP1CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C1_Process_Receive(uint8_t c) {
uint8_t ret = 0;
 
return ret;
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/I2C1.h
0,0 → 1,82
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 32
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2C1BUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C1_DATA;
 
void I2C1_Init(I2C1_DATA *data);
void I2C1_Interrupt_Handler(void);
void I2C1_Interrupt_Slave(void);
void I2C1_Interrupt_Master(void);
void I2C1_Configure_Slave(uint8_t address);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint8_t length);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
uint8_t I2C1_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/INTERRUPTS.c
0,0 → 1,71
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "UART.h"
#include "IOC.h"
 
void Interrupt_Init() {
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// Check to see if we have an I2C interrupt
if (PIR1bits.SSP1IF) {
 
// Call the handler
I2C1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSP1IF = 0;
 
// return;
}
// Check for an IOC interrupt
if (INTCONbits.IOCIF) {
 
// Call the handler
IOC_Interrupt_Handler();
 
// Clear the interrupt flag
INTCONbits.IOCIF = 0;
 
// return;
}
// if (PIR1bits.RCIF) {
//
// // Call the handler
// UART_RX_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.RCIF = 0;
//
// return;
// }
 
// if (PIR1bits.TXIF) {
//
// // Call the handler
// UART_TX_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.TXIF = 0;
//
// return;
// }
 
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/IOC.c
0,0 → 1,32
#include "defines.h"
#include "IOC.h"
 
static IOC_DATA *data_p;
 
void IOC_Init(IOC_DATA *data, void (*callback)(void)) {
data_p = data;
data_p->ioc_callback = callback;
 
INTCONbits.IOCIE = 0;
 
// Enable interrupt on rising edge on RA4
IOCAPbits.IOCAP4 = 1;
}
 
void IOC_Enable(void) {
IOC_Clear();
INTCONbits.IOCIE = 1;
}
 
void IOC_Disable(void) {
INTCONbits.IOCIE = 0;
IOC_Clear();
}
 
void IOC_Clear(void) {
IOCAF = 0x0;
}
 
void IOC_Interrupt_Handler(void) {
data_p->ioc_callback();
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/IOC.h
0,0 → 1,15
#ifndef IOC_H
#define IOC_H
 
typedef struct {
void (*ioc_callback)(void);
} IOC_DATA;
 
void IOC_Init(IOC_DATA *data, void (*callback)(void));
void IOC_Enable(void);
void IOC_Disable(void);
void IOC_Clear(void);
void IOC_Interrupt_Handler(void);
 
#endif /* IOC_H */
 
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/SMT6500.c
0,0 → 1,41
#include "defines.h"
#include "SMT6500.h"
#include "TIMER.h"
#include "IOC.h"
 
static uint16_t tmr_value;
 
void SMT6500_Init(void) {
BLNK_LAT = 0;
INIT_LAT = 0;
BINH_LAT = 0;
}
 
uint16_t SMT6500_Read(void) {
// Start transmission and timer
INIT_LAT = 1;
TIMER1_Start();
tmr_value = 0;
// Enable interrupt after 1ms (blanking period)
__delay_ms(1);
IOC_Enable();
__delay_ms(120);
INIT_LAT = 0;
IOC_Disable();
TIMER1_Stop();
 
 
if (tmr_value == 0) {
return 0xFFFF;
} else {
return tmr_value;
}
}
 
void SMT6500_Callback(void) {
tmr_value = TIMER1_Read();
IOC_Disable();
TIMER1_Stop();
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/SMT6500.h
0,0 → 1,9
#ifndef SMT6500_H
#define SMT6500_H
 
void SMT6500_Init(void);
uint16_t SMT6500_Read(void);
void SMT6500_Callback(void);
 
#endif /* SMT6500_H */
 
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/TIMER.c
0,0 → 1,43
#include "defines.h"
#include "TIMER.h"
 
void TIMER1_Init(void) {
T1CONbits.TMR1CS = 0x0; // Clock source is instruction clock
T1CONbits.T1CKPS = 0x3; // Prescale of 1:8
T1CONbits.T1OSCEN = 0x0; // Dedicated oscillator circuit disabled
T1CONbits.nT1SYNC = 0x0; // Sync clock input with system clock
T1CONbits.TMR1ON = 0; // Timer starts off
T1GCONbits.TMR1GE = 0; // Gate disabled
TMR1 = 0x0;
 
PIE1bits.TMR1IE = 0; // Interrupt disabled
 
// Instruction clock running at 8MHz
// 1:1 Prescale overflows at 122Hz (8.2ms period)
// 1:2 Prescale overflows at 61Hz (16.4ms period)
// 1:4 Prescale overflows at 30.5Hz (32.7ms period)
// 1:8 Prescale overflows at 15.3Hz (65.5ms period)
 
// Instruction clock running at 4MHz
// 1:1 Prescale overflows at 61Hz (16.4ms period)
// 1:2 Prescale overflows at 30.5Hz (32.7ms period)
// 1:4 Prescale overflows at 15.3Hz (65.5ms period)
// 1:8 Prescale overflows at 7.6Hz (131.1ms period)
}
 
void TIMER1_Start(void) {
TMR1 = 0x0;
T1CONbits.TMR1ON = 1;
}
 
void TIMER1_Stop(void) {
T1CONbits.TMR1ON = 0;
}
 
uint16_t TIMER1_Read(void) {
return TMR1;
}
 
void TIMER1_Interrupt_Handler(void) {
 
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/TIMER.h
0,0 → 1,11
#ifndef TIMER_H
#define TIMER_H
 
void TIMER1_Init(void);
void TIMER1_Start(void);
void TIMER1_Stop(void);
uint16_t TIMER1_Read(void);
void TIMER1_Interrupt_Handler(void);
 
#endif /* TIMER_H */
 
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/UART.c
0,0 → 1,106
#include <xc.h>
#include "defines.h"
#include "UART.h"
 
static UART_DATA *data_ptr;
 
void UART_Init(UART_DATA *data) {
data_ptr = data;
 
APFCON0bits.RXDTSEL = 1; // Change RX from RB5 to RC5
APFCON0bits.TXCKSEL = 1; // Change TX from RB7 to RC4
UART_RX_TRIS = 1;
UART_TX_TRIS = 0;
 
SPBRG = 16; // Set baud rate to 115200 @ 32MHz
BAUDCONbits.BRG16 = 0; // 8-bit baud rate generator
TXSTAbits.BRGH = 1; // High baud rate select
 
TXSTAbits.SYNC = 0; // Async operation
RCSTAbits.CREN = 1; // Enable reception module
TXSTAbits.TXEN = 1; // Enable transmission module
RCSTAbits.SPEN = 1; // Enable EUSART module
 
PIE1bits.RCIE = 1; // UART RX interrupt starts enabled
PIE1bits.TXIE = 0; // UART TX interrupt starts disabled
 
// Initialize local variables
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
data_ptr->buffer_in_len = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
 
void UART_TX_Interrupt_Handler(void) {
// Send more data when transmit buffer is empty
if (data_ptr->buffer_out_ind != data_ptr->buffer_out_len) {
TXREG = data_ptr->buffer_out[data_ptr->buffer_out_ind];
data_ptr->buffer_out_ind++;
} else {
// Stop processing TX interrupts if there is no more data to send
while (!TXSTAbits.TRMT);
PIE1bits.TXIE = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
}
 
void UART_RX_Interrupt_Handler(void) {
char c = RCREG;
 
// Read received data into buffer
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = c;
if (data_ptr->buffer_in_write_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_write_ind = 0;
} else {
data_ptr->buffer_in_write_ind++;
}
 
// Increment read counter to keep only the latest data
if (data_ptr->buffer_in_len < UART_BUFFER_SIZE) {
data_ptr->buffer_in_len++;
} else {
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
 
// Reset receiver module on overrun error
if (RCSTAbits.OERR == 1) {
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
}
 
void UART_Write(char *data, char length) {
// Ensure that no transmission is currently running
while (PIE1bits.TXIE);
 
data_ptr->buffer_out_len = length;
data_ptr->buffer_out_ind = 0;
for (char i = 0; i < length; i++) {
data_ptr->buffer_out[i] = data[i];
}
 
// Start transmission
PIE1bits.TXIE = 1;
}
 
char UART_Read(char *buffer) {
PIE1bits.RCIE = 0; // Disable receiver interrupt
char length = data_ptr->buffer_in_len;
for (char i = 0; i < length; i++) {
buffer[i] = data_ptr->buffer_in[data_ptr->buffer_in_read_ind];
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
data_ptr->buffer_in_len -= length;
PIE1bits.RCIE = 1; // Re-enable receiver interrupt
return length;
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/UART.h
0,0 → 1,25
#ifndef UART_H
#define UART_H
 
#define UART_BUFFER_SIZE 30
 
typedef struct {
char buffer_in[UART_BUFFER_SIZE];
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_in_len;
 
char buffer_out[UART_BUFFER_SIZE];
char buffer_out_ind;
char buffer_out_len;
} UART_DATA;
 
void UART_Init(UART_DATA *data);
void UART_Write(char *data, char length);
char UART_Read(char *buffer);
 
void UART_TX_Interrupt_Handler(void);
void UART_RX_Interrupt_Handler(void);
 
#endif /* UART_H */
 
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/defines.h
0,0 → 1,38
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
 
// Resets the ECHO output for the next return signal
// Must be high at least 0.44ms
#define BLNK_TRIS TRISCbits.TRISC4
#define BLNK_LAT LATCbits.LATC4
 
// Starts the 16 pulse transmit
#define INIT_TRIS TRISCbits.TRISC3
#define INIT_LAT LATCbits.LATC3
 
// Ends the internal blanking early
#define BINH_TRIS TRISCbits.TRISC2
#define BINH_LAT LATCbits.LATC2
 
// 420kHz time base
#define OSC_TRIS TRISAbits.TRISA5
 
// Return signal
#define ECHO_TRIS TRISAbits.TRISA4
 
#define I2C_1_CLK_TRIS TRISCbits.TRISC0
#define I2C_1_DAT_TRIS TRISCbits.TRISC1
 
#define UART_RX_TRIS TRISAbits.TRISA1
#define UART_TX_TRIS TRISAbits.TRISA0
 
// </editor-fold>
 
#define _XTAL_FREQ 16000000
 
#endif /* DEFINES_H */
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/funclist
0,0 → 1,42
_LED_Write_Digit_Num: CODE, 1807 0 39
_LED_Write_Num: CODE, 1066 0 194
_LED_Write_Digit_Raw: CODE, 2012 0 18
_IOC_Enable: CODE, 4030 0 4
_IOC_Interrupt_Handler: CODE, 4052 0 14
_LED_Init: CODE, 4066 0 14
i1_TIMER1_Stop: CODE, 4010 0 3
_LED_Set_Brightness: CODE, 1846 0 38
_TIMER1_Read: CODE, 4044 0 8
_TIMER1_Stop: CODE, 4019 0 3
_I2C1_Init: CODE, 1350 0 78
_I2C1_Interrupt_Slave: CODE, 679 0 387
_TIMER1_Start: CODE, 4039 0 5
_IOC_Init: CODE, 2030 0 17
_LED_Write_Display: CODE, 1919 0 32
_main: CODE, 1260 0 90
_Interrupt_Enable: CODE, 4013 0 3
_numbertable: STRCODE, 2048 0 10
_InterruptHandler: CODE, 4 0 22
_LED_Start: CODE, 1765 0 42
_I2C1_Process_Receive: CODE, 4004 0 3
_LED_Blink_Rate: CODE, 1884 0 35
_Interrupt_Init: CODE, 2047 0 1
__initialization: CODE, 28 0 5
___lwdiv: CODE, 1563 0 55
_I2C1_Configure_Master: CODE, 1720 0 45
_alphatable: STRCODE, 2058 0 6
_IOC_Disable: CODE, 4026 0 4
_SMT6500_Read: CODE, 1504 0 59
_SMT6500_Init: CODE, 4034 0 5
_SMT6500_Callback: CODE, 4080 0 16
_LED_Clear: CODE, 1975 0 19
_I2C1_Master_Send: CODE, 1428 0 76
_I2C1_Interrupt_Handler: CODE, 1951 0 24
___lwmod: CODE, 1673 0 47
i1_IOC_Disable: CODE, 4022 0 4
_IOC_Clear: CODE, 4016 0 3
_I2C1_Get_Status: CODE, 1618 0 55
_I2C1_Interrupt_Master: CODE, 37 0 642
_Pins_Init: CODE, 1994 0 18
i1_IOC_Clear: CODE, 4007 0 3
Total: 2146
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/main.c
0,0 → 1,91
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Disabled (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "HT16K33.h"
#include "SMT6500.h"
#include "IOC.h"
//#include "UART.h"
 
void Pins_Init(void) {
// Set all pins to digital I/O
ANSELA = 0x0;
ANSELC = 0x0;
 
// // Enable weak pull-up if WPU bit is set
// OPTION_REGbits.nWPUEN = 0;
 
BLNK_LAT = 0;
BLNK_TRIS = 0;
INIT_LAT = 0;
INIT_TRIS = 0;
BINH_LAT = 0;
BINH_TRIS = 0;
OSC_TRIS = 1;
ECHO_TRIS = 1;
}
 
int main(void) {
// Set internal oscillator speed to 16MHz
OSCCONbits.SPLLEN = 0; // 4x PLL disabled (overwritten by config bits)
OSCCONbits.IRCF = 0b1111; // Base frequency @ 4MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Initialize I/O
Pins_Init();
SMT6500_Init();
 
// Initialize I2C
I2C1_DATA i2c_data;
I2C1_Init(&i2c_data);
I2C1_Configure_Master(I2C_400KHZ);
 
// UART_DATA uart_data;
// UART_Init(&uart_data);
 
IOC_DATA ioc_data;
IOC_Init(&ioc_data, SMT6500_Callback);
 
LED_DATA led_data;
LED_Init(&led_data);
 
// Initialize interrupts
Interrupt_Init();
Interrupt_Enable();
 
__delay_ms(100);
 
LED_Start();
 
while (1) {
uint16_t distance = SMT6500_Read() / 7;
LED_Write_Num(distance);
// __delay_ms(100);
}
}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Makefile-default.mk
0,0 → 1,252
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=I2C1.c INTERRUPTS.c UART.c main.c HT16K33.c TIMER.c SMT6500.c IOC.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/UART.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/HT16K33.p1 ${OBJECTDIR}/TIMER.p1 ${OBJECTDIR}/SMT6500.p1 ${OBJECTDIR}/IOC.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/UART.p1.d ${OBJECTDIR}/main.p1.d ${OBJECTDIR}/HT16K33.p1.d ${OBJECTDIR}/TIMER.p1.d ${OBJECTDIR}/SMT6500.p1.d ${OBJECTDIR}/IOC.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/UART.p1 ${OBJECTDIR}/main.p1 ${OBJECTDIR}/HT16K33.p1 ${OBJECTDIR}/TIMER.p1 ${OBJECTDIR}/SMT6500.p1 ${OBJECTDIR}/IOC.p1
 
# Source Files
SOURCEFILES=I2C1.c INTERRUPTS.c UART.c main.c HT16K33.c TIMER.c SMT6500.c IOC.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1825
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/HT16K33.p1: HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/HT16K33.p1.d
@${RM} ${OBJECTDIR}/HT16K33.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/HT16K33.p1 HT16K33.c
@-${MV} ${OBJECTDIR}/HT16K33.d ${OBJECTDIR}/HT16K33.p1.d
@${FIXDEPS} ${OBJECTDIR}/HT16K33.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/SMT6500.p1: SMT6500.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SMT6500.p1.d
@${RM} ${OBJECTDIR}/SMT6500.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/SMT6500.p1 SMT6500.c
@-${MV} ${OBJECTDIR}/SMT6500.d ${OBJECTDIR}/SMT6500.p1.d
@${FIXDEPS} ${OBJECTDIR}/SMT6500.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/HT16K33.p1: HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/HT16K33.p1.d
@${RM} ${OBJECTDIR}/HT16K33.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/HT16K33.p1 HT16K33.c
@-${MV} ${OBJECTDIR}/HT16K33.d ${OBJECTDIR}/HT16K33.p1.d
@${FIXDEPS} ${OBJECTDIR}/HT16K33.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/SMT6500.p1: SMT6500.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SMT6500.p1.d
@${RM} ${OBJECTDIR}/SMT6500.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/SMT6500.p1 SMT6500.c
@-${MV} ${OBJECTDIR}/SMT6500.d ${OBJECTDIR}/SMT6500.p1.d
@${FIXDEPS} ${OBJECTDIR}/SMT6500.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sun Nov 16 18:54:24 EST 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.32\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.32
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1825_SMT6500_Ultrasonic
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.32\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.32\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1825_SMT6500_Ultrasonic.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1825_SMT6500_Ultrasonic.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1825smt6500ultrasonic.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1825smt6500ultrasonic.tar
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1825_SMT6500_Ultrasonic.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1825smt6500ultrasonic/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1825smt6500ultrasonic/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1825smt6500ultrasonic.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1825smt6500ultrasonic.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/configurations.xml
0,0 → 1,173
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>I2C1.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>UART.h</itemPath>
<itemPath>defines.h</itemPath>
<itemPath>HT16K33.h</itemPath>
<itemPath>TIMER.h</itemPath>
<itemPath>SMT6500.h</itemPath>
<itemPath>IOC.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>I2C1.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>UART.c</itemPath>
<itemPath>main.c</itemPath>
<itemPath>HT16K33.c</itemPath>
<itemPath>TIMER.c</itemPath>
<itemPath>SMT6500.c</itemPath>
<itemPath>IOC.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1825</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.32</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.32\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/private/private.properties
--- PICX_16F1825_SMT6500_Ultrasonic/nbproject/private/private.xml (nonexistent)
+++ PICX_16F1825_SMT6500_Ultrasonic/nbproject/private/private.xml (revision 342)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
/PIC Projects/PICX_16F1825_SMT6500_Ultrasonic/nbproject/project.properties
--- PICX_16F1825_SMT6500_Ultrasonic/nbproject/project.xml (nonexistent)
+++ PICX_16F1825_SMT6500_Ultrasonic/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1825_SMT6500_Ultrasonic</name>
+ <creation-uuid>c6cdd3b9-ae67-442b-be12-227aa291caac</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <asminc-extensions/>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1825_Stepper_Driver/ADC.c
0,0 → 1,24
#include "defines.h"
#include "ADC.h"
 
void ADC_Init(void) {
ADCON0bits.ADON = 0; // Turn off ADC module
ADCON1bits.ADFM = 1; // Right justified data
ADCON1bits.ADCS = 0b110; // A/D conversion clock = FOSC/64
ADCON1bits.ADNREF = 0; // Negative reference is VSS
ADCON1bits.ADPREF = 0b00; // Positive reference is VDD
}
 
uint16_t ADC_Read(uint8_t channel) {
uint16_t ret;
 
ADCON0bits.CHS = channel; // Set channel
ADCON0bits.ADON = 1; // Turn ADC on
__delay_us(10); // Wait the acquisition time
ADCON0bits.GO_nDONE = 1; // Start conversion
while (ADCON0bits.GO_nDONE == 1); // Wait for conversion to finish
ret = ADRESH << 8; // Read ADC value
ret |= ADRESL;
 
return ret;
}
/PIC Projects/PICX_16F1825_Stepper_Driver/ADC.h
0,0 → 1,9
#ifndef ADC_H
#define ADC_H
 
void ADC_Init(void);
 
uint16_t ADC_Read(uint8_t channel);
 
#endif /* ADC_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/INTERRUPTS.c
0,0 → 1,43
#include "defines.h"
#include "INTERRUPTS.h"
#include "IOC.h"
#include "SPI.h"
#include "TIMER.h"
 
void Interrupt_Init() {
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
if (PIR1bits.TMR2IF) {
 
TIMER_2_Interrupt_Handler();
PIR1bits.TMR2IF = 0;
return;
}
if (INTCONbits.IOCIF) {
// Call the handler
IOC_Interrupt_Handler();
 
INTCONbits.IOCIF = 0;
 
return;
}
 
 
}
/PIC Projects/PICX_16F1825_Stepper_Driver/IOC.c
0,0 → 1,60
#include "defines.h"
#include "IOC.h"
#include "STEPPER.h"
 
void IOC_Init(void) {
INTCONbits.IOCIE = 1;
 
// Enable interrupt on both edges on RA3 and RA4
IOCAPbits.IOCAP3 = 1;
IOCANbits.IOCAN3 = 1;
IOCAPbits.IOCAP4 = 1;
IOCANbits.IOCAN4 = 1;
}
 
void IOC_Interrupt_Handler(void) {
STEP_LAT = 1;
STEP_LAT = 0;
if (IOCAFbits.IOCAF3) {
 
// Delay to debounce button on any edge
__delay_ms(1);
if (SW_1_PORT) {
switch (Get_Cur_Mode()) {
case SINGLE_STEP:
STEPPER_Step();
break;
case AUTO_STEP:
STEPPER_Toggle_Auto();
break;
case SET_MICROSTEP:
STEPPER_Set_Next_Step();
break;
}
}
 
// Delay to debounce button on any edge
__delay_ms(1);
IOCAFbits.IOCAF3 = 0;
return;
}
 
if (IOCAFbits.IOCAF4) {
 
// Delay to debounce button on any edge
__delay_ms(1);
if (SW_2_PORT) {
Set_Next_Mode();
}
 
// Delay to debounce button on any edge
__delay_ms(1);
 
IOCAFbits.IOCAF4 = 0;
return;
}
}
/PIC Projects/PICX_16F1825_Stepper_Driver/SPI.h
0,0 → 1,36
#ifndef SPI_H
#define SPI_H
 
#define MAX_SPI_BUFFER 64
#define SPI_WRITE_ONLY
 
#define SPI2_FOSC_TMR2 0b0011
#define SPI2_FOSC_64 0b0010
#define SPI2_FOSC_16 0b0001
#define SPI2_FOSC_4 0b0000
 
typedef struct {
#ifndef SPI_WRITE_ONLY
uint8_t buffer_in[MAX_SPI_BUFFER];
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_in_len;
#endif
 
uint8_t buffer_out[MAX_SPI_BUFFER];
uint8_t buffer_out_ind;
uint8_t buffer_out_len;
} SPI_DATA;
 
void SPI_Init(SPI_DATA *data, uint8_t speed);
void SPI_Write(uint8_t *msg, uint16_t length);
void SPI2_Write_Repeat(uint8_t c, uint16_t length);
#ifndef SPI_WRITE_ONLY
void SPI_Recv_Interrupt_Handler(void);
void SPI_Read(uint8_t length);
uint8_t SPI_Buffer_Len(void);
uint8_t SPI_Read_Buffer(uint8_t *buffer);
#endif
 
#endif /* SPI_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/STEPPER.c
0,0 → 1,90
#include "defines.h"
#include "STEPPER.h"
#include "OLED_SSD1306.h"
#include "ADC.h"
#include "TIMER.h"
 
static STEPPER_MICROSTEP currStep = STEP_1_1;
static uint8_t autoOn = 0;
 
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
#ifdef DVR8825
if (step == STEP_1_1) {
M0_LAT = 0;
M1_LAT = 0;
M2_LAT = 0;
} else if (step == STEP_1_2) {
M0_LAT = 1;
M1_LAT = 0;
M2_LAT = 0;
} else if (step == STEP_1_4) {
M0_LAT = 0;
M1_LAT = 1;
M2_LAT = 0;
} else if (step == STEP_1_8) {
M0_LAT = 1;
M1_LAT = 1;
M2_LAT = 0;
} else if (step == STEP_1_16) {
M0_LAT = 0;
M1_LAT = 0;
M2_LAT = 1;
} else if (step == STEP_1_32) {
M0_LAT = 1;
M1_LAT = 0;
M2_LAT = 1;
}
#endif
}
 
void STEPPER_Set_Next_Step() {
switch (currStep) {
case STEP_1_1:
currStep = STEP_1_2;
break;
case STEP_1_2:
currStep = STEP_1_4;
break;
case STEP_1_4:
currStep = STEP_1_8;
break;
case STEP_1_8:
currStep = STEP_1_16;
break;
case STEP_1_16:
currStep = STEP_1_32;
break;
case STEP_1_32:
default:
currStep = STEP_1_1;
break;
}
STEPPER_Set_Microstep(currStep);
}
 
STEPPER_MICROSTEP STEPPER_Get_Cur_Step(void) {
return currStep;
}
 
void STEPPER_Toggle_Auto() {
if (autoOn == 0) {
// Turn on automatic stepping
TIMER_2_Init(STEPPER_Step);
TIMER_2_Set_Delay((ADC_Read(POT_ADC_CHANNEL) >> 4) + 1);
TIMER_2_Start();
autoOn = 1;
} else {
// Turn off automatic stepping
TIMER_2_Stop();
autoOn = 0;
}
}
 
void STEPPER_Step() {
// Toggle step pin
STEP_LAT = 1;
__delay_us(2);
STEP_LAT = 0;
// Set the timer delay for the next step
TIMER_2_Set_Delay((ADC_Read(POT_ADC_CHANNEL) >> 4) + 1);
}
/PIC Projects/PICX_16F1825_Stepper_Driver/STEPPER.h
0,0 → 1,22
#ifndef STEPPER_H
#define STEPPER_H
 
#define DVR8825
 
typedef enum {
STEP_1_1,
STEP_1_2,
STEP_1_4,
STEP_1_8,
STEP_1_16,
STEP_1_32
} STEPPER_MICROSTEP;
 
void STEPPER_Set_Microstep(STEPPER_MICROSTEP);
void STEPPER_Set_Next_Step(void);
STEPPER_MICROSTEP STEPPER_Get_Cur_Step(void);
void STEPPER_Toggle_Auto(void);
void STEPPER_Step(void);
 
#endif /* STEPPER_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/TIMER.c
0,0 → 1,41
#include "defines.h"
#include "TIMER.h"
 
static TIMER_DATA *timer_data_p;
 
void TIMER_Init(TIMER_DATA *data) {
timer_data_p = data;
}
 
void TIMER_2_Init(void (*callback)(void)) {
timer_data_p->timer_2_callback = callback;
timer_data_p->delay = 0;
T2CONbits.T2OUTPS = 0b0000; // 1:1 Postscaler
T2CONbits.T2CKPS = 0b10; // 1:16 Prescaler
T2CONbits.TMR2ON = 0; // Timer stopped
TMR2 = 6; // Initial value of 6 (overflows every 0.5ms)
 
PIE1bits.TMR2IE = 1; // Timer 1 overflow interrupt
}
 
void TIMER_2_Set_Delay(uint16_t delay) {
timer_data_p->delay = delay;
}
 
void TIMER_2_Start(void) {
T2CONbits.TMR2ON = 1; // Start timer
}
 
void TIMER_2_Stop(void) {
T2CONbits.TMR2ON = 0; // Stop timer
}
 
void TIMER_2_Interrupt_Handler(void) {
TMR2 = 6;
timer_data_p->counter++;
if (timer_data_p->counter > timer_data_p->delay) {
timer_data_p->timer_2_callback();
timer_data_p->counter = 0;
}
}
/PIC Projects/PICX_16F1825_Stepper_Driver/TIMER.h
0,0 → 1,18
#ifndef TIMER_H
#define TIMER_H
 
typedef struct {
void (*timer_2_callback)(void);
uint16_t delay;
uint24_t counter;
} TIMER_DATA;
 
void TIMER_Init(TIMER_DATA *data);
void TIMER_2_Init(void (*callback)(void));
void TIMER_2_Set_Delay(uint16_t delay);
void TIMER_2_Start(void);
void TIMER_2_Stop(void);
void TIMER_2_Interrupt_Handler(void);
 
#endif /* TIMER_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/defines.h
0,0 → 1,67
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
#include "STEPPER.h"
 
//#define CONTROL_FROM_CONTROLLER
#define CONTROL_FROM_UART
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
 
// Stepper Driver
#define STEP_TRIS TRISAbits.TRISA5
#define STEP_LAT LATAbits.LATA5
#define M2_TRIS TRISCbits.TRISC3
#define M2_LAT LATCbits.LATC3
#define M1_TRIS TRISCbits.TRISC4
#define M1_LAT LATCbits.LATC4
#define M0_TRIS TRISCbits.TRISC5
#define M0_LAT LATCbits.LATC5
 
// I/O
#define SW_2_TRIS TRISAbits.TRISA4
#define SW_2_PORT PORTAbits.RA4
#define SW_2_INLVL INLVLAbits.INLVLA4
 
#define SW_1_TRIS TRISAbits.TRISA3
#define SW_1_PORT PORTAbits.RA3
#define SW_1_INLVL INLVLAbits.INLVLA3
 
#define STEP_CURRENT_TRIS TRISAbits.TRISA1
#define STEP_ADC_CHANNEL 1
#define POT_CURRENT_TRIS TRISAbits.TRISA0
#define POT_ADC_CHANNEL 0
 
// SPI
#define SPI_MOSI_TRIS TRISCbits.TRISC2
#define SPI_MOSI_LAT LATCbits.LATC2
#define SPI_CLK_TRIS TRISCbits.TRISC0
#define SPI_CLK_LAT LATCbits.LATC0
#define SPI_DC_SELECT_TRIS TRISCbits.TRISC1
#define SPI_DC_SELECT_LAT LATCbits.LATC1
#define SPI_RESET_TRIS TRISAbits.TRISA2
#define SPI_RESET_LAT LATAbits.LATA2
 
// </editor-fold>
 
#define _XTAL_FREQ 32000000
 
typedef enum {
SINGLE_STEP,
AUTO_STEP,
SET_MICROSTEP
} OPERATING_MODE;
 
void Set_Next_Mode(void);
OPERATING_MODE Get_Cur_Mode(void);
 
void Update_OLED(void);
void Draw_Manual_Text(uint8_t selected);
void Draw_Auto_Text(uint8_t selected);
void Draw_Step_Text(STEPPER_MICROSTEP step, uint8_t selected);
void Draw_Stepper_Current(void);
void Draw_Pot_Value(void);
 
#endif /* DEFINES_H */
/PIC Projects/PICX_16F1825_Stepper_Driver/funclist
0,0 → 1,65
___awdiv: CODE, 5299 0 84
_TIMER_2_Init: CODE, 4280 0 29
_TIMER_2_Stop: CODE, 8075 0 3
_IOC_Interrupt_Handler: CODE, 5383 0 85
_Update_OLED: CODE, 5468 0 85
_TIMER_2_Start: CODE, 8072 0 3
_Set_Next_Mode: CODE, 2024 0 24
__stringdata: STRCODE, 1541 0 10
_Draw_Auto_Text: CODE, 5068 0 76
_SSD1306_Set_Cursor: CODE, 4115 0 20
_Draw_Pot_Value: CODE, 4732 0 51
___ftpack: CODE, 5553 0 97
_IOC_Init: CODE, 8082 0 7
_font: STRCODE, 256 0 1275
_dpowers: STRCODE, 1531 0 10
_memset: CODE, 4369 0 30
_STEPPER_Set_Microstep: CODE, 4835 0 54
_main: CODE, 4684 0 48
_Interrupt_Enable: CODE, 4096 0 3
___lwtoft: CODE, 4155 0 21
_TIMER_2_Set_Delay: CODE, 8096 0 11
_SSD1306_Draw_Fast_VLine: CODE, 4944 0 59
_SSD1306_Abs: CODE, 8142 0 15
_SSD1306_Set_Text_Color: CODE, 4135 0 20
_InterruptHandler: CODE, 4 0 23
_SSD1306_Swap: CODE, 4253 0 27
_SSD1306_Init: CODE, 2048 0 95
_SPI_Write: CODE, 4431 0 34
_Draw_Manual_Text: CODE, 5144 0 76
_Get_Cur_Mode: CODE, 8069 0 3
_SSD1306_Write: CODE, 2627 0 261
_SSD1306_Begin: CODE, 5650 0 126
_STEPPER_Set_Next_Step: CODE, 4399 0 32
_Interrupt_Init: CODE, 3 0 1
__initialization: CODE, 29 0 51
_SSD1306_Write_String: CODE, 4176 0 25
___lwdiv: CODE, 4889 0 55
_SSD1306_Draw_Line: CODE, 2367 0 260
_TIMER_2_Interrupt_Handler: CODE, 5220 0 79
_SSD1306_Draw_Char: CODE, 1551 0 473
_STEPPER_Step: CODE, 4309 0 30
_Draw_Stepper_Current: CODE, 5956 0 188
_SSD1306_Fill_Rect: CODE, 5003 0 65
_SPI_Init: CODE, 4465 0 40
_isdigit: CODE, 8157 0 15
_sprintf: CODE, 3186 0 398
_Draw_Step_Text: CODE, 2888 0 298
_SSD1306_Set_Text_Size: CODE, 4227 0 26
___lwmod: CODE, 4637 0 47
_SSD1306_Clear_Display: CODE, 4099 0 16
___ftmul: CODE, 5776 0 180
_TIMER_Init: CODE, 8089 0 7
_ADC_Read: CODE, 4783 0 52
_SSD1306_Command: CODE, 8172 0 20
_SSD1306_Draw_Pixel: CODE, 2143 0 224
___wmul: CODE, 4339 0 30
_ADC_Init: CODE, 8107 0 11
_SSD1306_Display: CODE, 4201 0 26
_SSD1306_Set_Text_Wrap: CODE, 8118 0 12
_STEPPER_Toggle_Auto: CODE, 4548 0 44
___fttol: CODE, 84 0 135
_Pins_Init: CODE, 4505 0 43
i1_ADC_Read: CODE, 4592 0 45
_STEPPER_Get_Cur_Step: CODE, 253 0 3
Total: 5696
/PIC Projects/PICX_16F1825_Stepper_Driver/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_16F1825_Stepper_Driver/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_16F1825_Stepper_Driver/main.c
0,0 → 1,234
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "INTERRUPTS.h"
#include "STEPPER.h"
#include "IOC.h"
#include "SPI.h"
#include "ADC.h"
#include "OLED_SSD1306.h"
#include "TIMER.h"
#include <stdio.h>
 
void Pins_Init(void) {
// RA0 and RA1 pins as analog input
ANSELA = 0x3;
ANSELC = 0x0;
 
// // Enable weak pull-up if WPU bit is set
// OPTION_REGbits.nWPUEN = 0;
 
// SDO1 on RC2
APFCON0bits.SDOSEL = 0;
 
// Stepper Driver
STEP_TRIS = 0;
STEP_LAT = 0;
M0_TRIS = 0;
M0_LAT = 0;
M1_TRIS = 0;
M1_LAT = 0;
M2_TRIS = 0;
M2_LAT = 0;
 
// I/O
SW_1_TRIS = 1;
SW_1_INLVL = 1;
SW_2_TRIS = 1;
SW_2_INLVL = 1;
 
STEP_CURRENT_TRIS = 1;
POT_CURRENT_TRIS = 1;
 
// SPI
SPI_MOSI_TRIS = 0;
SPI_CLK_TRIS = 0;
SPI_DC_SELECT_TRIS = 0;
SPI_DC_SELECT_LAT = 0;
SPI_RESET_TRIS = 0;
SPI_RESET_LAT = 0;
}
 
OPERATING_MODE currMode;
 
int main(void) {
// Set internal oscillator speed to 32MHz
OSCCONbits.SPLLEN = 1; // 4x PLL enable (overwritten by config bits)
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Initialize I/O
Pins_Init();
 
IOC_Init();
 
ADC_Init();
 
TIMER_DATA timer_data;
TIMER_Init(&timer_data);
SPI_DATA spi_data;
SPI_Init(&spi_data, SPI2_FOSC_16);
 
SSD1306_DATA ssd1306_data;
SSD1306_Init(&ssd1306_data);
 
Interrupt_Init();
Interrupt_Enable();
 
currMode = SINGLE_STEP;
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
 
while(1) {
Update_OLED();
// __delay_ms(1);
}
}
 
void Set_Next_Mode() {
switch (currMode) {
case SINGLE_STEP:
currMode = AUTO_STEP;
break;
case AUTO_STEP:
currMode = SET_MICROSTEP;
break;
case SET_MICROSTEP:
default:
currMode = SINGLE_STEP;
break;
}
}
 
OPERATING_MODE Get_Cur_Mode(void) {
return currMode;
}
 
void Update_OLED(void) {
SSD1306_Clear_Display();
SSD1306_Set_Text_Size(2);
SSD1306_Set_Text_Wrap(0);
switch (currMode) {
case SINGLE_STEP:
Draw_Manual_Text(1);
Draw_Auto_Text(0);
Draw_Step_Text(STEPPER_Get_Cur_Step(), 0);
break;
case AUTO_STEP:
Draw_Manual_Text(0);
Draw_Auto_Text(1);
Draw_Step_Text(STEPPER_Get_Cur_Step(), 0);
break;
case SET_MICROSTEP:
Draw_Manual_Text(0);
Draw_Auto_Text(0);
Draw_Step_Text(STEPPER_Get_Cur_Step(), 1);
break;
}
Draw_Stepper_Current();
Draw_Pot_Value();
SSD1306_Display();
}
 
void Draw_Manual_Text(uint8_t selected) {
// Draw and/or highlight the stepping mode in the top left corner
uint8_t stringManual[] = "MANUAL";
if (selected) {
SSD1306_Fill_Rect(0, 0, 75, 16, 1);
SSD1306_Set_Text_Color(0);
} else {
SSD1306_Set_Text_Color(1);
}
SSD1306_Set_Cursor(3, 1);
SSD1306_Write_String(stringManual, 6);
}
 
void Draw_Auto_Text(uint8_t selected) {
// Draw and/or highlight the stepping mode in the top right corner
uint8_t stringAuto[] = "AUTO";
if (selected) {
SSD1306_Fill_Rect(76, 0, 53, 16, 1);
SSD1306_Set_Text_Color(0);
} else {
SSD1306_Set_Text_Color(1);
}
SSD1306_Set_Cursor(79, 1);
SSD1306_Write_String(stringAuto, 4);
}
 
void Draw_Stepper_Current() {
// Draw the stepper motor current draw in the bottom right corner
uint8_t buffer[6] = {0};
uint16_t potVoltage = ADC_Read(STEP_ADC_CHANNEL);
// Compute current from voltage reading (2x)
uint16_t current = potVoltage * 0.3222 * 2;
uint8_t preDecimal = current / 100;
uint8_t postDecimal = current % 100;
sprintf(buffer, "%1d.%02dA", preDecimal, postDecimal);
SSD1306_Set_Text_Color(1);
SSD1306_Set_Cursor(67, 17);
SSD1306_Write_String(buffer, 5);
}
 
void Draw_Pot_Value() {
// Draw a line indicating auto rotation delay
uint8_t potVoltage = ADC_Read(POT_ADC_CHANNEL) >> 4;
SSD1306_Draw_Line(127, 31, 127 - potVoltage, 31, 1);
}
 
void Draw_Step_Text(STEPPER_MICROSTEP step, uint8_t selected) {
// Draw and/or highlight the stepping in the bottom left corner
uint8_t stringStepping32[] = "1/32";
uint8_t stringStepping16[] = "1/16";
uint8_t stringStepping8[] = "1/8";
uint8_t stringStepping4[] = "1/4";
uint8_t stringStepping2[] = "1/2";
uint8_t stringStepping1[] = "1/1";
if (selected) {
SSD1306_Fill_Rect(0, 16, 52, 16, 1);
SSD1306_Set_Text_Color(0);
} else {
SSD1306_Set_Text_Color(1);
}
if (step == STEP_1_32) {
SSD1306_Set_Cursor(2, 17);
SSD1306_Write_String(stringStepping32, 4);
} else if (step == STEP_1_16) {
SSD1306_Set_Cursor(2, 17);
SSD1306_Write_String(stringStepping16, 4);
} else if (step == STEP_1_8) {
SSD1306_Set_Cursor(8, 17);
SSD1306_Write_String(stringStepping8, 3);
} else if (step == STEP_1_4) {
SSD1306_Set_Cursor(8, 17);
SSD1306_Write_String(stringStepping4, 3);
} else if (step == STEP_1_2) {
SSD1306_Set_Cursor(8, 17);
SSD1306_Write_String(stringStepping2, 3);
} else if (step == STEP_1_1) {
SSD1306_Set_Cursor(8, 17);
SSD1306_Write_String(stringStepping1, 3);
}
}
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Makefile-default.mk
0,0 → 1,252
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c INTERRUPTS.c STEPPER.c IOC.c SPI.c OLED_SSD1306.c ADC.c TIMER.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/STEPPER.p1 ${OBJECTDIR}/IOC.p1 ${OBJECTDIR}/SPI.p1 ${OBJECTDIR}/OLED_SSD1306.p1 ${OBJECTDIR}/ADC.p1 ${OBJECTDIR}/TIMER.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/STEPPER.p1.d ${OBJECTDIR}/IOC.p1.d ${OBJECTDIR}/SPI.p1.d ${OBJECTDIR}/OLED_SSD1306.p1.d ${OBJECTDIR}/ADC.p1.d ${OBJECTDIR}/TIMER.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/STEPPER.p1 ${OBJECTDIR}/IOC.p1 ${OBJECTDIR}/SPI.p1 ${OBJECTDIR}/OLED_SSD1306.p1 ${OBJECTDIR}/ADC.p1 ${OBJECTDIR}/TIMER.p1
 
# Source Files
SOURCEFILES=main.c INTERRUPTS.c STEPPER.c IOC.c SPI.c OLED_SSD1306.c ADC.c TIMER.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1825
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/STEPPER.p1: STEPPER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/STEPPER.p1.d
@${RM} ${OBJECTDIR}/STEPPER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/STEPPER.p1 STEPPER.c
@-${MV} ${OBJECTDIR}/STEPPER.d ${OBJECTDIR}/STEPPER.p1.d
@${FIXDEPS} ${OBJECTDIR}/STEPPER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/SPI.p1: SPI.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI.p1.d
@${RM} ${OBJECTDIR}/SPI.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/SPI.p1 SPI.c
@-${MV} ${OBJECTDIR}/SPI.d ${OBJECTDIR}/SPI.p1.d
@${FIXDEPS} ${OBJECTDIR}/SPI.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/OLED_SSD1306.p1: OLED_SSD1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/OLED_SSD1306.p1.d
@${RM} ${OBJECTDIR}/OLED_SSD1306.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/OLED_SSD1306.p1 OLED_SSD1306.c
@-${MV} ${OBJECTDIR}/OLED_SSD1306.d ${OBJECTDIR}/OLED_SSD1306.p1.d
@${FIXDEPS} ${OBJECTDIR}/OLED_SSD1306.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/ADC.p1: ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ADC.p1.d
@${RM} ${OBJECTDIR}/ADC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/ADC.p1 ADC.c
@-${MV} ${OBJECTDIR}/ADC.d ${OBJECTDIR}/ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/STEPPER.p1: STEPPER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/STEPPER.p1.d
@${RM} ${OBJECTDIR}/STEPPER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/STEPPER.p1 STEPPER.c
@-${MV} ${OBJECTDIR}/STEPPER.d ${OBJECTDIR}/STEPPER.p1.d
@${FIXDEPS} ${OBJECTDIR}/STEPPER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IOC.p1: IOC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IOC.p1.d
@${RM} ${OBJECTDIR}/IOC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IOC.p1 IOC.c
@-${MV} ${OBJECTDIR}/IOC.d ${OBJECTDIR}/IOC.p1.d
@${FIXDEPS} ${OBJECTDIR}/IOC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/SPI.p1: SPI.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI.p1.d
@${RM} ${OBJECTDIR}/SPI.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/SPI.p1 SPI.c
@-${MV} ${OBJECTDIR}/SPI.d ${OBJECTDIR}/SPI.p1.d
@${FIXDEPS} ${OBJECTDIR}/SPI.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/OLED_SSD1306.p1: OLED_SSD1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/OLED_SSD1306.p1.d
@${RM} ${OBJECTDIR}/OLED_SSD1306.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/OLED_SSD1306.p1 OLED_SSD1306.c
@-${MV} ${OBJECTDIR}/OLED_SSD1306.d ${OBJECTDIR}/OLED_SSD1306.p1.d
@${FIXDEPS} ${OBJECTDIR}/OLED_SSD1306.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/ADC.p1: ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ADC.p1.d
@${RM} ${OBJECTDIR}/ADC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/ADC.p1 ADC.c
@-${MV} ${OBJECTDIR}/ADC.d ${OBJECTDIR}/ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Thu Sep 04 00:52:07 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.32\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.32
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/configurations.xml
0,0 → 1,174
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>STEPPER.h</itemPath>
<itemPath>IOC.h</itemPath>
<itemPath>SPI.h</itemPath>
<itemPath>OLED_SSD1306.h</itemPath>
<itemPath>ADC.h</itemPath>
<itemPath>TIMER.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>STEPPER.c</itemPath>
<itemPath>IOC.c</itemPath>
<itemPath>SPI.c</itemPath>
<itemPath>OLED_SSD1306.c</itemPath>
<itemPath>ADC.c</itemPath>
<itemPath>TIMER.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1825</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.32</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="firmware.download.all" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.32\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Thu Apr 03 21:51:18 EDT 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/private/private.xml
0,0 → 1,3
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.32\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.32\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1825_Stepper_Driver
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1825_Stepper_Driver.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1825_Stepper_Driver.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1825stepperdriver.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1825stepperdriver.tar
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1825_Stepper_Driver.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1825stepperdriver/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1825stepperdriver/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1825stepperdriver.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1825stepperdriver.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1825_Stepper_Driver/nbproject/project.properties
--- PICX_16F1825_Stepper_Driver/nbproject/project.xml (nonexistent)
+++ PICX_16F1825_Stepper_Driver/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1825_Sabertooth</name>
+ <creation-uuid>a37f9b7c-e474-41b7-9a5b-bc6808e97a44</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1825_Stepper_Driver/OLED_SSD1306.c
0,0 → 1,771
#include "defines.h"
#include <string.h>
//#include <stdio.h>
#include "OLED_SSD1306.h"
#include "SPI.h"
#include "glcdfont.c"
 
static SSD1306_DATA *ssd1306_data_p;
 
// 512 (128x32) or 1024 (128x64) bytes allocated for LCD buffer
// See linker file for details
static uint8_t LCD_BUFFER[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8,
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80,
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF,
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF,
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F,
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00,
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F,
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00,
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E,
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC,
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06,
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8,
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C,
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F,
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07,
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#endif
};
 
int16_t SSD1306_Abs(int16_t i) {
if (i < 0)
return -i;
else
return i;
}
 
void SSD1306_Swap(int16_t *a, int16_t *b) {
int16_t tmp = *a;
*a = *b;
*b = tmp;
}
 
void SSD1306_Init(SSD1306_DATA *data) {
ssd1306_data_p = data;
ssd1306_data_p->_height = SSD1306_LCDHEIGHT;
ssd1306_data_p->HEIGHT = SSD1306_LCDHEIGHT;
ssd1306_data_p->_width = SSD1306_LCDWIDTH;
ssd1306_data_p->WIDTH = SSD1306_LCDWIDTH;
ssd1306_data_p->rotation = 0;
ssd1306_data_p->cursor_x = ssd1306_data_p->cursor_y = 0;
ssd1306_data_p->textsize = 1;
ssd1306_data_p->textcolor = SSD1306_WHITE;
ssd1306_data_p->textbgcolor = SSD1306_BLACK;
ssd1306_data_p->wrap = 1;
}
 
void SSD1306_Begin(char vccstate) {
// Toggle reset pin
SPI_RESET_LAT = 0;
__delay_us(10);
SPI_RESET_LAT = 1;
 
#if defined SSD1306_128_32
// Init sequence for 128x32 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x1F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x02);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
SSD1306_Command(0x8F);
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
#if defined SSD1306_128_64
// Init sequence for 128x64 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x3F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x12);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x9F);
} else {
SSD1306_Command(0xCF);
}
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
SSD1306_Command(SSD1306_DISPLAYON); // Turn on OLED panel
}
 
void SSD1306_Command(uint8_t cmd) {
uint8_t c = cmd;
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI_Write(&c, 1);
}
 
void SSD1306_Data(uint8_t data) {
uint8_t c = data;
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI_Write(&c, 1);
}
 
void SSD1306_Clear_Display() {
memset(LCD_BUFFER, 0, (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8));
}
 
void SSD1306_Invert_Display(uint8_t c) {
if (c) {
SSD1306_Command(SSD1306_INVERTDISPLAY);
} else {
SSD1306_Command((SSD1306_NORMALDISPLAY));
}
}
 
void SSD1306_Display() {
SSD1306_Command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
SSD1306_Command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // line #0
 
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI_Write(LCD_BUFFER, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
 
// if (SSD1306_LCDHEIGHT == 32) {
// SPI2_Write_Repeat(0, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
// }
}
 
void SSD1306_Draw_Pixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (x >= ssd1306_data_p->_width) || (y < 0) || (y >= ssd1306_data_p->_height))
return;
 
// check rotation, move pixel around if necessary
switch (ssd1306_data_p->rotation) {
case 1:
SSD1306_Swap(&x, &y);
x = SSD1306_LCDWIDTH - x - 1;
break;
case 2:
x = SSD1306_LCDWIDTH - x - 1;
y = SSD1306_LCDHEIGHT - y - 1;
break;
case 3:
SSD1306_Swap(&x, &y);
y = SSD1306_LCDHEIGHT - y - 1;
break;
default:
break;
}
 
// Need to do this for some reason since x + (y / 8) * SSD1306_LCDWIDTH returns -128?!
// TODO: Change this back when they fix the compiler
int16_t loc = (y / 8) * SSD1306_LCDWIDTH;
loc += x;
// x is which column
if (color == SSD1306_WHITE) {
LCD_BUFFER[loc] |= 1<<(y % 8);
} else {
LCD_BUFFER[loc] &= ~(1<<(y % 8));
}
}
 
void SSD1306_Draw_Line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
int16_t dx, dy, err, ystep;
int16_t steep = SSD1306_Abs(y1 - y0) > SSD1306_Abs(x1 - x0);
if (steep) {
SSD1306_Swap(&x0, &y0);
SSD1306_Swap(&x1, &y1);
}
 
if (x0 > x1) {
SSD1306_Swap(&x0, &x1);
SSD1306_Swap(&y0, &y1);
}
 
dx = x1 - x0;
dy = SSD1306_Abs(y1 - y0);
 
err = dx / 2;
 
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
 
for (; x0 <= x1; x0++) {
 
if (steep) {
SSD1306_Draw_Pixel(y0, x0, color);
} else {
SSD1306_Draw_Pixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
 
void SSD1306_Draw_Fast_VLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
SSD1306_Draw_Line(x, y, x, y + h - 1, color);
}
 
void SSD1306_Draw_Fast_HLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
SSD1306_Draw_Line(x, y, x + w - 1, y, color);
}
 
void SSD1306_Draw_Rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
SSD1306_Draw_Fast_HLine(x, y, w, color);
SSD1306_Draw_Fast_HLine(x, y + h, w, color);
SSD1306_Draw_Fast_VLine(x, y, h, color);
SSD1306_Draw_Fast_VLine(x + w, y, h, color);
}
 
void SSD1306_Fill_Rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
int16_t i;
for (i = x; i < x + w; i++) {
SSD1306_Draw_Fast_VLine(i, y, h, color);
}
}
 
void SSD1306_Draw_Circle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
 
SSD1306_Draw_Pixel(x0, y0 + r, color);
SSD1306_Draw_Pixel(x0, y0 - r, color);
SSD1306_Draw_Pixel(x0 + r, y0, color);
SSD1306_Draw_Pixel(x0 - r, y0, color);
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
}
}
 
void SSD1306_Draw_Circle_Helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
}
}
}
 
void SSD1306_Fill_Circle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
SSD1306_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
SSD1306_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
}
 
void SSD1306_Fill_Circle_Helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
if (cornername & 0x1) {
SSD1306_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
 
void SSD1306_Draw_Triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
SSD1306_Draw_Line(x0, y0, x1, y1, color);
SSD1306_Draw_Line(x1, y1, x2, y2, color);
SSD1306_Draw_Line(x2, y2, x0, y0, color);
}
 
void SSD1306_Fill_Triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
int16_t a, b, y, last;
int16_t dx01 = x1 - x0;
int16_t dy01 = y1 - y0;
int16_t dx02 = x2 - x0;
int16_t dy02 = y2 - y0;
int16_t dx12 = x2 - x1;
int16_t dy12 = y2 - y1;
int16_t sa = 0;
int16_t sb = 0;
 
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
if (y1 > y2) {
SSD1306_Swap(&y2, &y1);
SSD1306_Swap(&x2, &x1);
}
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
 
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
SSD1306_Draw_Fast_HLine(a, y0, b - a + 1, color);
return;
}
 
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
 
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
 
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
}
 
void SSD1306_Draw_Round_Rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color) {
// smarter version
SSD1306_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
SSD1306_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
SSD1306_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
SSD1306_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
 
// draw four corners
SSD1306_Draw_Circle_Helper(x + r, y + r, r, 1, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
SSD1306_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
}
 
void SSD1306_Fill_Round_Rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color) {
// smarter version
SSD1306_Fill_Rect(x + r, y, w - 2 * r, h, color);
 
// draw four corners
SSD1306_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
SSD1306_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
 
void SSD1306_Draw_Bitmap(int16_t x, int16_t y, const uint8_t* bitmap, int16_t w, int16_t h, uint16_t color) {
int16_t i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (bitmap[i + (j / 8) * w] & (j % 8)) {
SSD1306_Draw_Pixel(x + i, y + j, color);
}
}
}
}
 
void SSD1306_Draw_Char(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size) {
int16_t i, j;
uint16_t line;
 
if ((x >= ssd1306_data_p->_width) || // Clip right
(y >= ssd1306_data_p->_height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
 
for (i = 0; i < 6; i++) {
if (i == 5)
line = 0x0;
else
line = font[(c * 5) + i];
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) {// default size
SSD1306_Draw_Pixel(x + i, y + j, color);
} else { // big size
SSD1306_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
}
} else if (bg != color) {
if (size == 1) { // default size
SSD1306_Draw_Pixel(x + i, y + j, bg);
} else { // big size
SSD1306_Fill_Rect(x + i*size, y + j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
 
void SSD1306_Write(uint8_t c) {
if (c == '\n' || c == '\r') {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
// } else if (c == '\r') {
// // skip em
} else {
SSD1306_Draw_Char(ssd1306_data_p->cursor_x, ssd1306_data_p->cursor_y, c, ssd1306_data_p->textcolor, ssd1306_data_p->textbgcolor, ssd1306_data_p->textsize);
ssd1306_data_p->cursor_x += ssd1306_data_p->textsize * 6;
if (ssd1306_data_p->wrap && (ssd1306_data_p->cursor_x > (ssd1306_data_p->_width - ssd1306_data_p->textsize * 6))) {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
}
}
}
 
void SSD1306_Write_String(uint8_t* msg, uint8_t length) {
for (uint8_t i = 0; i < length; i++) {
SSD1306_Write(msg[i]);
}
}
 
void SSD1306_Set_Cursor(int16_t x, int16_t y) {
ssd1306_data_p->cursor_x = x;
ssd1306_data_p->cursor_y = y;
}
 
void SSD1306_Set_Text_Color(uint16_t c) {
// for 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = c;
}
 
void SSD1306_Set_Text_Color_BG(uint16_t c, uint16_t bg) {
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = bg;
}
 
void SSD1306_Set_Text_Size(uint8_t s) {
ssd1306_data_p->textsize = (s > 0) ? s : 1;
}
 
void SSD1306_Set_Text_Wrap(uint8_t w) {
ssd1306_data_p->wrap = w;
}
 
void SSD1306_Set_Rotation(uint8_t x) {
x %= 4; // cant be higher than 3
ssd1306_data_p->rotation = x;
switch (x) {
case 0:
case 2:
ssd1306_data_p->_width = ssd1306_data_p->WIDTH;
ssd1306_data_p->_height = ssd1306_data_p->HEIGHT;
break;
case 1:
case 3:
ssd1306_data_p->_width = ssd1306_data_p->HEIGHT;
ssd1306_data_p->_height = ssd1306_data_p->WIDTH;
break;
}
}
 
 
void SSD1306_Test_DrawChar() {
uint8_t i;
SSD1306_Set_Text_Size(1);
SSD1306_Set_Text_Color(SSD1306_WHITE);
SSD1306_Set_Cursor(0, 0);
 
for (i = 0; i < 168; i++) {
if (i == '\n') continue;
SSD1306_Write(i);
// if ((i > 0) && (i % 21 == 0))
// SSD1306_write('\n');
}
SSD1306_Display();
}
 
void SSD1306_Test_DrawCircle() {
int16_t i;
for (i = 0; i < ssd1306_data_p->_height; i += 2) {
SSD1306_Draw_Circle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2, i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRect(void) {
int16_t i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 2) {
SSD1306_Draw_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRect(void) {
uint8_t color = 1;
int16_t i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 3) {
// alternate colors
SSD1306_Fill_Rect(i, i, ssd1306_data_p->_width - i * 2, ssd1306_data_p->_height - i * 2, color % 2);
SSD1306_Display();
color++;
}
}
 
void SSD1306_Test_DrawTriangle(void) {
int16_t i;
int16_t min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = 0; i < min / 2; i += 5) {
SSD1306_Draw_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillTriangle(void) {
uint8_t color = SSD1306_WHITE;
int16_t i;
int16_t min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = min / 2; i > 0; i -= 5) {
SSD1306_Fill_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRoundRect(void) {
int16_t i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Draw_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRoundRect(void) {
uint8_t color = SSD1306_WHITE;
int16_t i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Fill_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, color);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawLine(void) {
int16_t i;
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(0, 0, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
__delay_ms(10);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
__delay_ms(10);
 
SSD1306_Clear_Display();
for (i = ssd1306_data_p->_width - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
__delay_ms(10);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
__delay_ms(10);
}
/PIC Projects/PICX_16F1825_Stepper_Driver/OLED_SSD1306.h
0,0 → 1,132
#ifndef OLED_SSD1306_H
#define OLED_SSD1306_H
 
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
 
SSD1306_128_64 128x64 pixel display
 
SSD1306_128_32 128x32 pixel display
 
You also need to set the LCDWIDTH and LCDHEIGHT defines to an
appropriate size
 
-----------------------------------------------------------------------*/
// #define SSD1306_128_64
#define SSD1306_128_32
/*=========================================================================*/
 
#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 32
#endif
 
//#define SSD1306_STRING_BUFFER_SIZE 32
 
#define SSD1306_BLACK 0
#define SSD1306_WHITE 1
 
#define SSD1306_I2C_ADDRESS 0x3D // 011110+SA0+RW
 
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
 
typedef struct {
int16_t WIDTH, HEIGHT; // raw display size
int16_t _width, _height; // size depending on rotation
int16_t cursor_x, cursor_y;
uint16_t textcolor, textbgcolor;
uint8_t textsize;
uint8_t rotation;
uint8_t wrap; // If set, wrap text at right side
} SSD1306_DATA;
 
// Misc functions
int16_t SSD1306_Abs(int16_t i);
void SSD1306_Swap(int16_t *a, int16_t *b);
 
// Core functions
void SSD1306_Init(SSD1306_DATA *data);
void SSD1306_Begin(uint8_t vcc);
void SSD1306_Command(uint8_t cmd);
void SSD1306_Data(uint8_t data);
 
void SSD1306_Clear_Display(void);
void SSD1306_Invert_Display(uint8_t);
void SSD1306_Display(void);
 
// Drawing functions
void SSD1306_Draw_Pixel(int16_t x, int16_t y, uint16_t color);
void SSD1306_Draw_Line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void SSD1306_Draw_Fast_VLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void SSD1306_Draw_Fast_HLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void SSD1306_Draw_Rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void SSD1306_Fill_Rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
 
void SSD1306_Draw_Circle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void SSD1306_Draw_Circle_Helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
void SSD1306_Fill_Circle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void SSD1306_Fill_Circle_Helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
 
void SSD1306_Draw_Triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void SSD1306_Fill_Triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void SSD1306_Draw_Round_Rect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
void SSD1306_Fill_Round_Rect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
 
void SSD1306_Draw_Bitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void SSD1306_Draw_Char(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size);
 
void SSD1306_Write(uint8_t c);
void SSD1306_Write_String(uint8_t *msg, uint8_t length);
//void SSD1306_Write_String(const rom char *fmt, ...);
//void SSD1306_Append_String(const rom char *fmt, ...);
 
void SSD1306_Set_Cursor(int16_t x, int16_t y);
void SSD1306_Set_Text_Color(uint16_t c);
void SSD1306_Set_Text_Color_BG(uint16_t c, uint16_t bg);
void SSD1306_Set_Text_Size(uint8_t s);
void SSD1306_Set_Text_Wrap(uint8_t w);
void SSD1306_Set_Rotation(uint8_t r);
 
// Test functions
void SSD1306_Test_DrawChar(void);
void SSD1306_Test_DrawCircle(void);
void SSD1306_Test_DrawRect(void);
void SSD1306_Test_FillRect(void);
void SSD1306_Test_DrawTriangle(void);
void SSD1306_Test_FillTriangle(void);
void SSD1306_Test_DrawRoundRect(void);
void SSD1306_Test_FillRoundRect(void);
void SSD1306_Test_DrawLine(void);
 
#endif /* OLED_SSD1306_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/SPI.c
0,0 → 1,159
#include "defines.h"
#include "SPI.h"
 
static SPI_DATA *spi_data_p;
 
void SPI_Init(SPI_DATA *data, uint8_t speed) {
spi_data_p = data;
 
SPI_MOSI_TRIS = 0;
SPI_CLK_TRIS = 0;
 
#ifndef SPI_WRITE_ONLY
SPI_MISO_TRIS = 1;
#endif
 
// SPI_SLAVE_SELECT_TRIS = 0; // SPI2 slave select
// SPI_SLAVE_SELECT_LAT = 1; // SPI2 SS high (Idle)
 
// SPI_RESET_TRIS = 0; // SPI2 reset
// SPI_RESET_LAT = 1; // SPI2 reset active low
 
SPI_DC_SELECT_TRIS = 0; // SPI2 D/C select
SPI_DC_SELECT_LAT = 0;
 
SSP1STATbits.SMP = 0; // Input is sampled in the middle of data output time
SSP1STATbits.CKE = 0; // Transmit occurs on transition from Idle to active clock state
 
SSP1CON1bits.SSPM = speed;
 
SSP1CON1bits.CKP = 1; // Idle state for clock is a high level
SSP1CON1bits.SSPEN = 1; // Enable MSSP module
 
PIE1bits.SSP1IE = 0; // Disable MSSP interrupt
 
#ifndef SPI_WRITE_ONLY
spi_data_p->buffer_in_len = 0;
spi_data_p->buffer_in_read_ind = 0;
spi_data_p->buffer_in_write_ind = 0;
#endif
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
 
void SPI_Write(uint8_t *msg, uint16_t length) {
uint16_t i = 0;
 
// SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP1BUF = msg[i];
i++;
while (!SSP1STATbits.BF);
 
#ifndef SPI_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
uint8_t tmp = SSP1BUF;
#endif
}
// SPI_SLAVE_SELECT_LAT = 1;
}
 
void SPI2_Write_Repeat(uint8_t c, uint16_t length) {
uint16_t i = 0;
// SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP1BUF = c;
i++;
while (!SSP1STATbits.BF);
 
#ifndef SPI_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
uint8_t tmp = SSP1BUF;
#endif
}
// SPI_SLAVE_SELECT_LAT = 1;
}
 
#ifndef SPI_WRITE_ONLY
void SPI_Recv_Interrupt_Handler() {
uint8_t c;
 
if (SSP1STATbits.BF) { // Check if data receive flag is set
if (spi_data_p->buffer_in_len == MAX_SPI_BUFFER - 1) {
c = SSP1BUF; // Read SSP2BUF to clear it
} else {
// Save received data into buffer
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP1BUF;
if (spi_data_p->buffer_in_write_ind == MAX_SPI_BUFFER - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
 
// Put next byte in SSP2BUF for transmit
if (spi_data_p->buffer_out_ind != spi_data_p->buffer_out_len) {
SSP1BUF = spi_data_p->buffer_out[spi_data_p->buffer_out_ind];
spi_data_p->buffer_out_ind++;
} else {
// SPI_SLAVE_SELECT_LAT = 1; // Bring SS line high
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
}
}
}
 
void SPI_Read(char length) {
// SPI_SLAVE_SELECT_LAT = 0;
 
for (uint8_t i = 0; i < length; i++) {
SSP1BUF = 0x0;
while (!SSP1STATbits.BF);
 
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP1BUF;
if (spi_data_p->buffer_in_write_ind == MAX_SPI_BUFFER - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
}
// SPI_SLAVE_SELECT_LAT = 1;
}
 
uint8_t SPI_Buffer_Len() {
return spi_data_p->buffer_in_len;
}
 
uint8_t SPI_Read_Buffer(uint8_t* buffer) {
uint8_t i = 0;
while (spi_data_p->buffer_in_len != 0) {
buffer[i] = spi_data_p->buffer_in[spi_data_p->buffer_in_read_ind];
i++;
if (spi_data_p->buffer_in_read_ind == MAX_SPI_BUFFER - 1) {
spi_data_p->buffer_in_read_ind = 0;
} else {
spi_data_p->buffer_in_read_ind++;
}
spi_data_p->buffer_in_len--;
}
return i;
}
#endif
/PIC Projects/PICX_16F1825_Stepper_Driver/glcdfont.c
0,0 → 1,263
#ifndef FONT5X7_H
#define FONT5X7_H
 
// standard ascii 5x7 font
 
const char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
/PIC Projects/PICX_16F1825_Stepper_Driver/INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1825_Stepper_Driver/IOC.h
0,0 → 1,8
#ifndef IOC_H
#define IOC_H
 
void IOC_Init(void);
void IOC_Interrupt_Handler(void);
 
#endif /* IOC_H */
 
/PIC Projects/PICX_16F1825_Stepper_Driver/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/Cerebot_32MX7_LED_Cube/Ethernet API/cube.py
0,0 → 1,152
import socket, struct, time
 
# Set the address of the Cerebot board
dst_addr = '00183E00D7EB'.decode('hex')
# Open a socket on the eth0
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
sock.bind(("eth0", 0x1))
# Acquire MAC address of local machine
if_name, if_proto, pkt_type, hw_type, hw_addr = sock.getsockname()
 
# Create and initialize the frame buffer
frame_buffer_size = 1536
frame_buffer = [0] * frame_buffer_size
 
def cube_init():
'''Sets the cube into ethernet mode.'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 1)
txOpcode = "01".decode('hex')
sock.send(txFrame + txOpcode)
# Wait a few seconds for the cube to reset itself
time.sleep(6)
 
def cube_reset():
'''Resets the cube into idle mode.'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 1)
txOpcode = "02".decode('hex')
sock.send(txFrame + txOpcode)
 
def cube_clear():
'''Clear the cube's internal buffer.'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 1)
txOpcode = "0A".decode('hex')
sock.send(txFrame + txOpcode)
 
def cube_brightness(value):
'''Sets the global brightness value from 0 to 255.'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 2)
txOpcode = "0B".decode('hex')
txData = format(value, '02x').decode('hex')
sock.send(txFrame + txOpcode + txData)
 
def cube_rotate(direction):
'''Rotate the entire cube (0 = clockwise, 1 = counterclockwise).'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 2)
txOpcode = "0C".decode('hex')
txData = format(direction, '02x').decode('hex')
sock.send(txFrame + txOpcode + txData)
 
def cube_rotate_shell(direction, shell):
'''Rotate a specific layer (0 = clockwise, 0 = outermost layer).'''
# Generate and send the frame
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 3)
txOpcode = "0D".decode('hex')
txData = ''.join("%02x%02x" % (direction, shell))
sock.send(txFrame + txOpcode + txData.decode('hex'))
 
# def cube_update():
# '''Update the cube with the current frame buffer.
# Note: this requires jumbo frames (1536 bytes).'''
# # Generate the header, opcode, and format the frame buffer
# txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 0x0601)
# txOpcode = "10".decode('hex')
# txData = ''.join("%02x" % (x) for x in frame_buffer)
# sock.send(txFrame + txOpcode + txData.decode('hex'))
 
def cube_update_pixel(x, y, z, r, g, b):
'''Set a specific pixel on the cube.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 7)
txOpcode = "11".decode('hex')
frame = [x, y, z, r, g, b]
txData = ''.join("%02x" % (x) for x in frame)
sock.send(txFrame + txOpcode + txData.decode('hex'))
 
def cube_update():
'''Updates the cube with the current frame buffer.
The buffer is sent in three frames, one for each color channel.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 514)
txOpcode = "12".decode('hex')
for c in range(3):
txColorCh = "%02x" % c
txData = ''.join( ["%02x" % (x) for x in frame_buffer[c::3]])
payload = txFrame + txOpcode + txColorCh.decode('hex') + txData.decode('hex')
sock.send(payload)
time.sleep(0.01) # This value can be smaller (and should be) to reduce flickering
 
def cube_update_text_scrolling(string, r, g, b, update_rate):
'''Sets the scrolling text on the cube.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, len(string) + 6)
txOpcode = "20".decode('hex')
txData = ''.join("%02x%02x%02x%02x%02x" % (len(string), r, g, b, update_rate))
txString = string.encode('hex')
sock.send(txFrame + txOpcode + txData.decode('hex') + txString.decode('hex'))
 
def cube_update_text_static(string, r, g, b):
'''Sets the static text on the cube.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, len(string) + 5)
txOpcode = "21".decode('hex')
txData = ''.join("%02x%02x%02x%02x" % (len(string), r, g, b))
txString = string.encode('hex')
sock.send(txFrame + txOpcode + txData.decode('hex') + txString.decode('hex'))
 
def cube_update_text_insert(character, r, g, b, delay):
'''Appends a character to the beginning of the text buffer.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 6)
txOpcode = "22".decode('hex')
txData = ''.join("%02x%02x%02x%02x%02x" % (r, g, b, delay, character))
sock.send(txFrame + txOpcode + txData.decode('hex'))
 
def cube_update_waterfall(c0, c1, c2, c3, c4, c5, c6, c7):
'''Fills in one row and shifts rows by one.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 9)
txOpcode = "30".decode('hex')
txData = ''.join("%02x%02x%02x%02x%02x%02x%02x%02x" % (c0, c1, c2, c3, c4, c5, c6, c7))
sock.send(txFrame + txOpcode + txData.decode('hex'))
 
def cube_update_sphere(layer, r, g, b):
'''Sets the sphere layer to the specified color.'''
txFrame = struct.pack("!6s6sH", dst_addr, hw_addr, 5)
txOpcode = "31".decode('hex')
txData = ''.join("%02x%02x%02x%02x" % (layer, r, g, b))
sock.send(txFrame + txOpcode + txData.decode('hex'))
 
def fb_clear():
'''Clears the frame buffer/'''
for row in range(8):
for column in range(8):
for layer in range(8):
fb_set_pixel(row, column, layer, 0x00, 0x00, 0x00)
 
def fb_set_pixel(row, column, layer, R, G, B):
'''Sets a pixel to the given color in the frame buffer/'''
frame_buffer[layer * 192 + column * 24 + row * 3 + 0] = R
frame_buffer[layer * 192 + column * 24 + row * 3 + 1] = G
frame_buffer[layer * 192 + column * 24 + row * 3 + 2] = B
 
def fb_set_layer(layer, R, G, B):
'''Sets an entire layer to the given color in the frame buffer'''
for row in range(8):
for column in range(8):
fb_set_pixel(row, column, layer, R, G, B)
def fb_set_all(R, G, B):
'''Sets all the pixels in the frame buffer to the given color'''
for row in range(8):
for column in range(8):
for layer in range(8):
fb_set_pixel(row, column, layer, R, G, B)
/PIC Projects/Cerebot_32MX7_LED_Cube/Ethernet API/animations.py
0,0 → 1,59
from cube import *
from time import sleep
 
def solid_colors(delay):
fb_set_all(0xFF, 0x00, 0x00)
cube_update()
sleep(delay)
fb_set_all(0x00, 0xFF, 0x00)
cube_update()
sleep(delay)
fb_set_all(0x00, 0x00, 0xFF)
cube_update()
sleep(delay)
 
def row_column_sweep(delay):
# Sweep across three colors (R,G,B)
for color in range(3):
# Sweep across each row
for row in range(8):
fb_set_clear()
for column in range(8):
for layer in range(8):
if color % 3 == 0:
fb_set_pixel(row, column, layer, 0xFF, 0x00, 0x00)
elif color % 3 == 1:
fb_set_pixel(row, column, layer, 0x00, 0xFF, 0x00)
else:
fb_set_pixel(row, column, layer, 0x00, 0x00, 0xFF)
cube_update()
sleep(delay)
# Sweep across each column
for column in range(8):
fb_set_clear()
for row in range(8):
for layer in range(8):
if color % 3 == 0:
fb_set_pixel(row, column, layer, 0xFF, 0x00, 0x00)
elif color % 3 == 1:
fb_set_pixel(row, column, layer, 0x00, 0xFF, 0x00)
else:
fb_set_pixel(row, column, layer, 0x00, 0x00, 0xFF)
cube_update()
sleep(delay)
# Sweep across each layer
for layer in range(7, -1, -1):
fb_set_clear()
for layer_2 in range(8):
if color % 3 == 0:
if layer_2 == layer:
set_layer(layer_2, 0xFF, 0x00, 0x00)
elif color % 3 == 1:
if layer_2 == layer:
set_layer(layer_2, 0x00, 0xFF, 0x00)
else:
if layer_2 == layer:
set_layer(layer_2, 0x00, 0x00, 0xFF)
cube_update()
sleep(delay)
/PIC Projects/Cerebot_32MX7_LED_Cube/Ethernet API/main.py
0,0 → 1,44
from cube import *
import animations
from time import sleep
 
if __name__ == '__main__':
# Put the cube into ethernet mode
print "Initializing cube. Wait 6 seconds...\n"
# cube_init()
# ----- Begin animations -----
 
cube_clear()
cube_update_text("CCM LAB ", 0xFF, 0xFF, 0xFF, 100)
print "Looping animations...\n"
while(1):
 
# for i in range(9):
# cube_clear()
# cube_update_sphere(i, 0xFF, 0x00, 0x00)
# sleep(0.1)
 
cube_update_waterfall(1, 2, 3, 4, 5, 6, 7, 8)
sleep(0.1)
 
# #cube_update_pixel(x, y, z, r, g, b)
# for x in range(8):
# for y in range(8):
# for z in range(8):
# cube_update_pixel(x, y, z, 255, 255, 255)
# time.sleep(0.11)
# cube_update_pixel(x, y, z, 0, 0, 0)
# time.sleep(0.1)
# #time.sleep(0.1)
# ----- End Animations -----
 
# Reset the cube into idle mode (optional)
print "Animations done. Returning board to idle mode..."
cube_reset()
/PIC Projects/Cerebot_32MX7_LED_Cube/defines.h
0,0 → 1,55
// PIC32MX795F512L
 
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <plib.h>
#include <stdint.h>
 
// Uncomment ONE of the following:
#define CEREBOT_32MX7
// #define CEREBOT_MX7CK
 
#define CPU_CLOCK_HZ 80000000UL
#define PERIPHERAL_CLOCK_HZ 80000000UL
#define CPU_CT_HZ (CPU_CLOCK_HZ/2UL)
#define MS_TO_CT_TICKS (CPU_CLOCK_HZ/2000UL)
#define US_TO_CT_TICKS (CPU_CLOCK_HZ/2000000UL)
 
#define ADDRESS_EEPROM 0x50
#define ADDRESS_CONTROLLER_1 0x24
#define ADDRESS_CONTROLLER_2 0x25
 
// LED1 = G12, LED2 = G13, LED3 = G14, LED4 = G15 (active high)
#define LED1_TRIS TRISGbits.TRISG12
#define LED1_LAT LATGbits.LATG12
#define LED2_TRIS TRISGbits.TRISG13
#define LED2_LAT LATGbits.LATG13
#define LED3_TRIS TRISGbits.TRISG14
#define LED3_LAT LATGbits.LATG14
#define LED4_TRIS TRISGbits.TRISG15
#define LED4_LAT LATGbits.LATG15
 
// Reset conditions
#define RESET_POR 0x01 // Power on reset
#define RESET_BOR 0x02 // Brown out reset
#define RESET_SWR 0x03 // Software reset
#define RESET_WDT 0x04 // Watchdog timer reset
#define RESET_PIN 0x05 // MCLR pin reset
#define RESET_CFG 0x06 // Config mismatch reset
 
// Board 'modes' (idle/games/etc)
#define BOARD_MODE_IDLE 0x1
#define BOARD_MODE_SNAKE 0x2
#define BOARD_MODE_TRON 0x3
#define BOARD_MODE_ETHERNET 0x4
 
void Delay_MS(uint32_t delay_ms);
void Delay_US(uint32_t delay_us);
uint8_t Get_Reset_Condition(void);
uint8_t Get_Board_State(void);
void Reset_Board(uint8_t next_state);
void Idle_Animation_Sequence(void);
 
#endif /* DEFINES_H */
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Tue Mar 25 18:15:21 EDT 2014
default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=83f4565fa27ad9b8015f63d69ef74f66
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc32\\v1.31\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.31
host.platform=windows
conf.ids=default
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/private/private.xml
0,0 → 1,12
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/CONTROLLERS.h</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/SNAKE.h</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/TRON.h</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/main.c</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/CONTROLLERS.c</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/TRON.c</file>
<file>file:/C:/Users/Kevin/Documents/Code/Cerebot_32MX7_LED_Cube/SNAKE.c</file>
</open-files>
</project-private>
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>8108:=&lt;rev>0002:=&lt;man>Digilent:=&lt;prod>Cerebot 32MX7:=&lt;sn>D370400:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc32\v1.31\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/private/private.properties
--- Cerebot_32MX7_LED_Cube/nbproject/configurations.xml (nonexistent)
+++ Cerebot_32MX7_LED_Cube/nbproject/configurations.xml (revision 342)
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configurationDescriptor version="62">
+ <logicalFolder name="root" displayName="root" projectFiles="true">
+ <logicalFolder name="HeaderFiles"
+ displayName="Header Files"
+ projectFiles="true">
+ <itemPath>defines.h</itemPath>
+ <itemPath>SPI1.h</itemPath>
+ <itemPath>TIMER5.h</itemPath>
+ <itemPath>CUBE.h</itemPath>
+ <itemPath>BTN.h</itemPath>
+ <itemPath>PWM2.h</itemPath>
+ <itemPath>TIMER4.h</itemPath>
+ <itemPath>glcdfont.h</itemPath>
+ <itemPath>UART1.h</itemPath>
+ <itemPath>SPI4.h</itemPath>
+ <itemPath>ANIMATIONS.h</itemPath>
+ <itemPath>I2C1.h</itemPath>
+ <itemPath>CONTROLLERS.h</itemPath>
+ <itemPath>SNAKE.h</itemPath>
+ <itemPath>TRON.h</itemPath>
+ <itemPath>ETHERNET.h</itemPath>
+ </logicalFolder>
+ <logicalFolder name="LinkerScript"
+ displayName="Linker Files"
+ projectFiles="true">
+ </logicalFolder>
+ <logicalFolder name="SourceFiles"
+ displayName="Source Files"
+ projectFiles="true">
+ <itemPath>main.c</itemPath>
+ <itemPath>SPI1.c</itemPath>
+ <itemPath>TIMER5.c</itemPath>
+ <itemPath>CUBE.c</itemPath>
+ <itemPath>PWM2.c</itemPath>
+ <itemPath>BTN.c</itemPath>
+ <itemPath>TIMER4.c</itemPath>
+ <itemPath>UART1.c</itemPath>
+ <itemPath>SPI4.c</itemPath>
+ <itemPath>ANIMATIONS.c</itemPath>
+ <itemPath>I2C1.c</itemPath>
+ <itemPath>CONTROLLERS.c</itemPath>
+ <itemPath>SNAKE.c</itemPath>
+ <itemPath>TRON.c</itemPath>
+ <itemPath>ETHERNET.c</itemPath>
+ </logicalFolder>
+ <logicalFolder name="ExternalFiles"
+ displayName="Important Files"
+ projectFiles="false">
+ <itemPath>Makefile</itemPath>
+ <itemPath>README.txt</itemPath>
+ </logicalFolder>
+ </logicalFolder>
+ <projectmakefile>Makefile</projectmakefile>
+ <confs>
+ <conf name="default" type="2">
+ <toolsSet>
+ <developmentServer>localhost</developmentServer>
+ <targetDevice>PIC32MX795F512L</targetDevice>
+ <targetHeader></targetHeader>
+ <targetPluginBoard></targetPluginBoard>
+ <platformTool>PK3OBPlatformTool</platformTool>
+ <languageToolchain>XC32</languageToolchain>
+ <languageToolchainVersion>1.31</languageToolchainVersion>
+ <platform>3</platform>
+ </toolsSet>
+ <compileType>
+ <linkerTool>
+ <linkerLibItems>
+ </linkerLibItems>
+ </linkerTool>
+ <loading>
+ <useAlternateLoadableFile>false</useAlternateLoadableFile>
+ <alternateLoadableFile></alternateLoadableFile>
+ </loading>
+ </compileType>
+ <makeCustomizationType>
+ <makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
+ <makeCustomizationPreStep></makeCustomizationPreStep>
+ <makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
+ <makeCustomizationPostStep></makeCustomizationPostStep>
+ <makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
+ <makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
+ <makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
+ </makeCustomizationType>
+ <C32>
+ <property key="additional-warnings" value="false"/>
+ <property key="enable-app-io" value="false"/>
+ <property key="enable-omit-frame-pointer" value="false"/>
+ <property key="enable-symbols" value="true"/>
+ <property key="enable-unroll-loops" value="true"/>
+ <property key="exclude-floating-point" value="false"/>
+ <property key="extra-include-directories" value=""/>
+ <property key="generate-16-bit-code" value="false"/>
+ <property key="generate-micro-compressed-code" value="false"/>
+ <property key="isolate-each-function" value="false"/>
+ <property key="make-warnings-into-errors" value="false"/>
+ <property key="optimization-level" value="-O1"/>
+ <property key="place-data-into-section" value="false"/>
+ <property key="post-instruction-scheduling" value="default"/>
+ <property key="pre-instruction-scheduling" value="default"/>
+ <property key="preprocessor-macros" value=""/>
+ <property key="strict-ansi" value="false"/>
+ <property key="support-ansi" value="false"/>
+ <property key="use-cci" value="false"/>
+ <property key="use-iar" value="false"/>
+ <property key="use-indirect-calls" value="false"/>
+ </C32>
+ <C32-AS>
+ <property key="assembler-symbols" value=""/>
+ <property key="enable-symbols" value="true"/>
+ <property key="exclude-floating-point-library" value="false"/>
+ <property key="expand-macros" value="false"/>
+ <property key="extra-include-directories-for-assembler" value=""/>
+ <property key="extra-include-directories-for-preprocessor" value=""/>
+ <property key="false-conditionals" value="false"/>
+ <property key="keep-locals" value="false"/>
+ <property key="list-assembly" value="false"/>
+ <property key="list-source" value="false"/>
+ <property key="list-symbols" value="false"/>
+ <property key="oXC32asm-list-to-file" value="false"/>
+ <property key="omit-debug-dirs" value="false"/>
+ <property key="omit-forms" value="false"/>
+ <property key="preprocessor-macros" value=""/>
+ <property key="warning-level" value=""/>
+ </C32-AS>
+ <C32-LD>
+ <property key="additional-options-use-response-files" value="false"/>
+ <property key="enable-check-sections" value="false"/>
+ <property key="exclude-floating-point-library" value="false"/>
+ <property key="exclude-standard-libraries" value="false"/>
+ <property key="extra-lib-directories" value=""/>
+ <property key="generate-16-bit-code" value="false"/>
+ <property key="generate-cross-reference-file" value="false"/>
+ <property key="generate-micro-compressed-code" value="false"/>
+ <property key="heap-size" value=""/>
+ <property key="input-libraries" value=""/>
+ <property key="linker-symbols" value=""/>
+ <property key="map-file" value=""/>
+ <property key="no-startup-files" value="false"/>
+ <property key="oXC32ld-extra-opts" value=""/>
+ <property key="optimization-level" value=""/>
+ <property key="preprocessor-macros" value=""/>
+ <property key="remove-unused-sections" value="false"/>
+ <property key="report-memory-usage" value="true"/>
+ <property key="stack-size" value=""/>
+ <property key="symbol-stripping" value=""/>
+ <property key="trace-symbols" value=""/>
+ <property key="warn-section-align" value="false"/>
+ </C32-LD>
+ <C32CPP>
+ <property key="additional-warnings" value="false"/>
+ <property key="check-new" value="false"/>
+ <property key="eh-specs" value="true"/>
+ <property key="enable-app-io" value="false"/>
+ <property key="enable-omit-frame-pointer" value="false"/>
+ <property key="enable-symbols" value="true"/>
+ <property key="enable-unroll-loops" value="true"/>
+ <property key="exceptions" value="true"/>
+ <property key="exclude-floating-point" value="false"/>
+ <property key="extra-include-directories" value=""/>
+ <property key="generate-16-bit-code" value="false"/>
+ <property key="generate-micro-compressed-code" value="false"/>
+ <property key="isolate-each-function" value="false"/>
+ <property key="make-warnings-into-errors" value="false"/>
+ <property key="optimization-level" value="-O1"/>
+ <property key="place-data-into-section" value="false"/>
+ <property key="post-instruction-scheduling" value="default"/>
+ <property key="pre-instruction-scheduling" value="default"/>
+ <property key="preprocessor-macros" value=""/>
+ <property key="rtti" value="true"/>
+ <property key="strict-ansi" value="false"/>
+ <property key="use-cci" value="false"/>
+ <property key="use-iar" value="false"/>
+ <property key="use-indirect-calls" value="false"/>
+ </C32CPP>
+ <C32Global>
+ <property key="legacy-libc" value="false"/>
+ <property key="save-temps" value="false"/>
+ <property key="wpo-lto" value="false"/>
+ </C32Global>
+ <PK3OBPlatformTool>
+ <property key="AutoSelectMemRanges" value="auto"/>
+ <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
+ <property key="ToolFirmwareFilePath"
+ value="Press to browse for a specific firmware version"/>
+ <property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
+ <property key="memories.bootflash" value="false"/>
+ <property key="memories.configurationmemory" value="false"/>
+ <property key="memories.eeprom" value="false"/>
+ <property key="memories.id" value="false"/>
+ <property key="memories.programmemory" value="true"/>
+ <property key="memories.programmemory.end" value="0x1d07ffff"/>
+ <property key="memories.programmemory.start" value="0x1d000000"/>
+ <property key="poweroptions.powerenable" value="false"/>
+ <property key="programoptions.eraseb4program" value="true"/>
+ <property key="programoptions.preserveeeprom" value="false"/>
+ <property key="programoptions.preserveprogramrange" value="false"/>
+ <property key="programoptions.preserveprogramrange.end" value="0x1d0001ff"/>
+ <property key="programoptions.preserveprogramrange.start" value="0x1d000000"/>
+ <property key="programoptions.usehighvoltageonmclr" value="false"/>
+ <property key="programoptions.uselvpprogramming" value="false"/>
+ <property key="voltagevalue" value="3.25"/>
+ </PK3OBPlatformTool>
+ </conf>
+ </confs>
+</configurationDescriptor>
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/project.xml
0,0 → 1,16
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>Cerebot_32MX7_LED_Cube</name>
<creation-uuid>a23479a1-6afc-4362-a20c-e5ddcf3c7815</creation-uuid>
<make-project-type>0</make-project-type>
<c-extensions>c</c-extensions>
<cpp-extensions/>
<header-extensions>h</header-extensions>
<sourceEncoding>ISO-8859-1</sourceEncoding>
<asminc-extensions/>
<make-dep-projects/>
</data>
</configuration>
</project>
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Makefile-default.mk
0,0 → 1,316
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c SPI1.c TIMER5.c CUBE.c PWM2.c BTN.c TIMER4.c UART1.c SPI4.c ANIMATIONS.c I2C1.c CONTROLLERS.c SNAKE.c TRON.c ETHERNET.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o ${OBJECTDIR}/BTN.o ${OBJECTDIR}/TIMER4.o ${OBJECTDIR}/UART1.o ${OBJECTDIR}/SPI4.o ${OBJECTDIR}/ANIMATIONS.o ${OBJECTDIR}/I2C1.o ${OBJECTDIR}/CONTROLLERS.o ${OBJECTDIR}/SNAKE.o ${OBJECTDIR}/TRON.o ${OBJECTDIR}/ETHERNET.o
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/SPI1.o.d ${OBJECTDIR}/TIMER5.o.d ${OBJECTDIR}/CUBE.o.d ${OBJECTDIR}/PWM2.o.d ${OBJECTDIR}/BTN.o.d ${OBJECTDIR}/TIMER4.o.d ${OBJECTDIR}/UART1.o.d ${OBJECTDIR}/SPI4.o.d ${OBJECTDIR}/ANIMATIONS.o.d ${OBJECTDIR}/I2C1.o.d ${OBJECTDIR}/CONTROLLERS.o.d ${OBJECTDIR}/SNAKE.o.d ${OBJECTDIR}/TRON.o.d ${OBJECTDIR}/ETHERNET.o.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/SPI1.o ${OBJECTDIR}/TIMER5.o ${OBJECTDIR}/CUBE.o ${OBJECTDIR}/PWM2.o ${OBJECTDIR}/BTN.o ${OBJECTDIR}/TIMER4.o ${OBJECTDIR}/UART1.o ${OBJECTDIR}/SPI4.o ${OBJECTDIR}/ANIMATIONS.o ${OBJECTDIR}/I2C1.o ${OBJECTDIR}/CONTROLLERS.o ${OBJECTDIR}/SNAKE.o ${OBJECTDIR}/TRON.o ${OBJECTDIR}/ETHERNET.o
 
# Source Files
SOURCEFILES=main.c SPI1.c TIMER5.c CUBE.c PWM2.c BTN.c TIMER4.c UART1.c SPI4.c ANIMATIONS.c I2C1.c CONTROLLERS.c SNAKE.c TRON.c ETHERNET.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=32MX795F512L
MP_LINKER_FILE_OPTION=
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assembleWithPreprocess
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/SPI1.o: SPI1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI1.o.d
@${RM} ${OBJECTDIR}/SPI1.o
@${FIXDEPS} "${OBJECTDIR}/SPI1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SPI1.o.d" -o ${OBJECTDIR}/SPI1.o SPI1.c
${OBJECTDIR}/TIMER5.o: TIMER5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER5.o.d
@${RM} ${OBJECTDIR}/TIMER5.o
@${FIXDEPS} "${OBJECTDIR}/TIMER5.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TIMER5.o.d" -o ${OBJECTDIR}/TIMER5.o TIMER5.c
${OBJECTDIR}/CUBE.o: CUBE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CUBE.o.d
@${RM} ${OBJECTDIR}/CUBE.o
@${FIXDEPS} "${OBJECTDIR}/CUBE.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/CUBE.o.d" -o ${OBJECTDIR}/CUBE.o CUBE.c
${OBJECTDIR}/PWM2.o: PWM2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM2.o.d
@${RM} ${OBJECTDIR}/PWM2.o
@${FIXDEPS} "${OBJECTDIR}/PWM2.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/PWM2.o.d" -o ${OBJECTDIR}/PWM2.o PWM2.c
${OBJECTDIR}/BTN.o: BTN.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/BTN.o.d
@${RM} ${OBJECTDIR}/BTN.o
@${FIXDEPS} "${OBJECTDIR}/BTN.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/BTN.o.d" -o ${OBJECTDIR}/BTN.o BTN.c
${OBJECTDIR}/TIMER4.o: TIMER4.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER4.o.d
@${RM} ${OBJECTDIR}/TIMER4.o
@${FIXDEPS} "${OBJECTDIR}/TIMER4.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TIMER4.o.d" -o ${OBJECTDIR}/TIMER4.o TIMER4.c
${OBJECTDIR}/UART1.o: UART1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART1.o.d
@${RM} ${OBJECTDIR}/UART1.o
@${FIXDEPS} "${OBJECTDIR}/UART1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/UART1.o.d" -o ${OBJECTDIR}/UART1.o UART1.c
${OBJECTDIR}/SPI4.o: SPI4.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI4.o.d
@${RM} ${OBJECTDIR}/SPI4.o
@${FIXDEPS} "${OBJECTDIR}/SPI4.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SPI4.o.d" -o ${OBJECTDIR}/SPI4.o SPI4.c
${OBJECTDIR}/ANIMATIONS.o: ANIMATIONS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ANIMATIONS.o.d
@${RM} ${OBJECTDIR}/ANIMATIONS.o
@${FIXDEPS} "${OBJECTDIR}/ANIMATIONS.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/ANIMATIONS.o.d" -o ${OBJECTDIR}/ANIMATIONS.o ANIMATIONS.c
${OBJECTDIR}/I2C1.o: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.o.d
@${RM} ${OBJECTDIR}/I2C1.o
@${FIXDEPS} "${OBJECTDIR}/I2C1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/I2C1.o.d" -o ${OBJECTDIR}/I2C1.o I2C1.c
${OBJECTDIR}/CONTROLLERS.o: CONTROLLERS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CONTROLLERS.o.d
@${RM} ${OBJECTDIR}/CONTROLLERS.o
@${FIXDEPS} "${OBJECTDIR}/CONTROLLERS.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/CONTROLLERS.o.d" -o ${OBJECTDIR}/CONTROLLERS.o CONTROLLERS.c
${OBJECTDIR}/SNAKE.o: SNAKE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SNAKE.o.d
@${RM} ${OBJECTDIR}/SNAKE.o
@${FIXDEPS} "${OBJECTDIR}/SNAKE.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SNAKE.o.d" -o ${OBJECTDIR}/SNAKE.o SNAKE.c
${OBJECTDIR}/TRON.o: TRON.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TRON.o.d
@${RM} ${OBJECTDIR}/TRON.o
@${FIXDEPS} "${OBJECTDIR}/TRON.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TRON.o.d" -o ${OBJECTDIR}/TRON.o TRON.c
${OBJECTDIR}/ETHERNET.o: ETHERNET.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ETHERNET.o.d
@${RM} ${OBJECTDIR}/ETHERNET.o
@${FIXDEPS} "${OBJECTDIR}/ETHERNET.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/ETHERNET.o.d" -o ${OBJECTDIR}/ETHERNET.o ETHERNET.c
else
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/SPI1.o: SPI1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI1.o.d
@${RM} ${OBJECTDIR}/SPI1.o
@${FIXDEPS} "${OBJECTDIR}/SPI1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SPI1.o.d" -o ${OBJECTDIR}/SPI1.o SPI1.c
${OBJECTDIR}/TIMER5.o: TIMER5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER5.o.d
@${RM} ${OBJECTDIR}/TIMER5.o
@${FIXDEPS} "${OBJECTDIR}/TIMER5.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TIMER5.o.d" -o ${OBJECTDIR}/TIMER5.o TIMER5.c
${OBJECTDIR}/CUBE.o: CUBE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CUBE.o.d
@${RM} ${OBJECTDIR}/CUBE.o
@${FIXDEPS} "${OBJECTDIR}/CUBE.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/CUBE.o.d" -o ${OBJECTDIR}/CUBE.o CUBE.c
${OBJECTDIR}/PWM2.o: PWM2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM2.o.d
@${RM} ${OBJECTDIR}/PWM2.o
@${FIXDEPS} "${OBJECTDIR}/PWM2.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/PWM2.o.d" -o ${OBJECTDIR}/PWM2.o PWM2.c
${OBJECTDIR}/BTN.o: BTN.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/BTN.o.d
@${RM} ${OBJECTDIR}/BTN.o
@${FIXDEPS} "${OBJECTDIR}/BTN.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/BTN.o.d" -o ${OBJECTDIR}/BTN.o BTN.c
${OBJECTDIR}/TIMER4.o: TIMER4.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER4.o.d
@${RM} ${OBJECTDIR}/TIMER4.o
@${FIXDEPS} "${OBJECTDIR}/TIMER4.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TIMER4.o.d" -o ${OBJECTDIR}/TIMER4.o TIMER4.c
${OBJECTDIR}/UART1.o: UART1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART1.o.d
@${RM} ${OBJECTDIR}/UART1.o
@${FIXDEPS} "${OBJECTDIR}/UART1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/UART1.o.d" -o ${OBJECTDIR}/UART1.o UART1.c
${OBJECTDIR}/SPI4.o: SPI4.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SPI4.o.d
@${RM} ${OBJECTDIR}/SPI4.o
@${FIXDEPS} "${OBJECTDIR}/SPI4.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SPI4.o.d" -o ${OBJECTDIR}/SPI4.o SPI4.c
${OBJECTDIR}/ANIMATIONS.o: ANIMATIONS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ANIMATIONS.o.d
@${RM} ${OBJECTDIR}/ANIMATIONS.o
@${FIXDEPS} "${OBJECTDIR}/ANIMATIONS.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/ANIMATIONS.o.d" -o ${OBJECTDIR}/ANIMATIONS.o ANIMATIONS.c
${OBJECTDIR}/I2C1.o: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.o.d
@${RM} ${OBJECTDIR}/I2C1.o
@${FIXDEPS} "${OBJECTDIR}/I2C1.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/I2C1.o.d" -o ${OBJECTDIR}/I2C1.o I2C1.c
${OBJECTDIR}/CONTROLLERS.o: CONTROLLERS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CONTROLLERS.o.d
@${RM} ${OBJECTDIR}/CONTROLLERS.o
@${FIXDEPS} "${OBJECTDIR}/CONTROLLERS.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/CONTROLLERS.o.d" -o ${OBJECTDIR}/CONTROLLERS.o CONTROLLERS.c
${OBJECTDIR}/SNAKE.o: SNAKE.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/SNAKE.o.d
@${RM} ${OBJECTDIR}/SNAKE.o
@${FIXDEPS} "${OBJECTDIR}/SNAKE.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/SNAKE.o.d" -o ${OBJECTDIR}/SNAKE.o SNAKE.c
${OBJECTDIR}/TRON.o: TRON.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TRON.o.d
@${RM} ${OBJECTDIR}/TRON.o
@${FIXDEPS} "${OBJECTDIR}/TRON.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/TRON.o.d" -o ${OBJECTDIR}/TRON.o TRON.c
${OBJECTDIR}/ETHERNET.o: ETHERNET.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ETHERNET.o.d
@${RM} ${OBJECTDIR}/ETHERNET.o
@${FIXDEPS} "${OBJECTDIR}/ETHERNET.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -MMD -MF "${OBJECTDIR}/ETHERNET.o.d" -o ${OBJECTDIR}/ETHERNET.o ETHERNET.c
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: compileCPP
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) -mdebugger -D__MPLAB_DEBUGGER_PK3=1 -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -mreserve=data@0x0:0x1FC -mreserve=boot@0x1FC02000:0x1FC02FEF -mreserve=boot@0x1FC02000:0x1FC024FF -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),--defsym=__MPLAB_DEBUG=1,--defsym=__DEBUG=1,--defsym=__MPLAB_DEBUGGER_PK3=1,--report-mem
else
dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),--report-mem
${MP_CC_DIR}\\xc32-bin2hex dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-gcc.exe"
MP_CPPC="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-g++.exe"
# MP_BC is not defined
MP_AS="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-as.exe"
MP_LD="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-ld.exe"
MP_AR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-ar.exe"
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_CPPC_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
# MP_BC_DIR is not defined
MP_AS_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_LD_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_AR_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
# MP_BC_DIR is not defined
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=Cerebot_32MX7_LED_Cube
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=Cerebot_32MX7_LED_Cube.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/Cerebot_32MX7_LED_Cube.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=cerebot32mx7ledcube.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/cerebot32mx7ledcube.tar
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=Cerebot_32MX7_LED_Cube.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=cerebot32mx7ledcube/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/cerebot32mx7ledcube/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/cerebot32mx7ledcube.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/cerebot32mx7ledcube.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/Cerebot_32MX7_LED_Cube/nbproject/project.properties
--- Cerebot_32MX7_LED_Cube/CONTROLLERS.c (nonexistent)
+++ Cerebot_32MX7_LED_Cube/CONTROLLERS.c (revision 342)
@@ -0,0 +1,199 @@
+#include "defines.h"
+#include "CONTROLLERS.h"
+#include "I2C1.h"
+
+static CONTROLLER_DATA *ctrl_data_p;
+
+void Controller_Init(CONTROLLER_DATA *data,
+ void (*change_callback)(uint8_t controller, CTRL_BTN_STATUS values)) {
+
+ if (data != NULL)
+ ctrl_data_p = data;
+ ctrl_data_p->change_callback = change_callback;
+
+ // Variable initialization
+ int i, j;
+ for (i = 0; i < CONTROLLER_MAX_COUNT; i++) {
+ ctrl_data_p->connected_controllers[i] = 0x0;
+ ctrl_data_p->led_status[i].w[i] = 0x0;
+ ctrl_data_p->btn_prev[i].w = 0x0;
+ ctrl_data_p->btn_curr[i].w = 0x0;
+ for (j = 0; j < 16; j++) {
+ ctrl_data_p->led_status[i].w[j] = 0x0;
+ }
+ }
+
+ ctrl_data_p->connected_count = 0x0;
+ ctrl_data_p->next_poll = 0x0;
+
+ // Poll to see which controllers are connected
+ Controller_Poll_Connected();
+}
+
+void Controller_Poll_Connected(void) {
+ uint8_t buffer[2];
+ uint8_t result, i;
+ uint8_t address = CONTROLLER_PREFIX_ADDRESS + CONTROLLER_START_ADDRESS;
+
+ // Attempt to contact each controller to see if its connected
+ for (i = 0; i < CONTROLLER_MAX_COUNT; i++) {
+ I2C1_Master_Restart(address + i, CONTROLLER_CMD_READ, 1);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+ if (result == I2C1_RECV_OK) {
+ uint8_t length = I2C1_Read_Buffer(buffer);
+ // If a controller is connected, save its address
+ ctrl_data_p->connected_controllers[ctrl_data_p->connected_count] = address + i;
+ ctrl_data_p->connected_count++;
+ }
+
+ // A small delay is needed between polls
+ Delay_US(500);
+ }
+
+ // Show the number of controllers connected
+ if (ctrl_data_p->connected_count & 0x1)
+ LED1_LAT = 1;
+ if (ctrl_data_p->connected_count & 0x2)
+ LED2_LAT = 1;
+ if (ctrl_data_p->connected_count & 0x4)
+ LED3_LAT = 1;
+ if (ctrl_data_p->connected_count & 0x8)
+ LED4_LAT = 1;
+}
+
+void Controller_Update(void) {
+ uint8_t buffer[2];
+ uint8_t result, length;
+ CTRL_BTN_STATUS btn_change;
+
+ uint8_t controller = ctrl_data_p->next_poll;
+
+ // Store the last read values
+ ctrl_data_p->btn_prev[controller] = ctrl_data_p->btn_curr[controller];
+
+ // Read in the button values for each controller
+ I2C1_Master_Restart(ctrl_data_p->connected_controllers[controller], CONTROLLER_CMD_READ, 1);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+ // Save the read values
+ length = I2C1_Read_Buffer(buffer);
+ ctrl_data_p->btn_curr[controller].w = buffer[0];
+
+ // Determine if a change was made between the current and previous values
+ if (ctrl_data_p->btn_curr[controller].w != ctrl_data_p->btn_prev[controller].w) {
+ // Determine if a button was pressed (unpressed->pressed)
+ btn_change.w = ctrl_data_p->btn_prev[controller].w ^ ctrl_data_p->btn_curr[controller].w;
+ btn_change.w &= ctrl_data_p->btn_curr[controller].w;
+
+ // If a button was pressed, call the saved callback
+ if (btn_change.w) {
+ if (ctrl_data_p->change_callback != NULL) {
+ ctrl_data_p->change_callback(controller, btn_change);
+ }
+ }
+ }
+
+ ctrl_data_p->next_poll = (controller == ctrl_data_p->connected_count - 1) ? 0x0 : controller+1;
+}
+
+void Controller_Set_Left_Leds(uint8_t controller, uint8_t value) {
+ uint8_t result, i;
+ uint8_t buffer[18];
+
+ for (i = 0; i < 4; i++) {
+ if (value & (0x01 << i))
+ ctrl_data_p->led_status[controller].w[i+12] = CONTROLLER_BRIGHTNESS_HIGH;
+ else
+ ctrl_data_p->led_status[controller].w[i+12] = 0x00;
+ }
+
+ // Write the LED value to the controller
+ buffer[0] = CONTROLLER_CMD_WRITE;
+ for (i = 0; i < 16; i++)
+ buffer[i+1] = ctrl_data_p->led_status[controller].w[i];
+ I2C1_Master_Send(ctrl_data_p->connected_controllers[controller], buffer, 17);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+
+ Delay_MS(1);
+}
+
+void Controller_Set_Middle_Leds(uint8_t controller, uint8_t value) {
+ uint8_t result, i;
+ uint8_t buffer[18];
+
+ for (i = 0; i < 8; i++) {
+ if (value & (0x01 << i))
+ ctrl_data_p->led_status[controller].w[i] = CONTROLLER_BRIGHTNESS_HIGH;
+ else
+ ctrl_data_p->led_status[controller].w[i] = 0x00;
+ }
+
+ // Write the LED value to the controller
+ buffer[0] = CONTROLLER_CMD_WRITE;
+ for (i = 0; i < 16; i++)
+ buffer[i+1] = ctrl_data_p->led_status[controller].w[i];
+ I2C1_Master_Send(ctrl_data_p->connected_controllers[controller], buffer, 17);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+
+ Delay_MS(1);
+}
+
+void Controller_Set_Right_Leds(uint8_t controller, uint8_t value) {
+ uint8_t result, i;
+ uint8_t buffer[18];
+
+ for (i = 0; i < 4; i++) {
+ if (value & (0x01 << i))
+ ctrl_data_p->led_status[controller].w[i+8] = CONTROLLER_BRIGHTNESS_HIGH;
+ else
+ ctrl_data_p->led_status[controller].w[i+8] = 0x00;
+ }
+
+ // Write the LED value to the controller
+ buffer[0] = CONTROLLER_CMD_WRITE;
+ for (i = 0; i < 16; i++)
+ buffer[i+1] = ctrl_data_p->led_status[controller].w[i];
+ I2C1_Master_Send(ctrl_data_p->connected_controllers[controller], buffer, 17);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+
+ Delay_MS(1);
+}
+
+uint8_t Controller_Get_Connected(void) {
+ return ctrl_data_p->connected_count;
+}
+
+void Controller_Set_Active(uint8_t controller) {
+ uint8_t buffer[2];
+ uint8_t result;
+
+ buffer[0] = CONTROLLER_CMD_ACTIVE;
+ I2C1_Master_Send(ctrl_data_p->connected_controllers[controller], buffer, 1);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+
+ Delay_MS(1);
+}
+
+void Controller_Set_Idle(uint8_t controller) {
+ uint8_t buffer[2];
+ uint8_t result;
+
+ buffer[0] = CONTROLLER_CMD_RESET;
+ I2C1_Master_Send(ctrl_data_p->connected_controllers[controller], buffer, 1);
+ do {
+ result = I2C1_Get_Status();
+ } while (!result);
+
+ Delay_MS(1);
+}
\ No newline at end of file
/PIC Projects/Cerebot_32MX7_LED_Cube/CONTROLLERS.h
0,0 → 1,78
#ifndef CONTROLLERS_H
#define CONTROLLERS_H
 
#define CONTROLLER_CMD_READ 0xA
#define CONTROLLER_CMD_WRITE 0xB
#define CONTROLLER_CMD_RESET 0xC
#define CONTROLLER_CMD_ACTIVE 0xD
 
#define CONTROLLER_PREFIX_ADDRESS 0x10
#define CONTROLLER_START_ADDRESS 0x01
#define CONTROLLER_END_ADDRESS 0x08
 
#define CONTROLLER_MAX_COUNT 8
 
#define CONTROLLER_BRIGHTNESS_HIGH 0x80
 
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;
} CTRL_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];
} CTRL_LED_VALUES;
 
typedef struct {
void (*change_callback)(uint8_t controller, CTRL_BTN_STATUS values);
 
uint8_t connected_count;
uint8_t next_poll;
uint8_t connected_controllers[CONTROLLER_MAX_COUNT];
CTRL_LED_VALUES led_status[CONTROLLER_MAX_COUNT];
CTRL_BTN_STATUS btn_prev[CONTROLLER_MAX_COUNT];
CTRL_BTN_STATUS btn_curr[CONTROLLER_MAX_COUNT];
} CONTROLLER_DATA;
 
void Controller_Init(CONTROLLER_DATA *data,
void (*change_callback)(uint8_t controller, CTRL_BTN_STATUS values));
void Controller_Poll_Connected(void);
void Controller_Update(void);
void Controller_Set_Left_Leds(uint8_t controller, uint8_t value);
void Controller_Set_Middle_Leds(uint8_t controller, uint8_t value);
void Controller_Set_Right_Leds(uint8_t controller, uint8_t value);
 
uint8_t Controller_Get_Connected(void);
void Controller_Set_Active(uint8_t controller);
void Controller_Set_Idle(uint8_t controller);
 
#endif /* CONTROLLERS_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/SNAKE.c
0,0 → 1,206
#include "defines.h"
#include "CONTROLLERS.h"
#include "SNAKE.h"
#include "TIMER4.h"
 
static SNAKE_DATA *snake_data_p;
static uint32_t rand_value __attribute__((persistent));
 
void Snake_Init(SNAKE_DATA *data) {
snake_data_p = data;
 
// Set starting point
snake_data_p->body[0] = (SNAKE_POINT){0,0,7};
 
snake_data_p->pos_head = 0;
snake_data_p->pos_tail = 0;
snake_data_p->length = 1;
snake_data_p->level = 0;
snake_data_p->delay = SNAKE_MAXIMUM_DELAY;
 
// Initialize the starting direction
snake_data_p->direction = (SNAKE_POINT){1,0,7};
snake_data_p->last_direction = 0x08;
 
srand(rand_value);
 
// Generate a starting location for the candy
snake_data_p->candy_loc = Snake_Generate_Candy();
 
// Draw the snake (head)
Cube_Clear();
uint32_t index = snake_data_p->pos_head;
Cube_Set_Pixel(snake_data_p->body[index].z, snake_data_p->body[index].x, snake_data_p->body[index].y, SNAKE_HEAD_COLOR);
while (index != snake_data_p->pos_tail) {
if (snake_data_p->length > 1) {
index = (index == 0) ? CUBE_PIXELS - 1 : index - 1;
Cube_Set_Pixel(snake_data_p->body[index].z, snake_data_p->body[index].x, snake_data_p->body[index].y, SNAKE_BODY_COLOR);
}
}
}
 
void Snake_Main(void) {
// Main function, loops and delays while updating the frame every x milliseconds
 
// Ensure that a controller is connected before starting
while(!Controller_Get_Connected()) {
Delay_MS(100);
Controller_Poll_Connected();
}
 
// Set the first controller as active and indicate it on its LEDs
Controller_Set_Active(0);
Delay_MS(20);
Controller_Set_Left_Leds(0, 0x1);
TIMER4_Start();
Delay_MS(1000);
while (1) {
// Regenerate the seed upon each update so that the candy starts somewhere new every time
rand_value = rand();
 
Snake_Update_Frame();
Delay_MS(snake_data_p->delay);
}
}
 
void Snake_Update_Direction(uint8_t controller, CTRL_BTN_STATUS value) {
// Determine the next direction for the snake based off the last button press
if (controller == 0) {
snake_data_p->last_direction = value.w;
SNAKE_POINT point = snake_data_p->body[snake_data_p->pos_head];
 
if (value.BTN_L_N || value.BTN_L_E) { // Up
point.z = (point.z == CUBE_LAYER_COUNT - 1) ? 0 : point.z + 1;
} else if (value.BTN_L_W || value.BTN_L_S) { // Down
point.z = (point.z == 0) ? CUBE_LAYER_COUNT - 1 : point.z - 1;
} else if (value.BTN_R_N) { // Forward
point.x = (point.x == CUBE_ROW_COUNT - 1) ? 0 : point.x + 1;
} else if (value.BTN_R_W) { // Right
point.y = (point.y == CUBE_COLUMN_COUNT - 1) ? 0 : point.y + 1;
} else if (value.BTN_R_S) { // Backward
point.x = (point.x == 0) ? CUBE_ROW_COUNT - 1 : point.x - 1;
} else if (value.BTN_R_E) { // Left
point.y = (point.y== 0) ? CUBE_COLUMN_COUNT - 1 : point.y - 1;
}
 
snake_data_p->direction = point;
}
 
// Update the overlay with the candy location
Cube_Overlay_Clear();
Cube_Overlay_Set_Pixel(snake_data_p->candy_loc.z, snake_data_p->candy_loc.x, snake_data_p->candy_loc.y, SNAKE_CANDY_COLOR);
}
 
void Snake_Update_Frame(void) {
uint8_t om_nom_nom = 0;
 
// Check if we are moving onto a candy, if so extend body
if (snake_data_p->direction.x == snake_data_p->candy_loc.x &&
snake_data_p->direction.y == snake_data_p->candy_loc.y &&
snake_data_p->direction.z == snake_data_p->candy_loc.z) {
snake_data_p->pos_head = (snake_data_p->pos_head == CUBE_PIXELS - 1) ? 0 : snake_data_p->pos_head + 1;
snake_data_p->body[snake_data_p->pos_head] = snake_data_p->direction;
snake_data_p->length++;
snake_data_p->candy_loc = Snake_Generate_Candy();
om_nom_nom = 1;
}
 
// Check if the location that we are moving to is overlapping the body
uint32_t pos = snake_data_p->pos_tail;
while (pos != snake_data_p->pos_head) {
if (snake_data_p->direction.x == snake_data_p->body[pos].x &&
snake_data_p->direction.y == snake_data_p->body[pos].y &&
snake_data_p->direction.z == snake_data_p->body[pos].z) {
// Indicate the overlapping pixel, delay, then return to idle state
Cube_Set_Pixel(snake_data_p->direction.z, snake_data_p->direction.x, snake_data_p->direction.y, SNAKE_COLLISION_COLOR);
Delay_MS(3000);
Cube_Overlay_Clear();
Animation_Cube_In_Out(200, ORANGE);
Reset_Board(BOARD_MODE_IDLE);
}
pos = (pos == CUBE_PIXELS - 1) ? 0 : pos + 1;
}
 
// If we didnt eat a candy, increment the frame to move the body along
if (!om_nom_nom) {
snake_data_p->pos_head = (snake_data_p->pos_head == CUBE_PIXELS - 1) ? 0 : snake_data_p->pos_head + 1;
snake_data_p->pos_tail = (snake_data_p->pos_tail == CUBE_PIXELS - 1) ? 0 : snake_data_p->pos_tail + 1;
snake_data_p->body[snake_data_p->pos_head] = snake_data_p->direction;
}
 
// Draw updated snake location
Cube_Clear();
uint32_t index = snake_data_p->pos_head;
Cube_Set_Pixel(snake_data_p->body[index].z, snake_data_p->body[index].x, snake_data_p->body[index].y, SNAKE_HEAD_COLOR);
while (index != snake_data_p->pos_tail) {
if (snake_data_p->length > 1) {
index = (index == 0) ? CUBE_PIXELS - 1 : index - 1;
Cube_Set_Pixel(snake_data_p->body[index].z, snake_data_p->body[index].x, snake_data_p->body[index].y, SNAKE_BODY_COLOR);
}
}
 
// Determine the next point to move to
Snake_Update_Direction(0, (CTRL_BTN_STATUS)snake_data_p->last_direction);
 
// If we ate a candy, delay for a bit to rest
if (om_nom_nom) {
// Increase the level by one
snake_data_p->level += 1;
 
TIMER4_Stop();
Controller_Set_Middle_Leds(0, snake_data_p->level);
if (snake_data_p->level >= 256)
Controller_Set_Left_Leds(0, 0x9);
TIMER4_Start();
 
// Decrease the delay between frame updates by 5ms
if (snake_data_p->delay > SNAKE_MINIMUM_DELAY)
snake_data_p->delay -= 5;
// Clear the watchdog timer to prevent resets in a middle of a game
ClearWDT();
}
}
 
SNAKE_POINT Snake_Generate_Candy(void) {
// Generates a random position within the cube that doesnt overlap anything
SNAKE_POINT ret;
uint32_t x, y, z, brk = 0;
while(1) {
x = rand() % 8;
y = rand() % 8;
z = rand() % 8;
 
if (snake_data_p->length != 1) {
uint32_t pos = snake_data_p->pos_tail;
uint32_t overlap = 0;
// Iterate through the frame till we finish or find an overlap
while (pos != snake_data_p->pos_head) {
if (snake_data_p->body[pos].x == x &&
snake_data_p->body[pos].y == y &&
snake_data_p->body[pos].z == z) {
overlap = 1;
break;
} else {
pos = (pos == CUBE_PIXELS - 1) ? 0 : pos + 1;
}
}
if (!overlap)
brk = 1;
} else {
uint32_t pos = snake_data_p->pos_tail;
if (snake_data_p->body[pos].x != x &&
snake_data_p->body[pos].y != y &&
snake_data_p->body[pos].z != z) {
brk = 1;
}
}
 
if (brk)
break;
}
 
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
}
/PIC Projects/Cerebot_32MX7_LED_Cube/TRON.c
0,0 → 1,249
#include "defines.h"
#include "CONTROLLERS.h"
#include "TRON.h"
#include "TIMER4.h"
 
static TRON_DATA *tron_data_p;
 
void Tron_Init(TRON_DATA *data) {
tron_data_p = data;
 
// Set players 1-4 colors
tron_data_p->Color_Head_R[0] = 0xFF;
tron_data_p->Color_Head_G[0] = 0x00;
tron_data_p->Color_Head_B[0] = 0x00;
tron_data_p->Color_Body_R[0] = 0x20;
tron_data_p->Color_Body_G[0] = 0x00;
tron_data_p->Color_Body_B[0] = 0x00;
 
tron_data_p->Color_Head_R[1] = 0x00;
tron_data_p->Color_Head_G[1] = 0x00;
tron_data_p->Color_Head_B[1] = 0xFF;
tron_data_p->Color_Body_R[1] = 0x00;
tron_data_p->Color_Body_G[1] = 0x00;
tron_data_p->Color_Body_B[1] = 0x20;
 
tron_data_p->Color_Head_R[2] = 0x00;
tron_data_p->Color_Head_G[2] = 0xFF;
tron_data_p->Color_Head_B[2] = 0x00;
tron_data_p->Color_Body_R[2] = 0x00;
tron_data_p->Color_Body_G[2] = 0x20;
tron_data_p->Color_Body_B[2] = 0x00;
 
tron_data_p->Color_Head_R[3] = 0xFF;
tron_data_p->Color_Head_G[3] = 0x60;
tron_data_p->Color_Head_B[3] = 0x00;
tron_data_p->Color_Body_R[3] = 0x20;
tron_data_p->Color_Body_G[3] = 0x10;
tron_data_p->Color_Body_B[3] = 0x00;
 
// // Set starting points for players
tron_data_p->body[0][0] = (TRON_POINT){0,0,7};
tron_data_p->body[1][0] = (TRON_POINT){7,7,7};
tron_data_p->body[2][0] = (TRON_POINT){0,7,7};
tron_data_p->body[3][0] = (TRON_POINT){7,0,7};
 
tron_data_p->delay = TRON_DELAY;
 
Cube_Clear();
Cube_Overlay_Clear();
 
// Determine the number of players (connected controllers)
tron_data_p->players = Controller_Get_Connected();
while (tron_data_p->players < 2) {
Delay_MS(100);
Controller_Poll_Connected();
tron_data_p->players = Controller_Get_Connected();
}
if (tron_data_p->players > TRON_MAX_PLAYERS)
tron_data_p->players = TRON_MAX_PLAYERS;
tron_data_p->players_alive = tron_data_p->players;
 
// Draw each player's light trail
uint8_t i;
for (i = 0; i < tron_data_p->players; i++) {
tron_data_p->length[i] = 1;
tron_data_p->dead[i] = 0;
// Draw the head
Cube_Set_Pixel(tron_data_p->body[i][tron_data_p->length[i] - 1].z,
tron_data_p->body[i][tron_data_p->length[i] - 1].x,
tron_data_p->body[i][tron_data_p->length[i] - 1].y,
tron_data_p->Color_Head_R[i], tron_data_p->Color_Head_G[i],
tron_data_p->Color_Head_B[i]);
}
 
// Set starting direction for players
Tron_Update_Direction(0, (CTRL_BTN_STATUS) (uint8_t) 0x08);
Tron_Update_Direction(1, (CTRL_BTN_STATUS) (uint8_t) 0x10);
Tron_Update_Direction(2, (CTRL_BTN_STATUS) (uint8_t) 0x04);
Tron_Update_Direction(3, (CTRL_BTN_STATUS) (uint8_t) 0x20);
}
 
void Tron_Main(void) {
// Main function, loops and delays while updating the frame every x milliseconds
uint8_t i;
for (i = 0; i < tron_data_p->players; i++) {
Controller_Set_Active(i);
}
Delay_MS(20);
// Light up the player indicators
switch (tron_data_p->players) {
case 4:
Controller_Set_Left_Leds(3, 0x02);
case 3:
Controller_Set_Left_Leds(2, 0x04);
case 2:
default:
Controller_Set_Left_Leds(1, 0x08);
Controller_Set_Left_Leds(0, 0x01);
break;
}
TIMER4_Start();
Delay_MS(3000);
while (1) {
Tron_Update_Frame();
Delay_MS(tron_data_p->delay);
}
}
 
void Tron_Update_Direction(uint8_t controller, CTRL_BTN_STATUS value) {
// Determine the next direction for the trails based off the last button press
if (controller < tron_data_p->players) {
// Save the current button value
tron_data_p->last_direction[controller] = value.w;
 
// Grab the location of the head
TRON_POINT next_pos = tron_data_p->body[controller][tron_data_p->length[controller] - 1];
 
// Determine which next point to move to
if (value.BTN_L_N || value.BTN_L_E) { // Up
next_pos.z = (next_pos.z == CUBE_LAYER_COUNT - 1) ? 0 : next_pos.z + 1;
} else if (value.BTN_L_S || value.BTN_L_W) { // Down
next_pos.z = (next_pos.z == 0) ? CUBE_LAYER_COUNT - 1 : next_pos.z - 1;
} else if (value.BTN_R_N) { // Forward
next_pos.x = (next_pos.x == CUBE_ROW_COUNT - 1) ? 0 : next_pos.x + 1;
} else if (value.BTN_R_W) { // Left
next_pos.y = (next_pos.y == CUBE_COLUMN_COUNT - 1) ? 0 : next_pos.y + 1;
} else if (value.BTN_R_S) { // Backwards
next_pos.x = (next_pos.x == 0) ? CUBE_ROW_COUNT - 1 : next_pos.x - 1;
// } else if (value.BTN_R_E) { // Right
} else { // Right
next_pos.y = (next_pos.y== 0) ? CUBE_COLUMN_COUNT - 1 : next_pos.y - 1;
}
// Save the next point to move to
tron_data_p->direction[controller] = next_pos;
}
}
 
void Tron_Update_Frame(void) {
uint8_t player, player2;
 
// Change the current head color to the body color
for (player = 0; player < tron_data_p->players; player++) {
if (tron_data_p->dead[player] == 0) {
Cube_Set_Pixel(tron_data_p->body[player][tron_data_p->length[player] - 1].z,
tron_data_p->body[player][tron_data_p->length[player] - 1].x,
tron_data_p->body[player][tron_data_p->length[player] - 1].y,
tron_data_p->Color_Body_R[player],
tron_data_p->Color_Body_G[player],
tron_data_p->Color_Body_B[player]);
}
}
 
// Check if there is a head-on collision between any of the players
for (player = 0; player < tron_data_p->players; player++) {
if (tron_data_p->dead[player] == 0) {
for (player2 = 0; player2 < tron_data_p->players; player2++) {
if (player2 == player) continue;
if (tron_data_p->dead[player2] == 0) {
if (tron_data_p->direction[player].x == tron_data_p->direction[player2].x &&
tron_data_p->direction[player].y == tron_data_p->direction[player2].y &&
tron_data_p->direction[player].z == tron_data_p->direction[player2].z) {
// Indicate the collision point
Cube_Set_Pixel(tron_data_p->direction[player].z, tron_data_p->direction[player].x,
tron_data_p->direction[player].y, TRON_COLLISION);
// Mark the players as dead
tron_data_p->dead[player] = 1;
tron_data_p->dead[player2] = 1;
tron_data_p->players_alive -= 2;
}
}
}
}
}
 
// Check if the location that we are moving to is overlapping either trails
uint8_t index;
for (player = 0; player < tron_data_p->players; player++) {
// Check if the player in question is dead
if (tron_data_p->dead[player] == 0) {
// See if the player's next point hits anyone elses trail
for (player2 = 0; player2 < tron_data_p->players; player2++) {
for (index = 0; index < tron_data_p->length[player2]; index++) {
if (tron_data_p->direction[player].x == tron_data_p->body[player2][index].x &&
tron_data_p->direction[player].y == tron_data_p->body[player2][index].y &&
tron_data_p->direction[player].z == tron_data_p->body[player2][index].z) {
// Indicate the collision point
Cube_Set_Pixel(tron_data_p->direction[player].z, tron_data_p->direction[player].x,
tron_data_p->direction[player].y, TRON_COLLISION);
// Mark the player as dead
tron_data_p->dead[player] = 1;
tron_data_p->players_alive -= 1;
}
}
}
}
}
 
// Save the new head location of each trail
for (player = 0; player < tron_data_p->players; player++) {
// If player is still alive, extend its body in the next direction
if (tron_data_p->dead[player] == 0) {
tron_data_p->length[player]++;
tron_data_p->body[player][tron_data_p->length[player] - 1] = tron_data_p->direction[player];
}
}
 
// Update the head to its corresponding color
for (player = 0; player < tron_data_p->players; player++) {
// If player is still alive, recolor its body to indicate its new head
if (tron_data_p->dead[player] == 0) {
// Set the color of the new head
Cube_Set_Pixel(tron_data_p->body[player][tron_data_p->length[player] - 1].z,
tron_data_p->body[player][tron_data_p->length[player] - 1].x,
tron_data_p->body[player][tron_data_p->length[player] - 1].y,
tron_data_p->Color_Head_R[player],
tron_data_p->Color_Head_G[player],
tron_data_p->Color_Head_B[player]);
}
}
 
// End the game if there is one player left alive
if (tron_data_p->players_alive == 1) {
Delay_MS(5000);
// Determine which player is still alive and flash his color
for (player = 0; player < tron_data_p->players; player++) {
if (tron_data_p->dead[player] == 0) {
Animation_Cube_In_Out(200, tron_data_p->Color_Head_R[player],
tron_data_p->Color_Head_G[player], tron_data_p->Color_Head_B[player]);
}
}
Reset_Board(BOARD_MODE_IDLE);
} else if (tron_data_p->players_alive == 0) {
// If no players are alive flash neutral color
Delay_MS(5000);
Animation_Cube_In_Out(200, TRON_COLLISION_2);
Reset_Board(BOARD_MODE_IDLE);
}
 
// Determine the next direction to move to for each player
for (player = 0; player < tron_data_p->players; player++) {
if (tron_data_p->dead[player] == 0) {
Tron_Update_Direction(player, (CTRL_BTN_STATUS)tron_data_p->last_direction[player]);
}
}
 
// Decrease the delay between frame updates by 5ms
tron_data_p->delay -= 5;
}
/PIC Projects/Cerebot_32MX7_LED_Cube/TRON.h
0,0 → 1,43
#ifndef TRON_H
#define TRON_H
 
#include "CUBE.h"
 
#define TRON_MAX_PLAYERS 4
#define TRON_COLLISION WHITE
#define TRON_COLLISION_2 ORANGE
#define TRON_DELAY 800
 
typedef struct {
uint8_t x;
uint8_t y;
uint8_t z;
} TRON_POINT;
 
typedef struct {
uint8_t Color_Head_R[TRON_MAX_PLAYERS];
uint8_t Color_Head_G[TRON_MAX_PLAYERS];
uint8_t Color_Head_B[TRON_MAX_PLAYERS];
 
uint8_t Color_Body_R[TRON_MAX_PLAYERS];
uint8_t Color_Body_G[TRON_MAX_PLAYERS];
uint8_t Color_Body_B[TRON_MAX_PLAYERS];
 
TRON_POINT body[TRON_MAX_PLAYERS][CUBE_PIXELS];
TRON_POINT direction[TRON_MAX_PLAYERS];
uint8_t last_direction[TRON_MAX_PLAYERS];
uint8_t dead[TRON_MAX_PLAYERS];
uint32_t length[TRON_MAX_PLAYERS];
 
uint8_t players;
uint8_t players_alive;
uint32_t delay;
} TRON_DATA;
 
void Tron_Init(TRON_DATA *data);
void Tron_Main(void);
void Tron_Update_Direction(uint8_t controller, CTRL_BTN_STATUS value);
void Tron_Update_Frame(void);
 
#endif /* TRON_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/main.c
0,0 → 1,443
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* ------------------------------------------------------------ */
/* PIC32 Configuration Settings */
/* ------------------------------------------------------------ */
/* Oscillator Settings */
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits
#pragma config POSCMOD = EC // Primary Oscillator Configuration
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable
/* Clock Control Settings */
#pragma config IESO = OFF // Internal/External Clock Switch Over
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin
/* USB Settings */
#pragma config UPLLEN = ON // USB PLL Enable
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection
#pragma config FUSBIDIO = OFF // USB USID Selection
/* Other Peripheral Device Settings */
#pragma config FWDTEN = OFF // Watchdog Timer Enable
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1048.576s)
#pragma config FSRSSEL = PRIORITY_7 // SRS Interrupt Priority
#pragma config FCANIO = OFF // CAN I/O Pin Select (default/alternate)
#pragma config FETHIO = ON // Ethernet I/O Pin Select (default/alternate)
#pragma config FMIIEN = OFF // Ethernet MII/RMII select (OFF=RMII)
/* Code Protection Settings */
#pragma config CP = OFF // Code Protect
#pragma config BWP = OFF // Boot Flash Write Protect
#pragma config PWP = OFF // Program Flash Write Protect
/* Debug Settings */
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (on-board debugger)
/* ------------------------------------------------------------ */
// </editor-fold>
 
#include "defines.h"
#include "UART1.h"
#include "SPI1.h"
#include "SPI4.h"
#include "I2C1.h"
#include "ETHERNET.h"
#include "TIMER4.h"
#include "TIMER5.h"
#include "CUBE.h"
#include "BTN.h"
#include "ANIMATIONS.h"
#include "CONTROLLERS.h"
#include "SNAKE.h"
#include "TRON.h"
 
void BTN1_Interrupt(void);
void BTN2_Interrupt(void);
void BTN3_Interrupt(void);
 
void Delay_MS(uint32_t delay_ms) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow! (max delay_ms = 107374) ??
uint32_t delay = delay_ms * MS_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
void Delay_US(uint32_t delay_us) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow!
uint32_t delay = delay_us * US_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
uint8_t Get_Reset_Condition(void) {
uint8_t ret = 0;
if (RCONbits.POR && RCONbits.BOR)
ret = RESET_POR;
else if (RCONbits.BOR)
ret = RESET_BOR;
else if (RCONbits.EXTR)
ret = RESET_PIN;
else if (RCONbits.SWR)
ret = RESET_SWR;
else if (RCONbits.CMR)
ret = RESET_CFG;
else if (RCONbits.WDTO)
ret = RESET_WDT;
// Clear the RCON register
RCON = 0x0;
return ret;
}
 
// Initialize a persistent operational state machine
volatile static uint8_t op_state __attribute__((persistent));
 
uint8_t Get_Board_State(void) {
return op_state;
}
 
void Reset_Board(uint8_t next_state) {
op_state = next_state;
// Executes a software reset
INTDisableInterrupts();
SYSKEY = 0x00000000; // Write invalid key to force lock
SYSKEY = 0xAA996655; // Write key1 to SYSKEY
SYSKEY = 0x556699AA; // Write key2 to SYSKEY
/* OSCCON is now unlocked */
// Set SWRST bit to arm reset
RSWRSTSET = 1;
// Read RSWRST register to trigger reset
uint32_t dummy;
dummy = RSWRST;
// Prevent any unwanted code execution until reset occurs
while(1);
}
 
void Test_Callback(uint8_t controller, CTRL_BTN_STATUS value) {
LED1_LAT = 0;
LED2_LAT = 0;
LED3_LAT = 0;
LED4_LAT = 0;
if (value.BTN_R_N)
LED1_LAT = 1;
if (value.BTN_R_E)
LED2_LAT = 1;
if (value.BTN_R_S)
LED3_LAT = 1;
if (value.BTN_R_W)
LED4_LAT = 1;
}
 
void main() {
// WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
 
/* -------------------- BEGIN INITIALIZATION --------------------- */
// Configure the target for maximum performance at 80 MHz.
// Note: This overrides the peripheral clock to 80Mhz regardless of config
SYSTEMConfigPerformance(CPU_CLOCK_HZ);
 
// Configure the interrupts for multiple vectors
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
 
// Set all analog I/O pins to digital
AD1PCFGSET = 0xFFFF;
 
// Enable the watchdog timer with windowed mode disabled
// WDT prescaler set to 1048576 (1048.576s) (see config bits)
// WDTCON = 0x00008000;
WDTCON = 0x00000000;
 
// Configure onboard LEDs
LED1_TRIS = 0;
LED2_TRIS = 0;
LED3_TRIS = 0;
LED4_TRIS = 0;
LED1_LAT = 0;
LED2_LAT = 0;
LED3_LAT = 0;
LED4_LAT = 0;
 
// Determine what to do at this point. We either choose to idle (on POR)
// or go into a mode specified prior to the software reset event
uint8_t last_reset = Get_Reset_Condition();
if (last_reset == RESET_POR || last_reset == RESET_BOR ||
last_reset == RESET_PIN || last_reset == RESET_WDT ||
last_reset == RESET_CFG) {
op_state = BOARD_MODE_IDLE;
}
 
// Initialize the SPI1 module
SPI1_DATA spi_1_data;
SPI1_Init(&spi_1_data, NULL);
 
// Initialize the SPI4 module
// SPI4_DATA spi_4_data;
// SPI4_Init(&spi_4_data);
 
// Initialize the I2C1 module
I2C1_DATA i2c_1_data;
I2C1_Init(&i2c_1_data, I2C1_400KHZ, 0x20);
 
// // Initialize the UART1 module
// UART1_DATA uart_data;
// UART1_Init(&uart_data, &Cube_Data_In);
 
// Initializs the PWM2 output to 20MHz
PWM2_Init();
 
// Initialize the cube variables
CUBE_DATA cube_data;
Cube_Init(&cube_data, 0x40);
 
// Start the cube update layer interrupt
// 2084 = 60Hz, 500 = 250Hz, 250 = 500Hz
TIMER5_DATA timer_5_data;
TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
 
// Initialize timer for controller polling and overlay rotation interrupt
TIMER4_DATA timer_4_data;
TIMER4_Init(&timer_4_data, NULL, NULL, 0);
 
// Process button inputs
BTN_DATA btn_data;
BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
 
// Initialize controllers
CONTROLLER_DATA ctrl_data;
Controller_Init(&ctrl_data, NULL);
 
// Initialize the Ethernet module
if (op_state == BOARD_MODE_ETHERNET) {
LED1_LAT = 1;
ETH_DATA eth_data;
ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
}
SNAKE_DATA snake_data;
TRON_DATA tron_data;
 
PWM2_Start();
/* -------------------- END OF INITIALIZATION -------------------- */
/* ------------------------ BEGIN DISPLAY ------------------------ */
 
// Figure out what to do at this point (depending on current state)
switch (op_state) {
case BOARD_MODE_IDLE:
TIMER5_Start(); // Use the default refresh rate (250Hz)
Idle_Animation_Sequence();
break;
case BOARD_MODE_SNAKE:
// Change refresh rate to ~60Hz
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2000);
TIMER5_Start();
// Poll the controllers at 1kHz
Controller_Init(NULL, &Snake_Update_Direction);
TIMER4_Init(NULL, &Controller_Update, NULL, 0);
// Initialize and start the game
Snake_Init(&snake_data);
Snake_Main();
break;
case BOARD_MODE_TRON:
// Change refresh rate to ~60Hz
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2000);
TIMER5_Start();
// Poll the controllers at 1kHz
Controller_Init(NULL, &Tron_Update_Direction);
TIMER4_Init(NULL, &Controller_Update, NULL, 0);
// Initialize and start the game
Tron_Init(&tron_data);
Tron_Main();
break;
case BOARD_MODE_ETHERNET:
TIMER4_Stop();
TIMER5_Start();
LED2_LAT = 1;
while(1);
break;
}
 
}
 
void Idle_Animation_Sequence(void) {
 
// Cube_Set_All(RED);
// Delay_MS(2000);
// Cube_Set_All(GREEN);
// Delay_MS(2000);
// Cube_Set_All(BLUE);
// Delay_MS(2000);
// Animation_Pseudo_Random_Colors(200);
// Animation_Pseudo_Random_Colors(200);
// Animation_Pseudo_Random_Colors(200);
// Animation_Pseudo_Random_Colors(200);
// Animation_Pseudo_Random_Colors(200);
// Animation_Pseudo_Random_Colors(200);
uint8_t connected, i;
connected = Controller_Get_Connected();
for (i = 0; i < connected; i++) {
Controller_Set_Idle(i);
}
 
// Start the scrolling text
TIMER4_Stop();
TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, 100);
// TIMER4_Start();
 
// int8_t start_text[] = "Cube Initialized\r\n";
// UART1_Write(start_text, 18);
 
// Set the overlay text
uint8_t text_string[] = "Welcome to the CCM Lab ";
Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
// TIMER4_Start();
 
// Loop through some preset animations
while(1) {
 
Animation_Sawtooth(100);
Animation_Sawtooth(100);
Animation_Sawtooth(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave2(100);
Animation_Wave2(100);
Animation_Wave2(100);
Animation_Wave2(100);
// Animation_Solid_Colors(300);
// Animation_Layer_Alternate(300);
// Animation_Pixel_Alternate(200);
// Animation_Full_Color_Sweep(1000);
// Animation_Row_Column_Sweep(40);
Animation_Row_Column_Sweep(40);
Animation_Cube_In_Cube(300);
Animation_Cube_In_Cube(300);
Animation_Cube_In_Cube(300);
Animation_Double_Rotation(30);
Animation_Double_Rotation(30);
Animation_Double_Rotation(30);
Animation_Double_Rotation(30);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
// Animation_Random_Colors(300);
 
// ClearWDT(); // Clear the WDT if we dont want the board to reset
}
}
 
// Function call on button 1 press to change cube operation
void BTN1_Interrupt(void) {
switch (op_state) {
case BOARD_MODE_IDLE:
Reset_Board(BOARD_MODE_SNAKE);
break;
case BOARD_MODE_SNAKE:
Reset_Board(BOARD_MODE_TRON);
break;
case BOARD_MODE_TRON:
Reset_Board(BOARD_MODE_ETHERNET);
break;
case BOARD_MODE_ETHERNET:
Reset_Board(BOARD_MODE_IDLE);
break;
}
 
// Code to change refresh rate on button press
// static uint8_t state;
// state = (state == 4) ? 0 : state + 1;
// TIMER5_Stop();
// switch (state) {
// case 0:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
// break;
// case 1:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
// break;
// case 2:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
// break;
// case 3:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
// break;
// case 4:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
// break;
// }
// TIMER5_Start();
}
 
// Function call on button 2 press to change brightness
void BTN2_Interrupt(void) {
static uint8_t state = 6;
state = (state == 6) ? 0 : state + 1;
TIMER5_Stop();
Delay_MS(1); // Need to wait for all SPI writes to complete
uint8_t BC;
switch (state) {
case 0:
BC = 0x01;
break;
case 1:
BC = 0x08;
break;
case 2:
BC = 0x10;
break;
case 3:
BC = 0x20;
break;
case 4:
BC = 0x40;
break;
case 5:
BC = 0x80;
break;
case 6:
BC = 0xFF;
break;
}
Cube_Write_DCS(BC);
TIMER5_Start();
}
 
//// Function call on button 3 press to change text scroll speed
//void BTN3_Interrupt(void) {
// static uint8_t state;
// state = (state == 4) ? 0 : state + 1;
// TIMER4_Stop();
// switch (state) {
// case 0:
// TIMER4_Init(NULL, &Cube_Text_Interrupt, 209712);
// break;
// case 1:
// TIMER4_Init(NULL, &Cube_Text_Interrupt, 180000);
// break;
// case 2:
// TIMER4_Init(NULL, &Cube_Text_Interrupt, 150000);
// break;
// case 3:
// TIMER4_Init(NULL, &Cube_Text_Interrupt, 120000);
// break;
// case 4:
// TIMER4_Init(NULL, &Cube_Text_Interrupt, 90000);
// break;
// }
// TIMER4_Start();
//}
/PIC Projects/Cerebot_32MX7_LED_Cube/ANIMATIONS.c
0,0 → 1,553
#include "defines.h"
#include "ANIMATIONS.h"
#include "CUBE.h"
 
void Animation_Solid_Colors(uint16_t delay_ms) {
Cube_Set_All(RED);
Delay_MS(delay_ms);
Cube_Set_All(GREEN);
Delay_MS(delay_ms);
Cube_Set_All(BLUE);
Delay_MS(delay_ms);
}
 
void Animation_Layer_Alternate(uint16_t delay_ms) {
uint8_t i;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,RED);
else if (i % 3 == 1)
Cube_Set_Layer(i,GREEN);
else
Cube_Set_Layer(i,BLUE);
}
Delay_MS(delay_ms);
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,GREEN);
else if (i % 3 == 1)
Cube_Set_Layer(i,BLUE);
else
Cube_Set_Layer(i,RED);
}
Delay_MS(delay_ms);
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if (i % 3 == 0)
Cube_Set_Layer(i,BLUE);
else if (i % 3 == 1)
Cube_Set_Layer(i,RED);
else
Cube_Set_Layer(i,GREEN);
}
Delay_MS(delay_ms);
}
 
void Animation_Pixel_Alternate(uint16_t delay_ms) {
uint8_t i,j,k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int32_t var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,RED);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,GREEN);
else
Cube_Set_Pixel(i,j,k,BLUE);
}
}
Delay_MS(delay_ms);
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int32_t var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,GREEN);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,BLUE);
else
Cube_Set_Pixel(i,j,k,RED);
}
}
Delay_MS(delay_ms);
Cube_Clear();
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
int32_t var = (j * 8) + k;
if (var % 3 == 0)
Cube_Set_Pixel(i,j,k,BLUE);
else if (var % 3 == 1)
Cube_Set_Pixel(i,j,k,RED);
else
Cube_Set_Pixel(i,j,k,GREEN);
}
}
Delay_MS(delay_ms);
}
}
 
void Animation_Full_Color_Sweep(uint16_t delay_us) {
int16_t i;
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(i,0,0);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(0x0FF,i,0);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(i,0x0FF,0);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(0,0x0FF,i);
Delay_US(delay_us);
}
for (i = 0; i < 0x0FF; i+=2) {
Cube_Set_All(i,0x0FF,0x0FF);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(0x0FF,i,0x0FF);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(i,0,0x0FF);
Delay_US(delay_us);
}
for (i = 0x0FF; i >= 0; i-=2) {
Cube_Set_All(0,0,i);
Delay_US(delay_us);
}
}
 
void Animation_Row_Column_Sweep(uint16_t delay_ms) {
uint8_t i,j,k,a;
for (i = 0; i < 3; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
Cube_Clear();
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
if (i % 3 == 0)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,RED);
else if (i % 3 == 1)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,GREEN);
else
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,j,k,BLUE);
Delay_MS(delay_ms);
}
for (j = 0; j < CUBE_ROW_COUNT; j++) {
Cube_Clear();
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
if (i % 3 == 0)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,RED);
else if (i % 3 == 1)
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,GREEN);
else
for (a = 0; a < CUBE_LAYER_COUNT; a++)
Cube_Set_Pixel(a,k,j,BLUE);
Delay_MS(delay_ms);
}
for (j = CUBE_LAYER_COUNT; j != 0; j--) {
Cube_Clear();
if (i % 3 == 0) {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,RED);
} else if (i % 3 == 1) {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,GREEN);
} else {
for (k = 0; k < CUBE_LAYER_COUNT; k++)
if (k == j)
Cube_Set_Layer(k,BLUE);
}
Delay_MS(delay_ms);
}
}
}
 
void Animation_Pixel_Sweep(uint16_t delay_ms) {
uint8_t i,j,k,a;
for (a = 0; a < 3; a++) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Clear();
if (a % 3 == 0) {
Cube_Set_Pixel(i,j,k,RED);
} else if (a % 3 == 1) {
Cube_Set_Pixel(i,j,k,GREEN);
} else {
Cube_Set_Pixel(i,j,k,BLUE);
}
Delay_MS(delay_ms);
}
}
}
}
}
 
void Animation_Pseudo_Random_Colors(uint16_t delay_ms) {
uint8_t i,j,k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
uint32_t a = rand();
if (a % 5 == 0)
Cube_Set_Pixel(i,j,k,RED);
else if (a % 5 == 1)
Cube_Set_Pixel(i,j,k,GREEN);
else if (a % 5 == 2)
Cube_Set_Pixel(i,j,k,BLUE);
else if (a % 5 == 3)
Cube_Set_Pixel(i,j,k,PURPLE);
else if (a % 5 == 4)
Cube_Set_Pixel(i,j,k,YELLOW);
else
Cube_Set_Pixel(i,j,k,ORANGE);
}
}
}
Delay_MS(delay_ms);
}
 
void Animation_Random_Colors(uint16_t delay_ms) {
uint8_t i,j,k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Set_Pixel(i,j,k,rand()&0x0FF,rand()&0x0FF,rand()&0x0FF);
}
}
}
Delay_MS(delay_ms);
}
 
void Animation_Cube_In_Cube(uint16_t delay_ms) {
uint8_t x;
for (x = 0; x < 6; x++) {
Cube_Clear();
if (x == 0)
Cube_Set_Shell(0, RED);
else if (x == 1 || x == 5)
Cube_Set_Shell(1, YELLOW);
else if (x == 2 || x == 4)
Cube_Set_Shell(2, GREEN);
else if (x == 3)
Cube_Set_Shell(3, BLUE);
Delay_MS(delay_ms);
}
}
 
void Animation_Cube_In_Out(uint16_t delay_ms, uint16_t r, uint16_t g, uint16_t b) {
uint8_t x,i,j,k;
for (x = 0; x < 7; x++) {
Cube_Clear();
switch (x % 7) {
case 0:
Cube_Set_Shell(3, r, g, b);
break;
case 1:
Cube_Set_Shell(2, r, g, b);
break;
case 2:
Cube_Set_Shell(1, r, g, b);
break;
case 3:
Cube_Set_Shell(0, r, g, b);
break;
case 4:
Cube_Set_Shell(1, r, g, b);
break;
case 5:
Cube_Set_Shell(2, r, g, b);
break;
case 6:
Cube_Set_Shell(3, r, g, b);
break;
}
 
// for (i = 0; i < CUBE_LAYER_COUNT; i++) {
// if ((x == 0 || x == 6)&&(i == 0 || i == 7)) {
// Cube_Set_Layer(i,r,g,b);
// } else if ((x == 1 || x == 5)&&(i == 1 || i == 6)) {
// for (j = 1; j < CUBE_ROW_COUNT-1; j++)
// for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
// Cube_Set_Pixel(i,j,k,r,g,b);
// } else if ((x == 2 || x == 4)&&(i == 2 || i == 5)) {
// for (j = 2; j < CUBE_ROW_COUNT-2; j++)
// for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
// Cube_Set_Pixel(i,j,k,r,g,b);
// } else if ((x == 3)&&(i == 3 || i == 4)) {
// for (j = 3; j < CUBE_ROW_COUNT-3; j++)
// for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
// Cube_Set_Pixel(i,j,k,r,g,b);
// }
//
// if ((x == 0 || x == 6)&&(i > 0 && i < 8)) {
// for (j = 0; j < 8; j++) {
// Cube_Set_Pixel(i,j,0,r,g,b);
// Cube_Set_Pixel(i,j,7,r,g,b);
// Cube_Set_Pixel(i,0,j,r,g,b);
// Cube_Set_Pixel(i,7,j,r,g,b);
// }
// }
// if ((x == 1 || x == 5)&&(i > 1 && i < 7)) {
// for (j = 1; j < 7; j++) {
// Cube_Set_Pixel(i,j,1,r,g,b);
// Cube_Set_Pixel(i,j,6,r,g,b);
// Cube_Set_Pixel(i,1,j,r,g,b);
// Cube_Set_Pixel(i,6,j,r,g,b);
// }
// }
// if ((x == 2 || x == 4)&&(i > 2 && i < 6)) {
// for (j = 2; j < 6; j++) {
// Cube_Set_Pixel(i,j,2,r,g,b);
// Cube_Set_Pixel(i,j,5,r,g,b);
// Cube_Set_Pixel(i,2,j,r,g,b);
// Cube_Set_Pixel(i,5,j,r,g,b);
// }
// }
// }
Delay_MS(delay_ms);
}
}
 
void Animation_Double_Rotation(uint16_t delay_ms) {
Cube_Clear();
uint8_t x,y,z;
 
for (y = 0; y < CUBE_LAYER_COUNT; y++) {
Cube_Set_Pixel(y,0,0,RED);
Cube_Set_Pixel(y,1,1,ORANGE);
Cube_Set_Pixel(y,2,2,YELLOW);
Cube_Set_Pixel(y,3,3,GREEN);
Cube_Set_Pixel(y,4,4,TEAL);
Cube_Set_Pixel(y,5,5,BLUE);
Cube_Set_Pixel(y,6,6,PURPLE);
Cube_Set_Pixel(y,7,7,WHITE);
}
for (x = 0; x < 28; x++) {
Delay_MS(delay_ms);
Cube_Rotate(0);
}
}
 
// for (z = 0; z < 3; z++) {
// switch (z % 3) {
// case 0:
// for (y = 0; y < CUBE_LAYER_COUNT; y++) {
// Cube_Set_Pixel(y,0,0,RED);
// Cube_Set_Pixel(y,1,1,RED);
// Cube_Set_Pixel(y,2,2,RED);
// Cube_Set_Pixel(y,3,3,RED);
// Cube_Set_Pixel(y,4,4,RED);
// Cube_Set_Pixel(y,5,5,RED);
// Cube_Set_Pixel(y,6,6,RED);
// Cube_Set_Pixel(y,7,7,RED);
// }
// break;
// case 1:
// for (y = 0; y < CUBE_LAYER_COUNT; y++) {
// Cube_Set_Pixel(y,0,0,GREEN);
// Cube_Set_Pixel(y,1,1,GREEN);
// Cube_Set_Pixel(y,2,2,GREEN);
// Cube_Set_Pixel(y,3,3,GREEN);
// Cube_Set_Pixel(y,4,4,GREEN);
// Cube_Set_Pixel(y,5,5,GREEN);
// Cube_Set_Pixel(y,6,6,GREEN);
// Cube_Set_Pixel(y,7,7,GREEN);
// }
// break;
// case 2:
// for (y = 0; y < CUBE_LAYER_COUNT; y++) {
// Cube_Set_Pixel(y,0,0,BLUE);
// Cube_Set_Pixel(y,1,1,BLUE);
// Cube_Set_Pixel(y,2,2,BLUE);
// Cube_Set_Pixel(y,3,3,BLUE);
// Cube_Set_Pixel(y,4,4,BLUE);
// Cube_Set_Pixel(y,5,5,BLUE);
// Cube_Set_Pixel(y,6,6,BLUE);
// Cube_Set_Pixel(y,7,7,BLUE);
// }
// break;
// }
//
// for (x = 0; x < 28; x++) {
// Delay_MS(delay_ms);
// Cube_Rotate(0);
// }
// }
//}
 
void Animation_Wave1(uint16_t delay_ms) {
uint8_t i, j;
static uint8_t data[8];
uint32_t r;
for (i = 0; i < 16; i++) {
for (j = 0; j < 8; j++) {
r = rand();
if (r % 3 == 0) {
// Increase
data[j] = (data[j] == CUBE_LAYER_COUNT) ? data[j] : data[j] + 1;
} else if (r % 3 == 1) {
// Decrease
data[j] = (data[j] == 0) ? data[j] : data[j] - 1;
} else {
// No change
data[j] = data[j];
}
}
Cube_Shift_Waterfall(data);
Delay_MS(delay_ms);
}
}
 
void Animation_Wave2(uint16_t delay_ms) {
uint8_t i, j;
static uint8_t data[8];
uint32_t r;
 
for (i = 0; i < 16; i++) {
for (j = 0; j < 8; j++) {
r = rand();
if (r % 3 == 0) {
// Increase
data[j] = (data[j] == CUBE_LAYER_COUNT) ? data[j] : data[j] + 1;
} else if (r % 3 == 1) {
// Decrease
data[j] = (data[j] == 0) ? data[j] : data[j] - 1;
} else {
// No change
data[j] = data[j];
}
}
Cube_Shift_Waterfall2(data);
Delay_MS(delay_ms);
}
}
 
void Animation_Sphere(uint16_t delay_ms) {
Cube_Clear();
Cube_Set_Sphere(0, RED);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(1, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(2, YELLOW);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(3, GREEN);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(4, BLUE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(5, PURPLE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(6, RED);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(7, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(8, YELLOW);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(7, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(6, RED);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(5, PURPLE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(4, BLUE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(3, GREEN);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(2, YELLOW);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(1, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
}
 
void Animation_Sawtooth(uint16_t delay_ms) {
uint8_t i;
uint8_t dir = 1;
uint8_t layer_dir = 1;
uint8_t layer_min = 0;
uint8_t layer_max = CUBE_LAYER_COUNT;
uint8_t layer = layer_min;
 
for (i = 0; i < 48; i++) {
Cube_Set_Row(7, 0x00, 0x00, 0x00);
Cube_Set_Pixel(layer, 7, 0, RED);
Cube_Set_Pixel(layer, 7, 1, ORANGE);
Cube_Set_Pixel(layer, 7, 2, YELLOW);
Cube_Set_Pixel(layer, 7, 3, GREEN);
Cube_Set_Pixel(layer, 7, 4, TEAL);
Cube_Set_Pixel(layer, 7, 5, BLUE);
Cube_Set_Pixel(layer, 7, 6, PURPLE);
Cube_Set_Pixel(layer, 7, 7, WHITE);
if (dir)
layer++;
else
layer--;
 
// Decrease the maximum layer
if (layer == layer_min) {
dir = 1;
if (layer_dir)
layer_max--;
else
layer_max++;
}
 
// Increase the minimum layer
if (layer == layer_max - 1) {
dir = 0;
if (layer_dir)
layer_min++;
else
layer_min--;
}
 
// Change the layer gap to expansion
if (layer_max - layer_min < 3) {
if (layer_dir)
layer_dir = 0;
else
layer_dir = 1;
}
 
// Change the layer gap to reduction
if (layer == 0) {
if (layer_dir)
layer_dir = 0;
else
layer_dir = 1;
}
Delay_MS(delay_ms);
Cube_Shift_Row(0);
}
}
/PIC Projects/Cerebot_32MX7_LED_Cube/CUBE.h
0,0 → 1,164
#ifndef CUBE_H
#define CUBE_H
 
// Cube Parameters
#define CUBE_ROW_COUNT 8
#define CUBE_COLUMN_COUNT 8
#define CUBE_LAYER_COUNT 8
#define CUBE_PIXELS 512
#define CUBE_ROTATIONS 7
 
#define GCS_REG_SIZE 36
#define GCS_LAYER_SIZE (GCS_REG_SIZE*CUBE_ROW_COUNT)
 
// Color Definitions
#define CLEAR 0x000,0x000,0x000
#define RED 0x0FF,0x000,0x000
#define ORANGE 0x0FF,0x020,0x000
#define YELLOW 0x0FF,0x060,0x000
#define GREEN 0x000,0x0FF,0x000
#define TEAL 0x000,0x0FF,0x040
#define BLUE 0x000,0x000,0x0FF
#define PURPLE 0x0FF,0x000,0x0FF
#define WHITE 0x0FF,0x0FF,0x0FF
 
// Control Pin Declarations
#define DCSIN_TRIS TRISDbits.TRISD3
#define DCSCK_TRIS TRISDbits.TRISD12
 
#define DCSIN LATDbits.LATD3
#define DCSCK LATDbits.LATD12
 
#define SFT_R_TRIS TRISBbits.TRISB15
#define SFT_K_TRIS TRISDbits.TRISD5
#define SFT_S_TRIS TRISDbits.TRISD4
#define SFT_D_TRIS TRISBbits.TRISB14
 
#define SFT_R LATBbits.LATB15
#define SFT_K LATDbits.LATD5
#define SFT_S LATDbits.LATD4
#define SFT_D LATBbits.LATB14
 
#define GSLAT_TRIS TRISDbits.TRISD9
#define XBLNK_TRIS TRISDbits.TRISD2
 
#define GSLAT LATDbits.LATD9
#define XBLNK LATDbits.LATD2
 
// String Overlay Buffer Size
#define CUBE_STRING_MAX_LENGTH 255
 
// Data Streaming In Buffer Size
#define CUBE_FRAME_BUFFER_SIZE 3000
#define CUBE_START_CHAR 0x7E
#define CUBE_ESCAPE_CHAR 0x7D
#define CUBE_ESCAPE_XOR 0x20
 
// Data Streaming In Command Set
#define CUBE_COMMAND_SET_BC 0x0A // [Brightness Value]
#define CUBE_COMMAND_CLEAR 0x0B // (no data)
#define CUBE_COMMAND_SET_PIXEL 0x10 // [Layer, Row, Column, R, G, B]
#define CUBE_COMMAND_SET_ALL 0x11 // [R1, G1, B1, R2, ...]
#define CUBE_COMMAND_START_TEXT 0x20 // [R, G, B, Char1, Char2, Char3, ...]
#define CUBE_COMMAND_STOP_TEXT 0x21 // (no data)
 
// Ethernet Op-Codes
#define CUBE_ETH_RESET 0x01
#define CUBE_EHT_IDLE 0x02
#define CUBE_ETH_CLEAR 0x0A
#define CUBE_ETH_DCS 0x0B
#define CUBE_ETH_ROTATE 0x0C
#define CUBE_ETH_ROTATE_LAYER 0x0D
#define CUBE_ETH_WRITE_ALL 0x10
#define CUBE_ETH_WRITE_PIXEL 0x11
#define CUBE_ETH_WRITE_CHANNEL 0x12
#define CUBE_ETH_WRITE_TEXT_SCROLL 0x20
#define CUBE_ETH_WRITE_TEXT_STATIC 0x21
#define CUBE_EHT_WRITE_TEXT_INSERT 0x22
#define CUBE_ETH_WATERFALL 0x30
#define CUBE_ETH_SPHERE 0x31
 
typedef enum {
IDLE,
READ_LENGTH_MSB,
READ_LENGTH_LSB,
READ_COMMAND,
READ_DATA,
READ_CHECKSUM
} PROCESS_STATE;
 
typedef struct {
// Variables for base cube
uint8_t GCS[CUBE_LAYER_COUNT][GCS_LAYER_SIZE];
uint8_t GCS_OVERLAY[CUBE_LAYER_COUNT][GCS_LAYER_SIZE];
uint8_t GCS_WRITE[CUBE_LAYER_COUNT][GCS_LAYER_SIZE];
uint8_t current_layer;
uint8_t rotation_counter;
 
// Variables for the scrolling text
uint8_t string[CUBE_STRING_MAX_LENGTH];
uint8_t string_length;
uint8_t string_index;
uint8_t string_line;
uint16_t string_R, string_G, string_B;
 
// Variables for input frame data
PROCESS_STATE frame_state;
uint8_t frame_buffer[CUBE_FRAME_BUFFER_SIZE];
uint8_t frame_checksum;
uint32_t frame_length;
uint32_t frame_index;
uint32_t frame_command;
uint32_t frame_escape;
} CUBE_DATA;
 
void Cube_Init(CUBE_DATA *data, uint8_t BC);
void Cube_Timer_Interrupt(void);
 
// Callbacks on completion of DCS/GCS writes
void Cube_DCS_Write_Callback(void);
void Cube_GCS_Write_Callback(void);
 
// Cube control functions
void Cube_Write_DCS(uint8_t BC);
void Cube_Clear(void);
void Cube_Set_All(uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Layer(uint8_t layer, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Row(uint8_t row, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Column(uint8_t column, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B);
void Cube_Get_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t* R, uint16_t* G, uint16_t* B);
void Cube_Move_Pixel(uint8_t layer1, uint8_t row1, uint8_t column1, uint8_t layer2, uint8_t row2, uint8_t column2);
void Cube_Set_Sphere(uint8_t layer, uint8_t R, uint8_t G, uint8_t B);
void Cube_Set_Shell(uint8_t layer, uint8_t R, uint8_t G, uint8_t B);
void Cube_Rotate_Shell(uint8_t shell, uint8_t direction);
void Cube_Rotate(uint8_t direction);
void Cube_Shift_Row(uint8_t direction);
 
void Cube_Shift_Waterfall(uint8_t *values);
void Cube_Shift_Waterfall2(uint8_t *values);
 
// Overlay control functions
void Cube_Overlay_Clear(void);
void Cube_Overlay_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B);
void Cube_Overlay_Get_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t* R, uint16_t* G, uint16_t* B);
void Cube_Overlay_Move_Pixel(uint8_t layer1, uint8_t row1, uint8_t column1, uint8_t layer2, uint8_t row2, uint8_t column2);
void Cube_Overlay_Rotate_Shell(uint8_t shell, uint8_t direction);
 
// Text control functions
void Cube_Text_Init(uint8_t *string, uint8_t length, uint16_t R, uint16_t G, uint16_t B);
void Cube_Text_Update(void);
void Cube_Text_Insert(uint8_t c, uint16_t R, uint16_t G, uint16_t B, uint16_t delay);
void Cube_Text_Single_Char_Interupt(void);
void Cube_Text_Interrupt(void);
 
// Data stream in control functions
// UART functions
void Cube_Data_In(uint8_t c);
void Cube_Data_In_Process_Frame(void);
void Cube_Data_Direct_Write_All(uint8_t *buffer);
// Ethernet functions
void Cube_Ethernet_Frame_In(void);
 
#endif /* CUBE_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/I2C1.c
0,0 → 1,472
#include "defines.h"
#include "I2C1.h"
 
static I2C1_DATA *i2c_data_p;
 
// Initialize the data structures, should be called once before any I2C routines are called
void I2C1_Init(I2C1_DATA *data, uint8_t speed, uint8_t address) {
i2c_data_p = data;
 
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
 
i2c_data_p->operating_state = I2C1_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C1_MASTER_IDLE;
 
INTDisableInterrupts();
 
// Enable the I2C module and set the clock stretch enable bit
// Note: Automatically overrides any other pin settings
I2C1CONSET = 0x00008040;
I2C1ADD = address;
if (speed == 0x01) {
I2C1BRG = 0x0BE; // Operate at 200kHZ (80MHz)
I2C1CONbits.DISSLW = 0; // Slew rate control enabled
} else if (speed == 0x02) {
I2C1BRG = 0x05A; // Operate at 400kHZ (80MHz)
I2C1CONbits.DISSLW = 1; // Slew rate control disabled
} else if (speed == 0x03) {
I2C1BRG = 0x020; // Operate at 1MHz (80MHz)
I2C1CONbits.DISSLW = 1; // Slew rate control disabled
} else {
I2C1BRG = 0x186; // Operate at 100kHZ (80MHz)
I2C1CONbits.DISSLW = 0; // Slew rate control enabled
}
IFS0CLR = 0xE0000000; // Clear any existing events
IPC6CLR = 0x00001F00; // Reset priority levels
IPC6SET = 0x00001600; // Set IPL=6, Subpriority 2
IEC0SET = 0xE0000000; // Enable I2C1 interrupts
 
INTEnableInterrupts();
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
// Will return status I2C1_SEND_OK or I2C1_SEND_FAIL
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint32_t length) {
uint32_t i;
if (length == 0)
return;
 
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C1_SEND_ADDR;
i2c_data_p->master_status = I2C1_MASTER_SEND;
 
// Generate start condition
I2C1CONbits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
// Will return status I2C1_RECV_OK or I2C1_RECV_FAIL
void I2C1_Master_Recv(uint8_t address, uint32_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C1_SEND_ADDR;
i2c_data_p->master_status = I2C1_MASTER_RECV;
 
// Generate start condition
I2C1CONbits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
// Will return status I2C1_SEND_FAIL or I2C1_RECV_FAIL or I2C1_RECV_OK
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint32_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, &c, 1);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C1_SEND_ADDR;
i2c_data_p->master_status = I2C1_MASTER_RESTART;
 
// Generate start condition
I2C1CONbits.SEN = 1;
}
 
void __ISR(_I2C_1_VECTOR, ipl5) __I2C_1_Interrupt_Handler(void) {
// Bus collision event
if (IFS0bits.I2C1BIF) {
// TODO: Handle bus collision events here
IFS0CLR = 0x20000000;
}
// Slave event
if (IFS0bits.I2C1SIF) {
I2C1_Interrupt_Slave();
IFS0CLR = 0x40000000;
}
// Master event
if (IFS0bits.I2C1MIF) {
I2C1_Interrupt_Master();
IFS0CLR = 0x80000000;
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C1_Interrupt_Master() {
 
/* The PIC32 family has different master interrupts than the PIC8 family
* Master mode operations that generate a slave interrupt are:
* 1. Start condition
* 2. Repeated start sequence
* 3. Stop condition
* 4. Data transfer byte received
* 5. During a send ACK or NACK sequence to slave
* 6. Data transfer byte transmitted
* 7. During a slave-detected stop
*/
 
if (I2C1STATbits.IWCOL == 1) {
// TODO: Handle write collisions
I2C1STATbits.IWCOL = 0;
}
 
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C1_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C1_IDLE:
break;
case I2C1_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C1_CHECK_ACK_SEND;
I2C1TRN = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C1_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!I2C1STATbits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
I2C1TRN = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_SEND_FAIL;
}
break;
case I2C1_STOPPED:
i2c_data_p->operating_state = I2C1_IDLE;
i2c_data_p->master_status = I2C1_MASTER_IDLE;
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C1_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C1_IDLE:
break;
case I2C1_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C1_CHECK_ACK_RECV;
I2C1TRN = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C1_CHECK_ACK_RECV:
// Check if ACK is received
if (!I2C1STATbits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C1_RCV_DATA;
I2C1CONbits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_RECV_FAIL;
}
break;
case I2C1_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle possible I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = I2C1RCV;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C1_REQ_DATA;
I2C1CONbits.ACKDT = 0; // ACK
I2C1CONbits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C1_SEND_STOP;
I2C1CONbits.ACKDT = 1; // NACK
I2C1CONbits.ACKEN = 1;
}
break;
case I2C1_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C1_RCV_DATA;
I2C1CONbits.RCEN = 1;
break;
case I2C1_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_RECV_OK;
break;
case I2C1_STOPPED:
i2c_data_p->operating_state = I2C1_IDLE;
i2c_data_p->master_status = I2C1_MASTER_IDLE;
break;
}
} else if (i2c_data_p->master_status == I2C1_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C1_IDLE:
break;
case I2C1_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C1_CHECK_ACK_SEND;
I2C1TRN = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C1_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!I2C1STATbits.ACKSTAT) {
// If an ACK is received, send first byte of data
uint8_t to_send = i2c_data_p->buffer_in[0];
I2C1TRN = to_send;
i2c_data_p->operating_state = I2C1_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_SEND_FAIL;
}
break;
case I2C1_CHECK_ACK_RESTART:
if (!I2C1STATbits.ACKSTAT) {
I2C1CONbits.RSEN = 1;
i2c_data_p->operating_state = I2C1_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_SEND_FAIL;
}
break;
case I2C1_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C1_CHECK_ACK_RECV;
I2C1TRN = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C1_CHECK_ACK_RECV:
// Check if ACK is received
if (!I2C1STATbits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C1_RCV_DATA;
I2C1CONbits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_RECV_FAIL;
}
break;
case I2C1_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle possible I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = I2C1RCV;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C1_REQ_DATA;
I2C1CONbits.ACKDT = 0; // ACK
I2C1CONbits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C1_SEND_STOP;
I2C1CONbits.ACKDT = 1; // NACK
I2C1CONbits.ACKEN = 1;
}
break;
case I2C1_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C1_RCV_DATA;
I2C1CONbits.RCEN = 1;
break;
case I2C1_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C1_STOPPED;
I2C1CONbits.PEN = 1;
i2c_data_p->return_status = I2C1_RECV_OK;
break;
case I2C1_STOPPED:
i2c_data_p->operating_state = I2C1_IDLE;
i2c_data_p->master_status = I2C1_MASTER_IDLE;
break;
}
}
}
 
void I2C1_Interrupt_Slave() {
// !!WARNING!! THIS CODE DOES -NOT- HAVE ANY ERROR HANDLING !!
// TODO: Add error handling to this interrupt function
 
/* The PIC32 family has different slave interrupts than the PIC8 family
* Slave mode operations that generate a slave interrupt are:
* 1. Detection of a valid device address (including general call)
* 2. Reception of data
* 3. Request to transmit data
*/
 
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (I2C1STATbits.I2COV == 1) {
I2C1STATbits.I2COV = 0;
overrun_error = 1;
i2c_data_p->return_status = I2C1_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (I2C1STATbits.RBF == 1) {
received_data = I2C1RCV;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
if (I2C1STATbits.R_W == 0) {
// Slave is receiving data
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF - 1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
if (i2c_data_p->buffer_in_len < MAXI2C1BUF - 1) {
i2c_data_p->buffer_in_len++;
}
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C1_RECV_OK;
} else {
// Slave is returning data
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C1_Process_Request(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
I2C1TRN = i2c_data_p->buffer_out[0];
data_written_to_buffer = 1;
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
} else {
// Unknown request, fill rest of request with 0s
I2C1TRN = 0x0;
data_written_to_buffer = 1;
i2c_data_p->slave_sending_data = 0;
i2c_data_p->return_status = I2C1_SEND_FAIL;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
I2C1TRN = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
data_written_to_buffer = 1;
i2c_data_p->buffer_out_ind++;
} else {
// Nothing left to send, fill rest of request with 0s
I2C1TRN = 0x0;
data_written_to_buffer = 1;
i2c_data_p->slave_sending_data = 0;
i2c_data_p->return_status = I2C1_SEND_OK;
}
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (I2C1CONbits.SCLREL == 0) {
I2C1CONbits.SCLREL = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
if (i2c_data_p->master_status == I2C1_MASTER_IDLE &&
i2c_data_p->operating_state == I2C1_IDLE &&
I2C1STATbits.TBF == 0) {
return i2c_data_p->return_status;
} else {
return 0;
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint32_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C1_Process_Request(uint8_t c) {
uint8_t ret = 0;
switch (c) {
case 0x01:
i2c_data_p->buffer_out[0] = 0x12;
i2c_data_p->buffer_out_len = 1;
ret = 1;
break;
case 0x02:
i2c_data_p->buffer_out[0] = 0x34;
i2c_data_p->buffer_out[1] = 0x56;
i2c_data_p->buffer_out_len = 2;
ret = 1;
break;
}
return ret;
}
/PIC Projects/Cerebot_32MX7_LED_Cube/I2C1.h
0,0 → 1,80
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 32
 
// I2C Operating Speed
#define I2C1_100KHZ 0x0
#define I2C1_200KHZ 0x1
#define I2C1_400KHZ 0x2
#define I2C1_1MHZ 0x3
 
// Operating State
#define I2C1_IDLE 0x1
//#define I2C1_STARTED 0x2
#define I2C1_RCV_DATA 0x3
//#define I2C1_SEND_DATA 0x4
#define I2C1_SEND_ADDR 0x5
#define I2C1_SEND_ADDR_2 0x6
#define I2C1_CHECK_ACK_SEND 0x7
#define I2C1_CHECK_ACK_RECV 0x8
#define I2C1_CHECK_ACK_RESTART 0x9
#define I2C1_REQ_DATA 0xA
#define I2C1_SEND_STOP 0xB
//#define I2C1_SEND_START 0xC
#define I2C1_STOPPED 0xD
 
// Operating Mode
#define I2C1_MODE_SLAVE 0x10
#define I2C1_MODE_MASTER 0x11
 
// Master Status
#define I2C1_MASTER_SEND 0x20
#define I2C1_MASTER_RECV 0x21
#define I2C1_MASTER_RESTART 0x22
#define I2C1_MASTER_IDLE 0x23
 
// Return Status
#define I2C1_SEND_OK 0x30
#define I2C1_SEND_FAIL 0x31
#define I2C1_RECV_OK 0x32
#define I2C1_RECV_FAIL 0x33
#define I2C1_DATA_AVAL 0x34
#define I2C1_ERR_NOADDR 0x35
#define I2C1_ERR_OVERRUN 0x36
#define I2C1_ERR_NODATA 0x37
#define I2C1_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint32_t buffer_in_len;
uint32_t buffer_in_read_ind;
uint32_t buffer_in_write_ind;
 
uint8_t buffer_out[MAXI2C1BUF];
uint32_t buffer_out_len;
uint32_t buffer_out_ind;
 
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
 
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C1_DATA;
 
void I2C1_Init(I2C1_DATA *data, uint8_t speed, uint8_t address);
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint32_t length);
void I2C1_Master_Recv(uint8_t address, uint32_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint32_t length);
void I2C1_Interrupt_Master(void);
void I2C1_Interrupt_Slave(void);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
uint8_t I2C1_Process_Request(uint8_t);
 
#endif /* I2C1_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/README.txt
0,0 → 1,209
Here lies some random pieces of information that may make it easier to understand the code base
 
Notes:
Power supply must be 5V for proper operation of the board!
 
KNOWN ISSUES:
Cube is occasionally flickering to ~60Hz. Need to figure out why.
>= 400MHz I2C1 doesn't seem to work very well the controllers
 
PERIPHERAL USAGE:
SPI1 - Used by the cube code to send data to the cube
SPI4 - Unused
I2C1 - Used by the controller code
TIMER2 - Used by PWM2
TIMER4 - Used by the cube code for the overlay rotation interrupt / controllers
TIMER5 - Used by the cube code for the update layer interrupt
UART1 - Used by the cube code for reading in frame data
PWM2 - Generates a constant ~20MHz output, uses TIMER2
ETHERNET - Used to remote-update the cube
 
PERIPHERAL INTERRUPT PRIORITY LEVELS:
IPL1 = lowest, IPL7 = highest priority
SPI1 - Priority 6, Subpriority 1
SPI4 - Priority 6, Subpriority 2
I2C1 - Priority 5, Subpriority 2
TIMER5 - Priority 4, Subpriority 1
TIMER4 - Priority 1, Subpriority 1
UART1 - Priority 2, Subpriority 1
ETHERNET - Priority 1, Subpriority 1
 
 
PIN I/Os:
 
JA-01 AN2/C2IN-/CN4/RB2 RB02
JA-02 AN3/C2IN+/CN5/RB3 RB03
JA-03 AN4/C1IN-/CN6/RB4 RB04
JA-04 PGEC2/AN6/OCFA/RB6 RB06
JA-07 PGED2/AN7/RB7 RB07
JA-08 AN8/C1OUT/RB8 RB08
JA-09 AN9/C2OUT/RB9 RB09
JA-10 CVrefout/PMA13/AN10/RB10 RB10
*
JB-01 PMD0/RE0 RE00
JB-02 PMD1/RE1 RE01
JB-03 PMD2/RE2 RE02
JB-04 PMD3/RE3 RE03
JB-07 PMD4/RE4 RE04
JB-08 PMD5/RE5 RE05
JB-09 PMD6/RE6 RE06
JB-10 PMD7/RE7 RE07
*
JC-01 T2CK/RC1 RC01
JC-02 C2RX/PMD8/RG0 RG00
JC-03 C2TX/ETXERR/PMD9/RG1 RG01
JC-04 ETXCLK/PMD15/CN16/RD7 RD07
JC-07 AN15/ERXD3/AETXD2/OCFB/PMALL/PMA0/CN12/RB15 RB15 (SFT_R)
JC-08 PMRD/CN14/RD5 RD05 (SFT_K)
JC-09 OC5/PMWR/CN13/RD4 RD04 (SFT_S)
JC-10 AN14/ERXD2/AETXD3/PMALH/PMA1/RB14 RB14 (SFT_D)
*
JD-01 SS1/IC2/RD9 RD09 (GSLAT)
JD-02 SDO1/OC1/INT0/RD0 RD00 (GSSIN)
JD-03 T5CK/SDI1/RC4 RC04 (GSSOUT)
JD-04 SCK1/IC3/PMCS2/PMA15/RD10 RD10 (GSSCK)
JD-07 OC2/RD1 RD01 (PWMCK)
JD-08 OC3/RD2 RD02 (XBLNK)
JD-09 OC4/RD3 RD03 (DCSIN)
JD-10 ETXD2/IC5/PMD12/RD12 RD12 (DCSCK)
*
JE-01 AETXD0/SS3/U4RX/U1CTS/CN20/RD14 RD14
JE-02 SCL3/SDO3/U1TX/RF8 RF08
JE-03 SDA3/SDI3/U1RX/RF2 RF02
JE-04 AETXD1/SCK3/U4TX/U1RTS/CN21/RD15 RD15
JE-07 TRCLK/RA6 RA06 on 32MX7 or INT1/RF8 on MX7CK
JE-08 TRD3/RA7 RA07
JE-09 Vref-/CVref-/AERXD2/PMA7/RA9 RA09
JE-10 Vref+/CVref+/AERXD3/PMA6/RA10 RA10
*
JF-01 AC1RX/SS4/U5RX/U2CTS/RF12 RF12 shared with CAN1 Transceiver (JP-1)
JF-02 SCL5/SDO4/U2TX/PMA8/CN18/RF5 RF05
JF-03 SDA5/SDI4/U2RX/PMA9/CN17/RF4 RF04
JF-04 AC1TX/SCK4/U5TX/U2RTS/RF13 RF13 shared with CAN1 Transceiver (JP-2)
JF-07 TMS/RA0 RA00 on 32MX7 or INT2/RF9 on MX7CK
JF-08 TCK/RA1 RA01
JF-09 TDI/RA4 RA04
JF-10 TDO/RA5 RA05
 
N/A SCL2/RA2 RA02 I2C bus #2, not shared with Pmod connector
N/A SDA2/RA3 RA03 I2C bus #2, not shared with Pmod connector
N/A AETXCLK/SCL1/INT3/RA14 RA14 I2C Bus #1, not shared with Pmod connector
N/A AETXEN/SDA1/INT4/RA15 RA15 I2C Bus #1, not shared with Pmod connector
N/A PGED1/AN0/CN2/RB0 RB00 Used by debug circuit, PGC
N/A PGEC1/AN1/CN3/RB1 RB01 Used by debug circuit, PGD
N/A AN5/C1IN+/VBUSON/CN7/RB5 RB05 USB VBUSON
N/A AN11/ERXERR/AETXERR/PMA12/RB11 RB11 Ethernet PHY
N/A AN12/ERXD0/AECRS/PMA11/RB12 RB12 Ethernet PHY
N/A AN13/ERXD1/AECOL/PMA10/RB13 RB13 Ethernet PHY
N/A OSC1/CLKI/RC12 RC12 Primary Oscillator Crystal
N/A SOSCI/CN1/RC13 RC13 Secondary Oscillator Crystal
N/A SOSCO/T1CK/CN0/RC14 RC14 Secondary Oscillator Crystal
N/A OSC2/CLKO/RC15 RC15 Primary Oscillator Crystal
N/A ETXEN/PMD14/CN15/RD6 RD06 Ethernet PHY
N/A RTCC/EMDIO/AEMDIO/IC1/RD8 RD08 Ethernet PHY
N/A EMDC/AEMDC/IC4/PMCS1/PMA14/RD11 RD11 Ethernet PHY
N/A ETXD3/PMD13/CN19/RD13 RD13 BTN3
N/A AERXD0/INT1/RE8 RE08 USB Overcurrent detect
N/A AERXD1/INT2/RE9 RE09 Ethernet PHY Reset
N/A C1RX/ETXD1/PMD11/RF0 RF00 Ethernet PHY
N/A C1TX/ETXD0/PMD10/RF1 RF01 Ethernet PHY
N/A USBID/RF3 RF03 USBID (USB-4)
N/A D+/RG2 RG02 D+ (USB-3)
N/A D-/RG3 RG03 D- (USB-2)
N/A ECOL/SCK2/U6TX/U3RTS/PMA5/CN8/RG6 RG06 BTN1
N/A ECRS/SDA4/SDI2/U3RX/PMA4/CN9/RG7 RG07 BTN2
N/A ERXDV/AERXDV/ECRSDV/AECRSDV/SCL4/SDO2/U3TX/PMA3/CN10/RG8 RG08 Ethernet PHY
N/A ERXCLK/AERXCLK/EREFCLK/AEREFCLK/SS2/U6RX/U3CTS/PMA2/CN11/RG9 RG09 Ethernet PHY
N/A TRD1/RG12 RG12 LED1
N/A TRD0/RG13 RG13 LED2
N/A TRD2/RG14 RG14 LED3
N/A AERXERR/RG15 RG15 LED4
 
 
CONNECTORS:
 
J1 - Serial USB Misc Connections (MX7CK only)
* This header contains other FTDI UART function pins (CTS, DSR, DCD, RI)
J2 - Serial USB Connector (MX7CK only)
* This connector is connected to UART1 or PMOD JE
J7 - I2C port daisy chain connector
* On the Cerebot 32MX7, this connector provides access to the I2C signals, power and ground for I2C2.
* On the Cerebot MX7CK, this connector provides access to the I2C signals, power and ground for I2C1 + INT3/4.
J8 - I2C port daisy chain connector
* On the Cerebot 32MX7, this connector provides access to the I2C signals, power and ground for I2C1.
* On the Cerebot MX7CK, this connector provides access to the I2C signals, power and ground for I2C2.
EEPROM is changed to this port on the MX7CK
J9 - CAN #1 Connector
* This connector is used to access the signals for CAN #1.
J10 - CAN #2 Connector
* This connector is used to access the signals for CAN #2.
J11 - Ethernet Connector
* This connector provides access to the 10/100 Ethernet port.
J12-J14
* Do Not Use.
J15 - Debug USB Connector
* This connector is used to connect the on-board programming and
debug circuit to the PC for use with the MPLAB IDE.
J16 - Power supply source select
* This jumper is used to select the source of main board power.
Place a shorting block in the upper, ?USB? position to have the
board powered from the USB device connector, J19.
Place a shorting block in the center, ?EXT? position to have the
board powered from one of the external power connectors, J17 or J18.
Place a shorting block in the lower, ?DBG? position to have the
board powered from the debug USB connector, J15.
J17 - External Power Connector
* This is a 2.5mm x 5.5mm, center positive, coax power connector used to
provide external power to the board. The optional Digilent 5V Switching
Power Supply is connected here.
J18 - External Power Connector
* This is a screw terminal connector used to provide external power to
the board. Be sure to observe proper polarity (marked near the connector)
when providing power via this connector, or damage to the board and/or
connected devices may result.
J19 - USB Device / OTG Connector
* This is a USB micro-AB connector. It is used when using the PIC32MX795
microcontroller to implement a USB device or OTG Host/Device.
J20 - USB Host Connector
* This is a standard sized USB type A connector. This connector is used to
connect USB devices to the board when using the PIC32MX795 microcontroller
to implement an embedded USB host.
 
JUMPERS:
 
JP1 & JP2 - CAN or Pmod Select
* These jumpers select microcontroller signals RF12 and RF13 for use with CAN
#1 or Pmod connector JF. Place these jumpers in the CAN position to use CAN
#1. Place the jumpers in the PMOD position to use then with Pmod connector JF.
JP3 & JP4 - Pull-up enable for I2C port #2
* These two jumpers are used to enable/disable the pull-up resistors on I2C
port #2. Insert shorting blocks on these two jumpers to enable the pull-up
resistors. Remove the shorting blocks to disable the pull-up resistors. Only
a single device on the I2C bus should have the pull-up resistors enabled.
JP5 - CAN #1 Termination
* This jumper is used to enable/disable the 120 ohm termination resistor for
CAN #1. Insert the shorting block to enable the termination resistor, remove
it to disable the termination resistor.
JP6 - CAN #1 5V0 Enable
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
Insert the shorting block to connect the board 5V0 supply to pins 9 & 10 of
CAN #1 connector. Remove the shorting block to disconnect the 5V0 supply.
JP7 - CAN #2 Termination
* This jumper is used to enable/disable the 120 ohm termination resistor for
CAN #2. Insert the shorting block to enable the termination resistor, remove
it to disable the termination resistor.
JP8 - CAN #1 5V0 Enable
* This jumper is used to enable/disable providing 5V to the CAN #1 connector.
Insert the shorting block to connect the board 5V0 supply to pins 9 & 10 of
CAN #1 connector. Remove the shorting block to disconnect the 5V0 supply.
JP9 - Do Not Use
JP10 - USB Host Power Select
* This jumper is used to select which host connector is powered when host power
is enabled. Place the shorting block in the ?MICRO? position to supply power
to the USB micro-AB OTG Connector, J19. Place the shorting block in the ?A?
position to supply power to the USB type A Host Connector, J20.
JP11 - Programmer Serial Select (MX7CK only)
* Remove the jumper to disconnect the USB serial converter's connection to the
MCLR pin. Disconnecting this when using the built in debugger is recommended.
JP17 - Do Not Use
/PIC Projects/Cerebot_32MX7_LED_Cube/SNAKE.h
0,0 → 1,39
#ifndef SNAKE_H
#define SNAKE_H
 
#include "CUBE.h"
 
#define SNAKE_BODY_COLOR BLUE
#define SNAKE_HEAD_COLOR RED
#define SNAKE_CANDY_COLOR GREEN
#define SNAKE_COLLISION_COLOR ORANGE
 
#define SNAKE_MAXIMUM_DELAY 800
#define SNAKE_MINIMUM_DELAY 300
 
typedef struct {
uint8_t x;
uint8_t y;
uint8_t z;
} SNAKE_POINT;
 
typedef struct {
SNAKE_POINT body[CUBE_PIXELS];
SNAKE_POINT direction;
SNAKE_POINT candy_loc;
uint8_t last_direction;
uint32_t pos_head;
uint32_t pos_tail;
uint32_t length;
uint32_t level;
uint32_t delay;
} SNAKE_DATA;
 
void Snake_Init(SNAKE_DATA *data);
void Snake_Main(void);
void Snake_Update_Direction(uint8_t controller, CTRL_BTN_STATUS value);
void Snake_Update_Frame(void);
SNAKE_POINT Snake_Generate_Candy(void);
 
#endif /* SNAKE_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/TIMER5.c
0,0 → 1,56
#include "defines.h"
#include "TIMER5.h"
 
static TIMER5_DATA *timer_data_ptr;
 
void TIMER5_Init(TIMER5_DATA *data, void (*callback)(void), uint32_t time_us) {
if (data != NULL) // if ptr is null, use existing data
timer_data_ptr = data;
 
timer_data_ptr->callback_function = callback;
 
INTDisableInterrupts();
 
T5CON = 0x0;
 
// PR5 is 16 bits wide, so we need to determine what pre-scaler to use
uint16_t time;
if (time_us < 13107) {
time = 5 * time_us;
T5CONSET = 0x0040; // Prescaler at 1:16
} else if (time_us < 26214) {
time = 2.5 * time_us;
T5CONSET = 0x0050; // Prescaler at 1:32
} else if (time_us < 52428) {
time = 1.25 * time_us;
T5CONSET = 0x0060; // Prescaler at 1:64
} else { // Maximum time_us of 209712
time = 0.3125 * time_us;
T5CONSET = 0x0070; // Prescaler at 1:256
}
 
Nop();
TMR5 = 0x0; // Clear timer register
PR5 = time; // Load period register
// IPC5SET = 0x0000000D; // Set priority level = 3, sub-priority level = 1
IPC5SET = 0x00000011; // Set priority level = 4, sub-priority level = 1
IFS0CLR = 0x00100000; // Clear timer interrupt flag
IEC0SET = 0x00100000; // Enable timer interrupt
 
INTEnableInterrupts();
}
 
void TIMER5_Start(void) {
T5CONSET = 0x8000; // Start timer
}
 
void TIMER5_Stop(void) {
T5CONCLR = 0x8000; // Stop timer
}
 
void __ISR(_TIMER_5_VECTOR, ipl4) __TIMER_5_Interrupt_Handler(void) {
// Call the saved callback function
(*timer_data_ptr->callback_function)();
 
IFS0CLR = 0x00100000; // Clear the timer interrupt flag
}
/PIC Projects/Cerebot_32MX7_LED_Cube/ANIMATIONS.h
0,0 → 1,23
#ifndef ANIMATIONS_H
#define ANIMATIONS_H
 
void Animation_Solid_Colors(uint16_t delay_ms);
void Animation_Layer_Alternate(uint16_t delay_ms);
void Animation_Pixel_Alternate(uint16_t delay_ms);
void Animation_Full_Color_Sweep(uint16_t delay_us);
void Animation_Row_Column_Sweep(uint16_t delay_ms);
void Animation_Pixel_Sweep(uint16_t delay_ms);
void Animation_Pseudo_Random_Colors(uint16_t delay_ms);
void Animation_Random_Colors(uint16_t delay_ms);
void Animation_Cube_In_Cube(uint16_t delay_ms);
void Animation_Cube_In_Out(uint16_t delay_ms, uint16_t r, uint16_t g, uint16_t b);
void Animation_Double_Rotation(uint16_t delay_ms);
void Animation_Wave1(uint16_t delay_ms);
void Animation_Wave2(uint16_t delay_ms);
void Animation_Sphere(uint16_t delay_ms);
void Animation_Sawtooth(uint16_t delay_ms);
 
void Animation_Cube_In_Out(uint16_t delay_ms, uint16_t r, uint16_t g, uint16_t b);
 
#endif /* ANIMATIONS_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/CUBE.c
0,0 → 1,1844
#include "defines.h"
#include "CUBE.h"
#include "SPI1.h"
#include "glcdfont.h"
#include "UART1.h"
#include "ETHERNET.h"
#include "TIMER4.h"
 
static CUBE_DATA *cube_data_ptr;
 
inline void Cube_Delay() {
// Small delay to ensure that latch speeds are < 30Mhz
Nop();
Nop();
Nop();
}
 
void Cube_Init(CUBE_DATA *data, uint8_t BC) {
cube_data_ptr = data;
cube_data_ptr->current_layer = 0;
cube_data_ptr->rotation_counter = 0;
cube_data_ptr->frame_state = IDLE;
cube_data_ptr->frame_escape = 0;
 
DCSIN = 0;
DCSCK = 0;
SFT_R = 0;
SFT_K = 0;
SFT_S = 0;
SFT_D = 0;
GSLAT = 0;
XBLNK = 0;
 
DCSIN_TRIS = 0;
DCSCK_TRIS = 0;
SFT_R_TRIS = 0;
SFT_K_TRIS = 0;
SFT_S_TRIS = 0;
SFT_D_TRIS = 0;
GSLAT_TRIS = 0;
XBLNK_TRIS = 0;
 
// Clear the shift register
Cube_Delay();
SFT_K = 1;
Cube_Delay();
SFT_K = 0;
Cube_Delay();
SFT_S = 1;
Cube_Delay();
SFT_S = 0;
Cube_Delay();
SFT_R = 1;
 
Cube_Write_DCS(BC);
Cube_Clear();
Cube_Overlay_Clear();
}
 
void Cube_Timer_Interrupt(void) {
// OR values in the overlay array with the display array
uint8_t i;
uint16_t j;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < GCS_LAYER_SIZE; j++) {
cube_data_ptr->GCS_WRITE[i][j] = cube_data_ptr->GCS[i][j] | cube_data_ptr->GCS_OVERLAY[i][j];
}
}
// Write to the GCS register
SPI1_Write(cube_data_ptr->GCS_WRITE[cube_data_ptr->current_layer], GCS_LAYER_SIZE, &Cube_GCS_Write_Callback);
}
 
////////////////////////
// Callback functions //
////////////////////////
 
void Cube_DCS_Write_Callback(void) {
// GSLAT must be >7ms after DCS write
Delay_MS(7);
GSLAT = 0;
Cube_Delay();
GSLAT = 1;
Cube_Delay();
GSLAT = 0;
}
 
void Cube_GCS_Write_Callback(void) {
// Disable LED output and latch in written data to GCS
XBLNK = 0;
Cube_Delay();
GSLAT = 1;
// Set the shift register to turn on the current layer
uint8_t i;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
Cube_Delay();
SFT_D = (i == CUBE_LAYER_COUNT - cube_data_ptr->current_layer - 1) ? 1 : 0;
Cube_Delay();
SFT_K = 1;
Cube_Delay();
SFT_K = 0;
}
Cube_Delay();
SFT_S = 1;
Cube_Delay();
SFT_S = 0;
Cube_Delay();
// Enable LED output
XBLNK = 1;
Cube_Delay();
GSLAT = 0;
 
cube_data_ptr->current_layer = (cube_data_ptr->current_layer == CUBE_LAYER_COUNT-1)
? 0 : cube_data_ptr->current_layer + 1;
}
 
////////////////////////////
// Cube control functions //
////////////////////////////
 
void Cube_Write_DCS(uint8_t BC) {
XBLNK = 0;
uint8_t i,j;
// Write configuration data to the DC/BC/FC/UD registers
uint8_t DCS[GCS_LAYER_SIZE] = {0};
 
for (i = 0; i < 8; i++) {
uint16_t offset = i * GCS_REG_SIZE;
 
for (j = 0; j < 21; j++) {
DCS[offset + j] = 0xFF; // Dot correction
}
 
// Warning: do not set BC > 0x6F ?? NEED TO VERIFY THIS !!
DCS[offset + 21] = BC; // Global red brightness
DCS[offset + 22] = BC; // Global green brightness
DCS[offset + 23] = BC; // Global blue brightness
 
// DC low range, auto repeat, no timing reset, 8 bit counter mode
DCS[offset + 24] = 0x68; // 0110 1000
}
GSLAT = 1;
SPI1_Write(DCS, GCS_LAYER_SIZE, &Cube_DCS_Write_Callback);
Delay_MS(10); // Delay until the entire DCS write is finished
}
 
void Cube_Clear(void) {
uint8_t i;
uint16_t j;
for (i = 0; i < CUBE_LAYER_COUNT; i++)
for (j = 0; j < GCS_LAYER_SIZE; j++)
cube_data_ptr->GCS[i][j] = 0x00;
}
 
void Cube_Set_All(uint16_t R, uint16_t G, uint16_t B) {
// Set all pixels in the cube to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t i,j,k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
uint16_t j_var = j * GCS_REG_SIZE;
for (k = 0; k < 4; k++) {
uint16_t k_var = j_var + (k * 9);
cube_data_ptr->GCS[i][k_var+0] = R & 0xFF;;
cube_data_ptr->GCS[i][k_var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[i][k_var+2] = G >> 4;
cube_data_ptr->GCS[i][k_var+3] = B & 0xFF;
cube_data_ptr->GCS[i][k_var+4] = (R << 4) | (B >> 8);
cube_data_ptr->GCS[i][k_var+5] = R >> 4;
cube_data_ptr->GCS[i][k_var+6] = G & 0xFF;
cube_data_ptr->GCS[i][k_var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[i][k_var+8] = B >> 4;
}
}
}
}
 
void Cube_Set_Layer(uint8_t layer, uint16_t R, uint16_t G, uint16_t B) {
// Set all pixels in the specified layer to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t i,j;
for (i = 0; i < CUBE_ROW_COUNT; i++) {
uint16_t i_var = i * GCS_REG_SIZE;
for (j = 0; j < 4; j++) {
uint16_t j_var = i_var + (j * 9);
cube_data_ptr->GCS[layer][j_var+0] = R & 0xFF;;
cube_data_ptr->GCS[layer][j_var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][j_var+2] = G >> 4;
cube_data_ptr->GCS[layer][j_var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][j_var+4] = (R << 4) | (B >> 8);
cube_data_ptr->GCS[layer][j_var+5] = R >> 4;
cube_data_ptr->GCS[layer][j_var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][j_var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][j_var+8] = B >> 4;
}
}
}
 
void Cube_Set_Row(uint8_t row, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified row to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t column, layer;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
for (column = 0; column < CUBE_COLUMN_COUNT; column++) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
}
}
 
void Cube_Set_Column(uint8_t column, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified row to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t row, layer;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
for (row = 0; row < CUBE_COLUMN_COUNT; row++) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
}
}
 
void Cube_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified pixel to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
 
void Cube_Get_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t* R, uint16_t* G, uint16_t* B) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
// Concatenate lower byte and upper byte of each color channel
case 0:
*R = cube_data_ptr->GCS[layer][var+0] | ((cube_data_ptr->GCS[layer][var+1] & 0x0F) << 8);
*G = (cube_data_ptr->GCS[layer][var+1] >> 4) | (cube_data_ptr->GCS[layer][var+2] << 4);
*B = cube_data_ptr->GCS[layer][var+3] | ((cube_data_ptr->GCS[layer][var+4] & 0x0F) << 8);
break;
case 1:
*R = (cube_data_ptr->GCS[layer][var+4] >> 4) | (cube_data_ptr->GCS[layer][var+5] << 4);
*G = cube_data_ptr->GCS[layer][var+6] | ((cube_data_ptr->GCS[layer][var+7] & 0x0F) << 8);
*B = (cube_data_ptr->GCS[layer][var+7] >> 4) | (cube_data_ptr->GCS[layer][var+8] << 4);
break;
}
}
 
void Cube_Move_Pixel(uint8_t layer1, uint8_t row1, uint8_t column1, uint8_t layer2, uint8_t row2, uint8_t column2) {
// Copies data from pixel 1 to pixel 2
// Note: destination pixel value is overwritten
uint16_t prev_R, prev_G, prev_B;
Cube_Get_Pixel(layer1, row1, column1, &prev_R, &prev_G, &prev_B);
Cube_Set_Pixel(layer2, row2, column2, prev_R, prev_G, prev_B);
}
 
void Cube_Set_Sphere(uint8_t layer, uint8_t R, uint8_t G, uint8_t B) {
// Super code inefficient (or is it?) lookup table
switch (layer % 9) {
case 0:
Cube_Set_Pixel(3, 3, 3, R, G, B);
Cube_Set_Pixel(3, 3, 4, R, G, B);
Cube_Set_Pixel(3, 4, 3, R, G, B);
Cube_Set_Pixel(3, 4, 4, R, G, B);
Cube_Set_Pixel(4, 3, 3, R, G, B);
Cube_Set_Pixel(4, 3, 4, R, G, B);
Cube_Set_Pixel(4, 4, 3, R, G, B);
Cube_Set_Pixel(4, 4, 4, R, G, B);
break;
case 1:
Cube_Set_Pixel(2, 3, 3, R, G, B);
Cube_Set_Pixel(2, 3, 4, R, G, B);
Cube_Set_Pixel(2, 4, 3, R, G, B);
Cube_Set_Pixel(2, 4, 4, R, G, B);
 
Cube_Set_Pixel(5, 3, 3, R, G, B);
Cube_Set_Pixel(5, 3, 4, R, G, B);
Cube_Set_Pixel(5, 4, 3, R, G, B);
Cube_Set_Pixel(5, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 2, 3, R, G, B);
Cube_Set_Pixel(3, 2, 4, R, G, B);
Cube_Set_Pixel(3, 5, 3, R, G, B);
Cube_Set_Pixel(3, 5, 4, R, G, B);
Cube_Set_Pixel(3, 3, 2, R, G, B);
Cube_Set_Pixel(3, 4, 2, R, G, B);
Cube_Set_Pixel(3, 3, 5, R, G, B);
Cube_Set_Pixel(3, 4, 5, R, G, B);
 
Cube_Set_Pixel(4, 2, 3, R, G, B);
Cube_Set_Pixel(4, 2, 4, R, G, B);
Cube_Set_Pixel(4, 5, 3, R, G, B);
Cube_Set_Pixel(4, 5, 4, R, G, B);
Cube_Set_Pixel(4, 3, 2, R, G, B);
Cube_Set_Pixel(4, 4, 2, R, G, B);
Cube_Set_Pixel(4, 3, 5, R, G, B);
Cube_Set_Pixel(4, 4, 5, R, G, B);
break;
case 2:
Cube_Set_Pixel(1, 3, 3, R, G, B);
Cube_Set_Pixel(1, 3, 4, R, G, B);
Cube_Set_Pixel(1, 4, 3, R, G, B);
Cube_Set_Pixel(1, 4, 4, R, G, B);
Cube_Set_Pixel(6, 3, 3, R, G, B);
Cube_Set_Pixel(6, 3, 4, R, G, B);
Cube_Set_Pixel(6, 4, 3, R, G, B);
Cube_Set_Pixel(6, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 1, 3, R, G, B);
Cube_Set_Pixel(3, 1, 4, R, G, B);
Cube_Set_Pixel(3, 6, 3, R, G, B);
Cube_Set_Pixel(3, 6, 4, R, G, B);
Cube_Set_Pixel(3, 3, 1, R, G, B);
Cube_Set_Pixel(3, 4, 1, R, G, B);
Cube_Set_Pixel(3, 3, 6, R, G, B);
Cube_Set_Pixel(3, 4, 6, R, G, B);
 
Cube_Set_Pixel(3, 2, 2, R, G, B);
Cube_Set_Pixel(3, 2, 5, R, G, B);
Cube_Set_Pixel(3, 5, 5, R, G, B);
Cube_Set_Pixel(3, 5, 2, R, G, B);
 
Cube_Set_Pixel(4, 1, 3, R, G, B);
Cube_Set_Pixel(4, 1, 4, R, G, B);
Cube_Set_Pixel(4, 6, 3, R, G, B);
Cube_Set_Pixel(4, 6, 4, R, G, B);
Cube_Set_Pixel(4, 3, 1, R, G, B);
Cube_Set_Pixel(4, 4, 1, R, G, B);
Cube_Set_Pixel(4, 3, 6, R, G, B);
Cube_Set_Pixel(4, 4, 6, R, G, B);
 
Cube_Set_Pixel(4, 2, 2, R, G, B);
Cube_Set_Pixel(4, 2, 5, R, G, B);
Cube_Set_Pixel(4, 5, 5, R, G, B);
Cube_Set_Pixel(4, 5, 2, R, G, B);
 
Cube_Set_Pixel(2, 3, 2, R, G, B);
Cube_Set_Pixel(2, 4, 2, R, G, B);
Cube_Set_Pixel(2, 3, 5, R, G, B);
Cube_Set_Pixel(2, 4, 5, R, G, B);
Cube_Set_Pixel(2, 2, 3, R, G, B);
Cube_Set_Pixel(2, 2, 4, R, G, B);
Cube_Set_Pixel(2, 5, 3, R, G, B);
Cube_Set_Pixel(2, 5, 4, R, G, B);
 
Cube_Set_Pixel(2, 2, 2, R, G, B);
Cube_Set_Pixel(2, 2, 5, R, G, B);
Cube_Set_Pixel(2, 5, 2, R, G, B);
Cube_Set_Pixel(2, 5, 5, R, G, B);
 
Cube_Set_Pixel(5, 3, 2, R, G, B);
Cube_Set_Pixel(5, 4, 2, R, G, B);
Cube_Set_Pixel(5, 3, 5, R, G, B);
Cube_Set_Pixel(5, 4, 5, R, G, B);
Cube_Set_Pixel(5, 2, 3, R, G, B);
Cube_Set_Pixel(5, 2, 4, R, G, B);
Cube_Set_Pixel(5, 5, 3, R, G, B);
Cube_Set_Pixel(5, 5, 4, R, G, B);
 
Cube_Set_Pixel(5, 2, 2, R, G, B);
Cube_Set_Pixel(5, 2, 5, R, G, B);
Cube_Set_Pixel(5, 5, 2, R, G, B);
Cube_Set_Pixel(5, 5, 5, R, G, B);
break;
case 3:
Cube_Set_Pixel(0, 3, 3, R, G, B);
Cube_Set_Pixel(0, 3, 4, R, G, B);
Cube_Set_Pixel(0, 4, 3, R, G, B);
Cube_Set_Pixel(0, 4, 4, R, G, B);
Cube_Set_Pixel(7, 3, 3, R, G, B);
Cube_Set_Pixel(7, 3, 4, R, G, B);
Cube_Set_Pixel(7, 4, 3, R, G, B);
Cube_Set_Pixel(7, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 0, 3, R, G, B);
Cube_Set_Pixel(3, 0, 4, R, G, B);
Cube_Set_Pixel(3, 7, 3, R, G, B);
Cube_Set_Pixel(3, 7, 4, R, G, B);
Cube_Set_Pixel(3, 3, 0, R, G, B);
Cube_Set_Pixel(3, 4, 0, R, G, B);
Cube_Set_Pixel(3, 3, 7, R, G, B);
Cube_Set_Pixel(3, 4, 7, R, G, B);
 
Cube_Set_Pixel(3, 2, 6, R, G, B);
Cube_Set_Pixel(3, 1, 5, R, G, B);
Cube_Set_Pixel(3, 6, 2, R, G, B);
Cube_Set_Pixel(3, 5, 1, R, G, B);
Cube_Set_Pixel(3, 1, 2, R, G, B);
Cube_Set_Pixel(3, 2, 1, R, G, B);
Cube_Set_Pixel(3, 6, 5, R, G, B);
Cube_Set_Pixel(3, 5, 6, R, G, B);
 
Cube_Set_Pixel(4, 0, 3, R, G, B);
Cube_Set_Pixel(4, 0, 4, R, G, B);
Cube_Set_Pixel(4, 7, 3, R, G, B);
Cube_Set_Pixel(4, 7, 4, R, G, B);
Cube_Set_Pixel(4, 3, 0, R, G, B);
Cube_Set_Pixel(4, 4, 0, R, G, B);
Cube_Set_Pixel(4, 3, 7, R, G, B);
Cube_Set_Pixel(4, 4, 7, R, G, B);
 
Cube_Set_Pixel(4, 2, 6, R, G, B);
Cube_Set_Pixel(4, 1, 5, R, G, B);
Cube_Set_Pixel(4, 6, 2, R, G, B);
Cube_Set_Pixel(4, 5, 1, R, G, B);
Cube_Set_Pixel(4, 1, 2, R, G, B);
Cube_Set_Pixel(4, 2, 1, R, G, B);
Cube_Set_Pixel(4, 6, 5, R, G, B);
Cube_Set_Pixel(4, 5, 6, R, G, B);
 
Cube_Set_Pixel(1, 2, 5, R, G, B);
Cube_Set_Pixel(1, 2, 4, R, G, B);
Cube_Set_Pixel(1, 2, 3, R, G, B);
Cube_Set_Pixel(1, 2, 2, R, G, B);
Cube_Set_Pixel(1, 3, 5, R, G, B);
Cube_Set_Pixel(1, 3, 2, R, G, B);
Cube_Set_Pixel(1, 4, 5, R, G, B);
Cube_Set_Pixel(1, 4, 2, R, G, B);
Cube_Set_Pixel(1, 5, 5, R, G, B);
Cube_Set_Pixel(1, 5, 4, R, G, B);
Cube_Set_Pixel(1, 5, 3, R, G, B);
Cube_Set_Pixel(1, 5, 2, R, G, B);
 
Cube_Set_Pixel(2, 1, 5, R, G, B);
Cube_Set_Pixel(2, 1, 4, R, G, B);
Cube_Set_Pixel(2, 1, 3, R, G, B);
Cube_Set_Pixel(2, 1, 2, R, G, B);
Cube_Set_Pixel(2, 6, 5, R, G, B);
Cube_Set_Pixel(2, 6, 4, R, G, B);
Cube_Set_Pixel(2, 6, 3, R, G, B);
Cube_Set_Pixel(2, 6, 2, R, G, B);
Cube_Set_Pixel(2, 2, 6, R, G, B);
Cube_Set_Pixel(2, 3, 6, R, G, B);
Cube_Set_Pixel(2, 4, 6, R, G, B);
Cube_Set_Pixel(2, 5, 6, R, G, B);
Cube_Set_Pixel(2, 2, 1, R, G, B);
Cube_Set_Pixel(2, 3, 1, R, G, B);
Cube_Set_Pixel(2, 4, 1, R, G, B);
Cube_Set_Pixel(2, 5, 1, R, G, B);
 
Cube_Set_Pixel(5, 1, 5, R, G, B);
Cube_Set_Pixel(5, 1, 4, R, G, B);
Cube_Set_Pixel(5, 1, 3, R, G, B);
Cube_Set_Pixel(5, 1, 2, R, G, B);
Cube_Set_Pixel(5, 6, 5, R, G, B);
Cube_Set_Pixel(5, 6, 4, R, G, B);
Cube_Set_Pixel(5, 6, 3, R, G, B);
Cube_Set_Pixel(5, 6, 2, R, G, B);
Cube_Set_Pixel(5, 2, 6, R, G, B);
Cube_Set_Pixel(5, 3, 6, R, G, B);
Cube_Set_Pixel(5, 4, 6, R, G, B);
Cube_Set_Pixel(5, 5, 6, R, G, B);
Cube_Set_Pixel(5, 2, 1, R, G, B);
Cube_Set_Pixel(5, 3, 1, R, G, B);
Cube_Set_Pixel(5, 4, 1, R, G, B);
Cube_Set_Pixel(5, 5, 1, R, G, B);
 
Cube_Set_Pixel(6, 2, 5, R, G, B);
Cube_Set_Pixel(6, 2, 4, R, G, B);
Cube_Set_Pixel(6, 2, 3, R, G, B);
Cube_Set_Pixel(6, 2, 2, R, G, B);
Cube_Set_Pixel(6, 3, 5, R, G, B);
Cube_Set_Pixel(6, 3, 2, R, G, B);
Cube_Set_Pixel(6, 4, 5, R, G, B);
Cube_Set_Pixel(6, 4, 2, R, G, B);
Cube_Set_Pixel(6, 5, 5, R, G, B);
Cube_Set_Pixel(6, 5, 4, R, G, B);
Cube_Set_Pixel(6, 5, 3, R, G, B);
Cube_Set_Pixel(6, 5, 2, R, G, B);
break;
case 4:
Cube_Set_Pixel(0, 2, 5, R, G, B);
Cube_Set_Pixel(0, 2, 4, R, G, B);
Cube_Set_Pixel(0, 2, 3, R, G, B);
Cube_Set_Pixel(0, 2, 2, R, G, B);
Cube_Set_Pixel(0, 3, 5, R, G, B);
Cube_Set_Pixel(0, 3, 2, R, G, B);
Cube_Set_Pixel(0, 4, 5, R, G, B);
Cube_Set_Pixel(0, 4, 2, R, G, B);
Cube_Set_Pixel(0, 5, 5, R, G, B);
Cube_Set_Pixel(0, 5, 4, R, G, B);
Cube_Set_Pixel(0, 5, 3, R, G, B);
Cube_Set_Pixel(0, 5, 2, R, G, B);
 
Cube_Set_Pixel(7, 2, 5, R, G, B);
Cube_Set_Pixel(7, 2, 4, R, G, B);
Cube_Set_Pixel(7, 2, 3, R, G, B);
Cube_Set_Pixel(7, 2, 2, R, G, B);
Cube_Set_Pixel(7, 3, 5, R, G, B);
Cube_Set_Pixel(7, 3, 2, R, G, B);
Cube_Set_Pixel(7, 4, 5, R, G, B);
Cube_Set_Pixel(7, 4, 2, R, G, B);
Cube_Set_Pixel(7, 5, 5, R, G, B);
Cube_Set_Pixel(7, 5, 4, R, G, B);
Cube_Set_Pixel(7, 5, 3, R, G, B);
Cube_Set_Pixel(7, 5, 2, R, G, B);
 
Cube_Set_Pixel(1, 1, 5, R, G, B);
Cube_Set_Pixel(1, 1, 4, R, G, B);
Cube_Set_Pixel(1, 1, 3, R, G, B);
Cube_Set_Pixel(1, 1, 2, R, G, B);
Cube_Set_Pixel(1, 6, 5, R, G, B);
Cube_Set_Pixel(1, 6, 4, R, G, B);
Cube_Set_Pixel(1, 6, 3, R, G, B);
Cube_Set_Pixel(1, 6, 2, R, G, B);
Cube_Set_Pixel(1, 2, 6, R, G, B);
Cube_Set_Pixel(1, 3, 6, R, G, B);
Cube_Set_Pixel(1, 4, 6, R, G, B);
Cube_Set_Pixel(1, 5, 6, R, G, B);
Cube_Set_Pixel(1, 2, 1, R, G, B);
Cube_Set_Pixel(1, 3, 1, R, G, B);
Cube_Set_Pixel(1, 4, 1, R, G, B);
Cube_Set_Pixel(1, 5, 1, R, G, B);
 
Cube_Set_Pixel(6, 1, 5, R, G, B);
Cube_Set_Pixel(6, 1, 4, R, G, B);
Cube_Set_Pixel(6, 1, 3, R, G, B);
Cube_Set_Pixel(6, 1, 2, R, G, B);
Cube_Set_Pixel(6, 6, 5, R, G, B);
Cube_Set_Pixel(6, 6, 4, R, G, B);
Cube_Set_Pixel(6, 6, 3, R, G, B);
Cube_Set_Pixel(6, 6, 2, R, G, B);
Cube_Set_Pixel(6, 2, 6, R, G, B);
Cube_Set_Pixel(6, 3, 6, R, G, B);
Cube_Set_Pixel(6, 4, 6, R, G, B);
Cube_Set_Pixel(6, 5, 6, R, G, B);
Cube_Set_Pixel(6, 2, 1, R, G, B);
Cube_Set_Pixel(6, 3, 1, R, G, B);
Cube_Set_Pixel(6, 4, 1, R, G, B);
Cube_Set_Pixel(6, 5, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 5, R, G, B);
Cube_Set_Pixel(2, 0, 4, R, G, B);
Cube_Set_Pixel(2, 0, 3, R, G, B);
Cube_Set_Pixel(2, 0, 2, R, G, B);
Cube_Set_Pixel(2, 7, 5, R, G, B);
Cube_Set_Pixel(2, 7, 4, R, G, B);
Cube_Set_Pixel(2, 7, 3, R, G, B);
Cube_Set_Pixel(2, 7, 2, R, G, B);
Cube_Set_Pixel(2, 5, 0, R, G, B);
Cube_Set_Pixel(2, 4, 0, R, G, B);
Cube_Set_Pixel(2, 3, 0, R, G, B);
Cube_Set_Pixel(2, 2, 0, R, G, B);
Cube_Set_Pixel(2, 5, 7, R, G, B);
Cube_Set_Pixel(2, 4, 7, R, G, B);
Cube_Set_Pixel(2, 3, 7, R, G, B);
Cube_Set_Pixel(2, 2, 7, R, G, B);
Cube_Set_Pixel(2, 1, 1, R, G, B);
Cube_Set_Pixel(2, 1, 6, R, G, B);
Cube_Set_Pixel(2, 6, 1, R, G, B);
Cube_Set_Pixel(2, 6, 6, R, G, B);
 
Cube_Set_Pixel(5, 0, 5, R, G, B);
Cube_Set_Pixel(5, 0, 4, R, G, B);
Cube_Set_Pixel(5, 0, 3, R, G, B);
Cube_Set_Pixel(5, 0, 2, R, G, B);
Cube_Set_Pixel(5, 7, 5, R, G, B);
Cube_Set_Pixel(5, 7, 4, R, G, B);
Cube_Set_Pixel(5, 7, 3, R, G, B);
Cube_Set_Pixel(5, 7, 2, R, G, B);
Cube_Set_Pixel(5, 5, 0, R, G, B);
Cube_Set_Pixel(5, 4, 0, R, G, B);
Cube_Set_Pixel(5, 3, 0, R, G, B);
Cube_Set_Pixel(5, 2, 0, R, G, B);
Cube_Set_Pixel(5, 5, 7, R, G, B);
Cube_Set_Pixel(5, 4, 7, R, G, B);
Cube_Set_Pixel(5, 3, 7, R, G, B);
Cube_Set_Pixel(5, 2, 7, R, G, B);
Cube_Set_Pixel(5, 1, 1, R, G, B);
Cube_Set_Pixel(5, 1, 6, R, G, B);
Cube_Set_Pixel(5, 6, 1, R, G, B);
Cube_Set_Pixel(5, 6, 6, R, G, B);
 
Cube_Set_Pixel(3, 0, 2, R, G, B);
Cube_Set_Pixel(3, 0, 5, R, G, B);
Cube_Set_Pixel(3, 2, 0, R, G, B);
Cube_Set_Pixel(3, 5, 0, R, G, B);
Cube_Set_Pixel(3, 7, 2, R, G, B);
Cube_Set_Pixel(3, 7, 5, R, G, B);
Cube_Set_Pixel(3, 2, 7, R, G, B);
Cube_Set_Pixel(3, 5, 7, R, G, B);
Cube_Set_Pixel(3, 1, 1, R, G, B);
Cube_Set_Pixel(3, 1, 6, R, G, B);
Cube_Set_Pixel(3, 6, 1, R, G, B);
Cube_Set_Pixel(3, 6, 6, R, G, B);
 
Cube_Set_Pixel(4, 0, 2, R, G, B);
Cube_Set_Pixel(4, 0, 5, R, G, B);
Cube_Set_Pixel(4, 2, 0, R, G, B);
Cube_Set_Pixel(4, 5, 0, R, G, B);
Cube_Set_Pixel(4, 7, 2, R, G, B);
Cube_Set_Pixel(4, 7, 5, R, G, B);
Cube_Set_Pixel(4, 2, 7, R, G, B);
Cube_Set_Pixel(4, 5, 7, R, G, B);
Cube_Set_Pixel(4, 1, 1, R, G, B);
Cube_Set_Pixel(4, 1, 6, R, G, B);
Cube_Set_Pixel(4, 6, 1, R, G, B);
Cube_Set_Pixel(4, 6, 6, R, G, B);
break;
case 5:
Cube_Set_Pixel(0, 1, 5, R, G, B);
Cube_Set_Pixel(0, 1, 4, R, G, B);
Cube_Set_Pixel(0, 1, 3, R, G, B);
Cube_Set_Pixel(0, 1, 2, R, G, B);
Cube_Set_Pixel(0, 6, 5, R, G, B);
Cube_Set_Pixel(0, 6, 4, R, G, B);
Cube_Set_Pixel(0, 6, 3, R, G, B);
Cube_Set_Pixel(0, 6, 2, R, G, B);
Cube_Set_Pixel(0, 2, 6, R, G, B);
Cube_Set_Pixel(0, 3, 6, R, G, B);
Cube_Set_Pixel(0, 4, 6, R, G, B);
Cube_Set_Pixel(0, 5, 6, R, G, B);
Cube_Set_Pixel(0, 2, 1, R, G, B);
Cube_Set_Pixel(0, 3, 1, R, G, B);
Cube_Set_Pixel(0, 4, 1, R, G, B);
Cube_Set_Pixel(0, 5, 1, R, G, B);
 
Cube_Set_Pixel(1, 0, 2, R, G, B);
Cube_Set_Pixel(1, 0, 3, R, G, B);
Cube_Set_Pixel(1, 0, 4, R, G, B);
Cube_Set_Pixel(1, 0, 5, R, G, B);
Cube_Set_Pixel(1, 1, 6, R, G, B);
Cube_Set_Pixel(1, 2, 7, R, G, B);
Cube_Set_Pixel(1, 3, 7, R, G, B);
Cube_Set_Pixel(1, 4, 7, R, G, B);
Cube_Set_Pixel(1, 5, 7, R, G, B);
Cube_Set_Pixel(1, 6, 6, R, G, B);
Cube_Set_Pixel(1, 7, 5, R, G, B);
Cube_Set_Pixel(1, 7, 4, R, G, B);
Cube_Set_Pixel(1, 7, 3, R, G, B);
Cube_Set_Pixel(1, 7, 2, R, G, B);
Cube_Set_Pixel(1, 6, 1, R, G, B);
Cube_Set_Pixel(1, 5, 0, R, G, B);
Cube_Set_Pixel(1, 4, 0, R, G, B);
Cube_Set_Pixel(1, 3, 0, R, G, B);
Cube_Set_Pixel(1, 2, 0, R, G, B);
Cube_Set_Pixel(1, 1, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 1, R, G, B);
Cube_Set_Pixel(2, 1, 0, R, G, B);
Cube_Set_Pixel(2, 0, 6, R, G, B);
Cube_Set_Pixel(2, 1, 7, R, G, B);
Cube_Set_Pixel(2, 6, 7, R, G, B);
Cube_Set_Pixel(2, 7, 6, R, G, B);
Cube_Set_Pixel(2, 6, 0, R, G, B);
Cube_Set_Pixel(2, 7, 1, R, G, B);
 
Cube_Set_Pixel(3, 0, 1, R, G, B);
Cube_Set_Pixel(3, 1, 0, R, G, B);
Cube_Set_Pixel(3, 0, 6, R, G, B);
Cube_Set_Pixel(3, 1, 7, R, G, B);
Cube_Set_Pixel(3, 6, 7, R, G, B);
Cube_Set_Pixel(3, 7, 6, R, G, B);
Cube_Set_Pixel(3, 6, 0, R, G, B);
Cube_Set_Pixel(3, 7, 1, R, G, B);
 
Cube_Set_Pixel(4, 0, 1, R, G, B);
Cube_Set_Pixel(4, 1, 0, R, G, B);
Cube_Set_Pixel(4, 0, 6, R, G, B);
Cube_Set_Pixel(4, 1, 7, R, G, B);
Cube_Set_Pixel(4, 6, 7, R, G, B);
Cube_Set_Pixel(4, 7, 6, R, G, B);
Cube_Set_Pixel(4, 6, 0, R, G, B);
Cube_Set_Pixel(4, 7, 1, R, G, B);
 
Cube_Set_Pixel(5, 0, 1, R, G, B);
Cube_Set_Pixel(5, 1, 0, R, G, B);
Cube_Set_Pixel(5, 0, 6, R, G, B);
Cube_Set_Pixel(5, 1, 7, R, G, B);
Cube_Set_Pixel(5, 6, 7, R, G, B);
Cube_Set_Pixel(5, 7, 6, R, G, B);
Cube_Set_Pixel(5, 6, 0, R, G, B);
Cube_Set_Pixel(5, 7, 1, R, G, B);
 
 
Cube_Set_Pixel(6, 0, 2, R, G, B);
Cube_Set_Pixel(6, 0, 3, R, G, B);
Cube_Set_Pixel(6, 0, 4, R, G, B);
Cube_Set_Pixel(6, 0, 5, R, G, B);
Cube_Set_Pixel(6, 1, 6, R, G, B);
Cube_Set_Pixel(6, 2, 7, R, G, B);
Cube_Set_Pixel(6, 3, 7, R, G, B);
Cube_Set_Pixel(6, 4, 7, R, G, B);
Cube_Set_Pixel(6, 5, 7, R, G, B);
Cube_Set_Pixel(6, 6, 6, R, G, B);
Cube_Set_Pixel(6, 7, 5, R, G, B);
Cube_Set_Pixel(6, 7, 4, R, G, B);
Cube_Set_Pixel(6, 7, 3, R, G, B);
Cube_Set_Pixel(6, 7, 2, R, G, B);
Cube_Set_Pixel(6, 6, 1, R, G, B);
Cube_Set_Pixel(6, 5, 0, R, G, B);
Cube_Set_Pixel(6, 4, 0, R, G, B);
Cube_Set_Pixel(6, 3, 0, R, G, B);
Cube_Set_Pixel(6, 2, 0, R, G, B);
Cube_Set_Pixel(6, 1, 1, R, G, B);
 
Cube_Set_Pixel(7, 1, 5, R, G, B);
Cube_Set_Pixel(7, 1, 4, R, G, B);
Cube_Set_Pixel(7, 1, 3, R, G, B);
Cube_Set_Pixel(7, 1, 2, R, G, B);
Cube_Set_Pixel(7, 6, 5, R, G, B);
Cube_Set_Pixel(7, 6, 4, R, G, B);
Cube_Set_Pixel(7, 6, 3, R, G, B);
Cube_Set_Pixel(7, 6, 2, R, G, B);
Cube_Set_Pixel(7, 2, 6, R, G, B);
Cube_Set_Pixel(7, 3, 6, R, G, B);
Cube_Set_Pixel(7, 4, 6, R, G, B);
Cube_Set_Pixel(7, 5, 6, R, G, B);
Cube_Set_Pixel(7, 2, 1, R, G, B);
Cube_Set_Pixel(7, 3, 1, R, G, B);
Cube_Set_Pixel(7, 4, 1, R, G, B);
Cube_Set_Pixel(7, 5, 1, R, G, B);
break;
case 6:
Cube_Set_Pixel(0, 0, 2, R, G, B);
Cube_Set_Pixel(0, 0, 3, R, G, B);
Cube_Set_Pixel(0, 0, 4, R, G, B);
Cube_Set_Pixel(0, 0, 5, R, G, B);
Cube_Set_Pixel(0, 1, 1, R, G, B);
Cube_Set_Pixel(0, 1, 6, R, G, B);
Cube_Set_Pixel(0, 2, 0, R, G, B);
Cube_Set_Pixel(0, 2, 7, R, G, B);
Cube_Set_Pixel(0, 3, 0, R, G, B);
Cube_Set_Pixel(0, 3, 7, R, G, B);
Cube_Set_Pixel(0, 4, 0, R, G, B);
Cube_Set_Pixel(0, 4, 7, R, G, B);
Cube_Set_Pixel(0, 5, 0, R, G, B);
Cube_Set_Pixel(0, 5, 7, R, G, B);
Cube_Set_Pixel(0, 6, 6, R, G, B);
Cube_Set_Pixel(0, 6, 1, R, G, B);
Cube_Set_Pixel(0, 7, 2, R, G, B);
Cube_Set_Pixel(0, 7, 3, R, G, B);
Cube_Set_Pixel(0, 7, 4, R, G, B);
Cube_Set_Pixel(0, 7, 5, R, G, B);
 
Cube_Set_Pixel(1, 0, 1, R, G, B);
Cube_Set_Pixel(1, 1, 0, R, G, B);
Cube_Set_Pixel(1, 0, 6, R, G, B);
Cube_Set_Pixel(1, 1, 7, R, G, B);
Cube_Set_Pixel(1, 6, 7, R, G, B);
Cube_Set_Pixel(1, 7, 6, R, G, B);
Cube_Set_Pixel(1, 6, 0, R, G, B);
Cube_Set_Pixel(1, 7, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 0, R, G, B);
Cube_Set_Pixel(2, 0, 7, R, G, B);
Cube_Set_Pixel(2, 7, 7, R, G, B);
Cube_Set_Pixel(2, 7, 0, R, G, B);
 
Cube_Set_Pixel(3, 0, 0, R, G, B);
Cube_Set_Pixel(3, 0, 7, R, G, B);
Cube_Set_Pixel(3, 7, 7, R, G, B);
Cube_Set_Pixel(3, 7, 0, R, G, B);
 
Cube_Set_Pixel(4, 0, 0, R, G, B);
Cube_Set_Pixel(4, 0, 7, R, G, B);
Cube_Set_Pixel(4, 7, 7, R, G, B);
Cube_Set_Pixel(4, 7, 0, R, G, B);
 
Cube_Set_Pixel(5, 0, 0, R, G, B);
Cube_Set_Pixel(5, 0, 7, R, G, B);
Cube_Set_Pixel(5, 7, 7, R, G, B);
Cube_Set_Pixel(5, 7, 0, R, G, B);
 
Cube_Set_Pixel(6, 0, 1, R, G, B);
Cube_Set_Pixel(6, 1, 0, R, G, B);
Cube_Set_Pixel(6, 0, 6, R, G, B);
Cube_Set_Pixel(6, 1, 7, R, G, B);
Cube_Set_Pixel(6, 6, 7, R, G, B);
Cube_Set_Pixel(6, 7, 6, R, G, B);
Cube_Set_Pixel(6, 6, 0, R, G, B);
Cube_Set_Pixel(6, 7, 1, R, G, B);
 
Cube_Set_Pixel(7, 0, 2, R, G, B);
Cube_Set_Pixel(7, 0, 3, R, G, B);
Cube_Set_Pixel(7, 0, 4, R, G, B);
Cube_Set_Pixel(7, 0, 5, R, G, B);
Cube_Set_Pixel(7, 1, 1, R, G, B);
Cube_Set_Pixel(7, 1, 6, R, G, B);
Cube_Set_Pixel(7, 2, 0, R, G, B);
Cube_Set_Pixel(7, 2, 7, R, G, B);
Cube_Set_Pixel(7, 3, 0, R, G, B);
Cube_Set_Pixel(7, 3, 7, R, G, B);
Cube_Set_Pixel(7, 4, 0, R, G, B);
Cube_Set_Pixel(7, 4, 7, R, G, B);
Cube_Set_Pixel(7, 5, 0, R, G, B);
Cube_Set_Pixel(7, 5, 7, R, G, B);
Cube_Set_Pixel(7, 6, 6, R, G, B);
Cube_Set_Pixel(7, 6, 1, R, G, B);
Cube_Set_Pixel(7, 7, 2, R, G, B);
Cube_Set_Pixel(7, 7, 3, R, G, B);
Cube_Set_Pixel(7, 7, 4, R, G, B);
Cube_Set_Pixel(7, 7, 5, R, G, B);
break;
case 7:
Cube_Set_Pixel(0, 0, 1, R, G, B);
Cube_Set_Pixel(0, 1, 0, R, G, B);
Cube_Set_Pixel(0, 0, 6, R, G, B);
Cube_Set_Pixel(0, 1, 7, R, G, B);
Cube_Set_Pixel(0, 6, 7, R, G, B);
Cube_Set_Pixel(0, 7, 6, R, G, B);
Cube_Set_Pixel(0, 7, 1, R, G, B);
Cube_Set_Pixel(0, 6, 0, R, G, B);
 
Cube_Set_Pixel(1, 0, 0, R, G, B);
Cube_Set_Pixel(1, 0, 7, R, G, B);
Cube_Set_Pixel(1, 7, 7, R, G, B);
Cube_Set_Pixel(1, 7, 0, R, G, B);
 
Cube_Set_Pixel(6, 0, 0, R, G, B);
Cube_Set_Pixel(6, 0, 7, R, G, B);
Cube_Set_Pixel(6, 7, 7, R, G, B);
Cube_Set_Pixel(6, 7, 0, R, G, B);
 
Cube_Set_Pixel(7, 0, 1, R, G, B);
Cube_Set_Pixel(7, 1, 0, R, G, B);
Cube_Set_Pixel(7, 0, 6, R, G, B);
Cube_Set_Pixel(7, 1, 7, R, G, B);
Cube_Set_Pixel(7, 6, 7, R, G, B);
Cube_Set_Pixel(7, 7, 6, R, G, B);
Cube_Set_Pixel(7, 7, 1, R, G, B);
Cube_Set_Pixel(7, 6, 0, R, G, B);
break;
case 8:
Cube_Set_Pixel(0, 0, 0, R, G, B);
Cube_Set_Pixel(0, 0, 7, R, G, B);
Cube_Set_Pixel(0, 7, 7, R, G, B);
Cube_Set_Pixel(0, 7, 0, R, G, B);
 
Cube_Set_Pixel(7, 0, 0, R, G, B);
Cube_Set_Pixel(7, 0, 7, R, G, B);
Cube_Set_Pixel(7, 7, 7, R, G, B);
Cube_Set_Pixel(7, 7, 0, R, G, B);
break;
default:
break;
}
}
 
void Cube_Set_Shell(uint8_t layer, uint8_t R, uint8_t G, uint8_t B) {
// Sets the specified shell to the specific color
// Shell 0 is the outermost layer, 3 is the innermost cube of pixels
uint8_t i, j, k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if ((layer == 0 || layer == 4)&&(i == 0 || i == 7)) {
Cube_Set_Layer(i,R,G,B);
} else if ((layer == 1 || layer == 4)&&(i == 1 || i == 6)) {
for (j = 1; j < CUBE_ROW_COUNT-1; j++)
for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
} else if ((layer == 2 || layer == 4)&&(i == 2 || i == 5)) {
for (j = 2; j < CUBE_ROW_COUNT-2; j++)
for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
} else if ((layer == 3 || layer == 4)&&(i == 3 || i == 4)) {
for (j = 3; j < CUBE_ROW_COUNT-3; j++)
for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
}
 
if ((layer == 0 || layer == 4)&&(i > 0 && i < 8)) {
for (j = 0; j < 8; j++) {
Cube_Set_Pixel(i,j,0,R,G,B);
Cube_Set_Pixel(i,j,7,R,G,B);
Cube_Set_Pixel(i,0,j,R,G,B);
Cube_Set_Pixel(i,7,j,R,G,B);
}
}
if ((layer == 1 || layer == 4)&&(i > 1 && i < 7)) {
for (j = 1; j < 7; j++) {
Cube_Set_Pixel(i,j,1,R,G,B);
Cube_Set_Pixel(i,j,6,R,G,B);
Cube_Set_Pixel(i,1,j,R,G,B);
Cube_Set_Pixel(i,6,j,R,G,B);
}
}
if ((layer == 2 || layer == 4)&&(i > 2 && i < 6)) {
for (j = 2; j < 6; j++) {
Cube_Set_Pixel(i,j,2,R,G,B);
Cube_Set_Pixel(i,j,5,R,G,B);
Cube_Set_Pixel(i,2,j,R,G,B);
Cube_Set_Pixel(i,5,j,R,G,B);
}
}
}
}
 
void Cube_Rotate_Shell(uint8_t shell, uint8_t direction) {
// Shell is the layer to rotate, with the outermost being 0
uint8_t layer;
uint16_t origin_R, origin_G, origin_B;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
if (direction) {
switch(shell) {
case 0:
// Rotate outermost layer
Cube_Get_Pixel(layer, 0, 0, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 0, 1, layer, 0, 0);
Cube_Move_Pixel(layer, 0, 2, layer, 0, 1);
Cube_Move_Pixel(layer, 0, 3, layer, 0, 2);
Cube_Move_Pixel(layer, 0, 4, layer, 0, 3);
Cube_Move_Pixel(layer, 0, 5, layer, 0, 4);
Cube_Move_Pixel(layer, 0, 6, layer, 0, 5);
Cube_Move_Pixel(layer, 0, 7, layer, 0, 6);
Cube_Move_Pixel(layer, 1, 7, layer, 0, 7);
Cube_Move_Pixel(layer, 2, 7, layer, 1, 7);
Cube_Move_Pixel(layer, 3, 7, layer, 2, 7);
Cube_Move_Pixel(layer, 4, 7, layer, 3, 7);
Cube_Move_Pixel(layer, 5, 7, layer, 4, 7);
Cube_Move_Pixel(layer, 6, 7, layer, 5, 7);
Cube_Move_Pixel(layer, 7, 7, layer, 6, 7);
Cube_Move_Pixel(layer, 7, 6, layer, 7, 7);
Cube_Move_Pixel(layer, 7, 5, layer, 7, 6);
Cube_Move_Pixel(layer, 7, 4, layer, 7, 5);
Cube_Move_Pixel(layer, 7, 3, layer, 7, 4);
Cube_Move_Pixel(layer, 7, 2, layer, 7, 3);
Cube_Move_Pixel(layer, 7, 1, layer, 7, 2);
Cube_Move_Pixel(layer, 7, 0, layer, 7, 1);
Cube_Move_Pixel(layer, 6, 0, layer, 7, 0);
Cube_Move_Pixel(layer, 5, 0, layer, 6, 0);
Cube_Move_Pixel(layer, 4, 0, layer, 5, 0);
Cube_Move_Pixel(layer, 3, 0, layer, 4, 0);
Cube_Move_Pixel(layer, 2, 0, layer, 3, 0);
Cube_Move_Pixel(layer, 1, 0, layer, 2, 0);
Cube_Set_Pixel(layer, 1, 0, origin_R, origin_G, origin_B);
break;
case 1:
// Rotate second to outermost layer
Cube_Get_Pixel(layer, 1, 1, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 1, 2, layer, 1, 1);
Cube_Move_Pixel(layer, 1, 3, layer, 1, 2);
Cube_Move_Pixel(layer, 1, 4, layer, 1, 3);
Cube_Move_Pixel(layer, 1, 5, layer, 1, 4);
Cube_Move_Pixel(layer, 1, 6, layer, 1, 5);
Cube_Move_Pixel(layer, 2, 6, layer, 1, 6);
Cube_Move_Pixel(layer, 3, 6, layer, 2, 6);
Cube_Move_Pixel(layer, 4, 6, layer, 3, 6);
Cube_Move_Pixel(layer, 5, 6, layer, 4, 6);
Cube_Move_Pixel(layer, 6, 6, layer, 5, 6);
Cube_Move_Pixel(layer, 6, 5, layer, 6, 6);
Cube_Move_Pixel(layer, 6, 4, layer, 6, 5);
Cube_Move_Pixel(layer, 6, 3, layer, 6, 4);
Cube_Move_Pixel(layer, 6, 2, layer, 6, 3);
Cube_Move_Pixel(layer, 6, 1, layer, 6, 2);
Cube_Move_Pixel(layer, 5, 1, layer, 6, 1);
Cube_Move_Pixel(layer, 4, 1, layer, 5, 1);
Cube_Move_Pixel(layer, 3, 1, layer, 4, 1);
Cube_Move_Pixel(layer, 2, 1, layer, 3, 1);
Cube_Set_Pixel(layer, 2, 1, origin_R, origin_G, origin_B);
break;
case 2:
// Rotate second to innermost layer
Cube_Get_Pixel(layer, 2, 2, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 2, 3, layer, 2, 2);
Cube_Move_Pixel(layer, 2, 4, layer, 2, 3);
Cube_Move_Pixel(layer, 2, 5, layer, 2, 4);
Cube_Move_Pixel(layer, 3, 5, layer, 2, 5);
Cube_Move_Pixel(layer, 4, 5, layer, 3, 5);
Cube_Move_Pixel(layer, 5, 5, layer, 4, 5);
Cube_Move_Pixel(layer, 5, 4, layer, 5, 5);
Cube_Move_Pixel(layer, 5, 3, layer, 5, 4);
Cube_Move_Pixel(layer, 5, 2, layer, 5, 3);
Cube_Move_Pixel(layer, 4, 2, layer, 5, 2);
Cube_Move_Pixel(layer, 3, 2, layer, 4, 2);
Cube_Set_Pixel(layer, 3, 2, origin_R, origin_G, origin_B);
break;
case 3:
// Rotate innermost layer
Cube_Get_Pixel(layer, 3, 3, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 3, 4, layer, 3, 3);
Cube_Move_Pixel(layer, 4, 4, layer, 3, 4);
Cube_Move_Pixel(layer, 4, 3, layer, 4, 4);
Cube_Set_Pixel(layer, 4, 3, origin_R, origin_G, origin_B);
break;
}
} else {
switch(shell) {
case 0:
// Rotate outermost layer
Cube_Get_Pixel(layer, 0, 0, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 1, 0, layer, 0, 0);
Cube_Move_Pixel(layer, 2, 0, layer, 1, 0);
Cube_Move_Pixel(layer, 3, 0, layer, 2, 0);
Cube_Move_Pixel(layer, 4, 0, layer, 3, 0);
Cube_Move_Pixel(layer, 5, 0, layer, 4, 0);
Cube_Move_Pixel(layer, 6, 0, layer, 5, 0);
Cube_Move_Pixel(layer, 7, 0, layer, 6, 0);
Cube_Move_Pixel(layer, 7, 1, layer, 7, 0);
Cube_Move_Pixel(layer, 7, 2, layer, 7, 1);
Cube_Move_Pixel(layer, 7, 3, layer, 7, 2);
Cube_Move_Pixel(layer, 7, 4, layer, 7, 3);
Cube_Move_Pixel(layer, 7, 5, layer, 7, 4);
Cube_Move_Pixel(layer, 7, 6, layer, 7, 5);
Cube_Move_Pixel(layer, 7, 7, layer, 7, 6);
Cube_Move_Pixel(layer, 6, 7, layer, 7, 7);
Cube_Move_Pixel(layer, 5, 7, layer, 6, 7);
Cube_Move_Pixel(layer, 4, 7, layer, 5, 7);
Cube_Move_Pixel(layer, 3, 7, layer, 4, 7);
Cube_Move_Pixel(layer, 2, 7, layer, 3, 7);
Cube_Move_Pixel(layer, 1, 7, layer, 2, 7);
Cube_Move_Pixel(layer, 0, 7, layer, 1, 7);
Cube_Move_Pixel(layer, 0, 6, layer, 0, 7);
Cube_Move_Pixel(layer, 0, 5, layer, 0, 6);
Cube_Move_Pixel(layer, 0, 4, layer, 0, 5);
Cube_Move_Pixel(layer, 0, 3, layer, 0, 4);
Cube_Move_Pixel(layer, 0, 2, layer, 0, 3);
Cube_Move_Pixel(layer, 0, 1, layer, 0, 2);
Cube_Set_Pixel(layer, 0, 1, origin_R, origin_G, origin_B);
break;
case 1:
// Rotate second to outermost layer
Cube_Get_Pixel(layer, 1, 1, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 2, 1, layer, 1, 1);
Cube_Move_Pixel(layer, 3, 1, layer, 2, 1);
Cube_Move_Pixel(layer, 4, 1, layer, 3, 1);
Cube_Move_Pixel(layer, 5, 1, layer, 4, 1);
Cube_Move_Pixel(layer, 6, 1, layer, 5, 1);
Cube_Move_Pixel(layer, 6, 2, layer, 6, 1);
Cube_Move_Pixel(layer, 6, 3, layer, 6, 2);
Cube_Move_Pixel(layer, 6, 4, layer, 6, 3);
Cube_Move_Pixel(layer, 6, 5, layer, 6, 4);
Cube_Move_Pixel(layer, 6, 6, layer, 6, 5);
Cube_Move_Pixel(layer, 5, 6, layer, 6, 6);
Cube_Move_Pixel(layer, 4, 6, layer, 5, 6);
Cube_Move_Pixel(layer, 3, 6, layer, 4, 6);
Cube_Move_Pixel(layer, 2, 6, layer, 3, 6);
Cube_Move_Pixel(layer, 1, 6, layer, 2, 6);
Cube_Move_Pixel(layer, 1, 5, layer, 1, 6);
Cube_Move_Pixel(layer, 1, 4, layer, 1, 5);
Cube_Move_Pixel(layer, 1, 3, layer, 1, 4);
Cube_Move_Pixel(layer, 1, 2, layer, 1, 3);
Cube_Set_Pixel(layer, 1, 2, origin_R, origin_G, origin_B);
break;
case 2:
// Rotate second to innermost layer
Cube_Get_Pixel(layer, 2, 2, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 3, 2, layer, 2, 2);
Cube_Move_Pixel(layer, 4, 2, layer, 3, 2);
Cube_Move_Pixel(layer, 5, 2, layer, 4, 2);
Cube_Move_Pixel(layer, 5, 3, layer, 5, 2);
Cube_Move_Pixel(layer, 5, 4, layer, 5, 3);
Cube_Move_Pixel(layer, 5, 5, layer, 5, 4);
Cube_Move_Pixel(layer, 4, 5, layer, 5, 5);
Cube_Move_Pixel(layer, 3, 5, layer, 4, 5);
Cube_Move_Pixel(layer, 2, 5, layer, 3, 5);
Cube_Move_Pixel(layer, 2, 4, layer, 2, 5);
Cube_Move_Pixel(layer, 2, 3, layer, 2, 4);
Cube_Set_Pixel(layer, 2, 3, origin_R, origin_G, origin_B);
break;
case 3:
// Rotate innermost layer
Cube_Get_Pixel(layer, 3, 3, &origin_R, &origin_G, &origin_B);
Cube_Move_Pixel(layer, 4, 3, layer, 3, 3);
Cube_Move_Pixel(layer, 4, 4, layer, 4, 3);
Cube_Move_Pixel(layer, 3, 4, layer, 4, 4);
Cube_Set_Pixel(layer, 3, 4, origin_R, origin_G, origin_B);
break;
}
}
}
}
 
void Cube_Rotate(uint8_t direction) {
// Rotate outermost layer
Cube_Rotate_Shell(0, direction);
// Rotate second to outermost layer
if ((cube_data_ptr->rotation_counter != 1) && (cube_data_ptr->rotation_counter != 5)) {
Cube_Rotate_Shell(1, direction);
}
// Rotate second to innermost layer
if ((cube_data_ptr->rotation_counter != 0) && (cube_data_ptr->rotation_counter != 2) &&
(cube_data_ptr->rotation_counter != 4) && (cube_data_ptr->rotation_counter != 6)) {
Cube_Rotate_Shell(2, direction);
}
// Rotate innermost layer
if ((cube_data_ptr->rotation_counter == 3) || (cube_data_ptr->rotation_counter == 7)) {
Cube_Rotate_Shell(3, direction);
}
 
if (direction == 0) {
cube_data_ptr->rotation_counter = (cube_data_ptr->rotation_counter == CUBE_ROTATIONS - 1)
? 0 : cube_data_ptr->rotation_counter + 1;
} else {
cube_data_ptr->rotation_counter = (cube_data_ptr->rotation_counter == 0)
? CUBE_ROTATIONS - 1 : cube_data_ptr->rotation_counter - 1;
}
}
 
void Cube_Shift_Row(uint8_t direction) {
// Shifts the display by an entire row
int i, j, k;
if (direction) {
// Shift values in each row by one
for (i = CUBE_ROW_COUNT - 1; i >= 0; i--) { // Row
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_LAYER_COUNT; k++) {
Cube_Move_Pixel(k, i - 1, j, k, i, j);
}
}
}
} else {
for (i = 0; i < CUBE_ROW_COUNT - 1; i++) {
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_LAYER_COUNT; k++) {
Cube_Move_Pixel(k, i + 1, j, k, i, j);
}
}
}
}
}
 
void Cube_Shift_Waterfall(uint8_t *values) {
// Takes an array of 8 values and sets them to the column height
// Each column is set to a manually specified color
uint8_t i, j;
uint8_t update_row = CUBE_ROW_COUNT - 1;
 
// First shift the rows
Cube_Shift_Row(0);
 
// Then update the empty row
for (i = 0; i < CUBE_COLUMN_COUNT; i++) {
for (j = 0; j < CUBE_LAYER_COUNT; j++) {
if (j < values[i] % 9) {
// Specify the color for each column
if (i == 0)
Cube_Set_Pixel(j, update_row, i, RED);
else if (i == 1)
Cube_Set_Pixel(j, update_row, i, ORANGE);
else if (i == 2)
Cube_Set_Pixel(j, update_row, i, YELLOW);
else if (i == 3)
Cube_Set_Pixel(j, update_row, i, GREEN);
else if (i == 4)
Cube_Set_Pixel(j, update_row, i, TEAL);
else if (i == 5)
Cube_Set_Pixel(j, update_row, i, BLUE);
else if (i == 6)
Cube_Set_Pixel(j, update_row, i, PURPLE);
else
Cube_Set_Pixel(j, update_row, i, WHITE);
} else {
Cube_Set_Pixel(j, update_row, i, CLEAR);
}
}
}
}
 
void Cube_Shift_Waterfall2(uint8_t *values) {
// Takes an array of 8 values and sets them to the column height
// Each layer is set to a manually specified color
uint8_t i, j;
uint8_t update_row = CUBE_ROW_COUNT - 1;
 
// First shift the rows
Cube_Shift_Row(0);
 
// Then update the empty row
for (i = 0; i < CUBE_COLUMN_COUNT; i++) {
for (j = 0; j < CUBE_LAYER_COUNT; j++) {
if (j < values[i] % 9) {
// Specify the color for each layer
if (j == 7)
Cube_Set_Pixel(j, update_row, i, RED);
else if (j == 6)
Cube_Set_Pixel(j, update_row, i, ORANGE);
else if (j == 5)
Cube_Set_Pixel(j, update_row, i, YELLOW);
else if (j == 4)
Cube_Set_Pixel(j, update_row, i, GREEN);
else if (j == 3)
Cube_Set_Pixel(j, update_row, i, TEAL);
else if (j == 2)
Cube_Set_Pixel(j, update_row, i, BLUE);
else if (j == 1)
Cube_Set_Pixel(j, update_row, i, PURPLE);
else
Cube_Set_Pixel(j, update_row, i, WHITE);
} else {
Cube_Set_Pixel(j, update_row, i, CLEAR);
}
}
}
}
 
///////////////////////////////
// Overlay control functions //
///////////////////////////////
 
void Cube_Overlay_Clear(void) {
uint16_t i,j;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < GCS_LAYER_SIZE; j++) {
cube_data_ptr->GCS_OVERLAY[i][j] = 0x00;
}
}
}
 
void Cube_Overlay_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified pixel to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS_OVERLAY[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS_OVERLAY[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS_OVERLAY[layer][var+2] = G >> 4;
cube_data_ptr->GCS_OVERLAY[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS_OVERLAY[layer][var+4] = (cube_data_ptr->GCS_OVERLAY[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS_OVERLAY[layer][var+4] = (cube_data_ptr->GCS_OVERLAY[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS_OVERLAY[layer][var+5] = R >> 4;
cube_data_ptr->GCS_OVERLAY[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS_OVERLAY[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS_OVERLAY[layer][var+8] = B >> 4;
break;
}
}
 
void Cube_Overlay_Get_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t* R, uint16_t* G, uint16_t* B) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
// Concatenate lower byte and upper byte of each color channel
case 0:
*R = cube_data_ptr->GCS_OVERLAY[layer][var+0] | ((cube_data_ptr->GCS_OVERLAY[layer][var+1] & 0x0F) << 8);
*G = (cube_data_ptr->GCS_OVERLAY[layer][var+1] >> 4) | (cube_data_ptr->GCS_OVERLAY[layer][var+2] << 4);
*B = cube_data_ptr->GCS_OVERLAY[layer][var+3] | ((cube_data_ptr->GCS_OVERLAY[layer][var+4] & 0x0F) << 8);
break;
case 1:
*R = (cube_data_ptr->GCS_OVERLAY[layer][var+4] >> 4) | (cube_data_ptr->GCS_OVERLAY[layer][var+5] << 4);
*G = cube_data_ptr->GCS_OVERLAY[layer][var+6] | ((cube_data_ptr->GCS_OVERLAY[layer][var+7] & 0x0F) << 8);
*B = (cube_data_ptr->GCS_OVERLAY[layer][var+7] >> 4) | (cube_data_ptr->GCS_OVERLAY[layer][var+8] << 4);
break;
}
}
 
void Cube_Overlay_Move_Pixel(uint8_t layer1, uint8_t row1, uint8_t column1, uint8_t layer2, uint8_t row2, uint8_t column2) {
// Copies data from pixel 1 to pixel 2
// Note: destination pixel value is overwritten
uint16_t prev_R, prev_G, prev_B;
Cube_Overlay_Get_Pixel(layer1, row1, column1, &prev_R, &prev_G, &prev_B);
Cube_Overlay_Set_Pixel(layer2, row2, column2, prev_R, prev_G, prev_B);
}
 
void Cube_Overlay_Rotate_Shell(uint8_t shell, uint8_t direction) {
// Shell is the layer to rotate, with the outermost being 0
uint8_t layer;
uint16_t origin_R, origin_G, origin_B;;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
if (direction) {
switch(shell) {
case 0:
// Rotate outermost layer
Cube_Overlay_Get_Pixel(layer, 0, 0, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 0, 1, layer, 0, 0);
Cube_Overlay_Move_Pixel(layer, 0, 2, layer, 0, 1);
Cube_Overlay_Move_Pixel(layer, 0, 3, layer, 0, 2);
Cube_Overlay_Move_Pixel(layer, 0, 4, layer, 0, 3);
Cube_Overlay_Move_Pixel(layer, 0, 5, layer, 0, 4);
Cube_Overlay_Move_Pixel(layer, 0, 6, layer, 0, 5);
Cube_Overlay_Move_Pixel(layer, 0, 7, layer, 0, 6);
Cube_Overlay_Move_Pixel(layer, 1, 7, layer, 0, 7);
Cube_Overlay_Move_Pixel(layer, 2, 7, layer, 1, 7);
Cube_Overlay_Move_Pixel(layer, 3, 7, layer, 2, 7);
Cube_Overlay_Move_Pixel(layer, 4, 7, layer, 3, 7);
Cube_Overlay_Move_Pixel(layer, 5, 7, layer, 4, 7);
Cube_Overlay_Move_Pixel(layer, 6, 7, layer, 5, 7);
Cube_Overlay_Move_Pixel(layer, 7, 7, layer, 6, 7);
Cube_Overlay_Move_Pixel(layer, 7, 6, layer, 7, 7);
Cube_Overlay_Move_Pixel(layer, 7, 5, layer, 7, 6);
Cube_Overlay_Move_Pixel(layer, 7, 4, layer, 7, 5);
Cube_Overlay_Move_Pixel(layer, 7, 3, layer, 7, 4);
Cube_Overlay_Move_Pixel(layer, 7, 2, layer, 7, 3);
Cube_Overlay_Move_Pixel(layer, 7, 1, layer, 7, 2);
Cube_Overlay_Move_Pixel(layer, 7, 0, layer, 7, 1);
Cube_Overlay_Move_Pixel(layer, 6, 0, layer, 7, 0);
Cube_Overlay_Move_Pixel(layer, 5, 0, layer, 6, 0);
Cube_Overlay_Move_Pixel(layer, 4, 0, layer, 5, 0);
Cube_Overlay_Move_Pixel(layer, 3, 0, layer, 4, 0);
Cube_Overlay_Move_Pixel(layer, 2, 0, layer, 3, 0);
Cube_Overlay_Move_Pixel(layer, 1, 0, layer, 2, 0);
Cube_Overlay_Set_Pixel(layer, 1, 0, origin_R, origin_G, origin_B);
break;
case 1:
// Rotate second to outermost layer
Cube_Overlay_Get_Pixel(layer, 1, 1, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 1, 2, layer, 1, 1);
Cube_Overlay_Move_Pixel(layer, 1, 3, layer, 1, 2);
Cube_Overlay_Move_Pixel(layer, 1, 4, layer, 1, 3);
Cube_Overlay_Move_Pixel(layer, 1, 5, layer, 1, 4);
Cube_Overlay_Move_Pixel(layer, 1, 6, layer, 1, 5);
Cube_Overlay_Move_Pixel(layer, 2, 6, layer, 1, 6);
Cube_Overlay_Move_Pixel(layer, 3, 6, layer, 2, 6);
Cube_Overlay_Move_Pixel(layer, 4, 6, layer, 3, 6);
Cube_Overlay_Move_Pixel(layer, 5, 6, layer, 4, 6);
Cube_Overlay_Move_Pixel(layer, 6, 6, layer, 5, 6);
Cube_Overlay_Move_Pixel(layer, 6, 5, layer, 6, 6);
Cube_Overlay_Move_Pixel(layer, 6, 4, layer, 6, 5);
Cube_Overlay_Move_Pixel(layer, 6, 3, layer, 6, 4);
Cube_Overlay_Move_Pixel(layer, 6, 2, layer, 6, 3);
Cube_Overlay_Move_Pixel(layer, 6, 1, layer, 6, 2);
Cube_Overlay_Move_Pixel(layer, 5, 1, layer, 6, 1);
Cube_Overlay_Move_Pixel(layer, 4, 1, layer, 5, 1);
Cube_Overlay_Move_Pixel(layer, 3, 1, layer, 4, 1);
Cube_Overlay_Move_Pixel(layer, 2, 1, layer, 3, 1);
Cube_Overlay_Set_Pixel(layer, 2, 1, origin_R, origin_G, origin_B);
break;
case 2:
// Rotate second to innermost layer
Cube_Overlay_Get_Pixel(layer, 2, 2, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 2, 3, layer, 2, 2);
Cube_Overlay_Move_Pixel(layer, 2, 4, layer, 2, 3);
Cube_Overlay_Move_Pixel(layer, 2, 5, layer, 2, 4);
Cube_Overlay_Move_Pixel(layer, 3, 5, layer, 2, 5);
Cube_Overlay_Move_Pixel(layer, 4, 5, layer, 3, 5);
Cube_Overlay_Move_Pixel(layer, 5, 5, layer, 4, 5);
Cube_Overlay_Move_Pixel(layer, 5, 4, layer, 5, 5);
Cube_Overlay_Move_Pixel(layer, 5, 3, layer, 5, 4);
Cube_Overlay_Move_Pixel(layer, 5, 2, layer, 5, 3);
Cube_Overlay_Move_Pixel(layer, 4, 2, layer, 5, 2);
Cube_Overlay_Move_Pixel(layer, 3, 2, layer, 4, 2);
Cube_Overlay_Set_Pixel(layer, 3, 2, origin_R, origin_G, origin_B);
break;
case 3:
// Rotate innermost layer
Cube_Overlay_Get_Pixel(layer, 3, 3, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 3, 4, layer, 3, 3);
Cube_Overlay_Move_Pixel(layer, 4, 4, layer, 3, 4);
Cube_Overlay_Move_Pixel(layer, 4, 3, layer, 4, 4);
Cube_Overlay_Set_Pixel(layer, 4, 3, origin_R, origin_G, origin_B);
break;
}
} else {
switch(shell) {
case 0:
// Rotate outermost layer
Cube_Overlay_Get_Pixel(layer, 0, 0, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 1, 0, layer, 0, 0);
Cube_Overlay_Move_Pixel(layer, 2, 0, layer, 1, 0);
Cube_Overlay_Move_Pixel(layer, 3, 0, layer, 2, 0);
Cube_Overlay_Move_Pixel(layer, 4, 0, layer, 3, 0);
Cube_Overlay_Move_Pixel(layer, 5, 0, layer, 4, 0);
Cube_Overlay_Move_Pixel(layer, 6, 0, layer, 5, 0);
Cube_Overlay_Move_Pixel(layer, 7, 0, layer, 6, 0);
Cube_Overlay_Move_Pixel(layer, 7, 1, layer, 7, 0);
Cube_Overlay_Move_Pixel(layer, 7, 2, layer, 7, 1);
Cube_Overlay_Move_Pixel(layer, 7, 3, layer, 7, 2);
Cube_Overlay_Move_Pixel(layer, 7, 4, layer, 7, 3);
Cube_Overlay_Move_Pixel(layer, 7, 5, layer, 7, 4);
Cube_Overlay_Move_Pixel(layer, 7, 6, layer, 7, 5);
Cube_Overlay_Move_Pixel(layer, 7, 7, layer, 7, 6);
Cube_Overlay_Move_Pixel(layer, 6, 7, layer, 7, 7);
Cube_Overlay_Move_Pixel(layer, 5, 7, layer, 6, 7);
Cube_Overlay_Move_Pixel(layer, 4, 7, layer, 5, 7);
Cube_Overlay_Move_Pixel(layer, 3, 7, layer, 4, 7);
Cube_Overlay_Move_Pixel(layer, 2, 7, layer, 3, 7);
Cube_Overlay_Move_Pixel(layer, 1, 7, layer, 2, 7);
Cube_Overlay_Move_Pixel(layer, 0, 7, layer, 1, 7);
Cube_Overlay_Move_Pixel(layer, 0, 6, layer, 0, 7);
Cube_Overlay_Move_Pixel(layer, 0, 5, layer, 0, 6);
Cube_Overlay_Move_Pixel(layer, 0, 4, layer, 0, 5);
Cube_Overlay_Move_Pixel(layer, 0, 3, layer, 0, 4);
Cube_Overlay_Move_Pixel(layer, 0, 2, layer, 0, 3);
Cube_Overlay_Move_Pixel(layer, 0, 1, layer, 0, 2);
Cube_Overlay_Set_Pixel(layer, 0, 1, origin_R, origin_G, origin_B);
break;
case 1:
// Rotate second to outermost layer
Cube_Overlay_Get_Pixel(layer, 1, 1, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 2, 1, layer, 1, 1);
Cube_Overlay_Move_Pixel(layer, 3, 1, layer, 2, 1);
Cube_Overlay_Move_Pixel(layer, 4, 1, layer, 3, 1);
Cube_Overlay_Move_Pixel(layer, 5, 1, layer, 4, 1);
Cube_Overlay_Move_Pixel(layer, 6, 1, layer, 5, 1);
Cube_Overlay_Move_Pixel(layer, 6, 2, layer, 6, 1);
Cube_Overlay_Move_Pixel(layer, 6, 3, layer, 6, 2);
Cube_Overlay_Move_Pixel(layer, 6, 4, layer, 6, 3);
Cube_Overlay_Move_Pixel(layer, 6, 5, layer, 6, 4);
Cube_Overlay_Move_Pixel(layer, 6, 6, layer, 6, 5);
Cube_Overlay_Move_Pixel(layer, 5, 6, layer, 6, 6);
Cube_Overlay_Move_Pixel(layer, 4, 6, layer, 5, 6);
Cube_Overlay_Move_Pixel(layer, 3, 6, layer, 4, 6);
Cube_Overlay_Move_Pixel(layer, 2, 6, layer, 3, 6);
Cube_Overlay_Move_Pixel(layer, 1, 6, layer, 2, 6);
Cube_Overlay_Move_Pixel(layer, 1, 5, layer, 1, 6);
Cube_Overlay_Move_Pixel(layer, 1, 4, layer, 1, 5);
Cube_Overlay_Move_Pixel(layer, 1, 3, layer, 1, 4);
Cube_Overlay_Move_Pixel(layer, 1, 2, layer, 1, 3);
Cube_Overlay_Set_Pixel(layer, 1, 2, origin_R, origin_G, origin_B);
break;
case 2:
// Rotate second to innermost layer
Cube_Overlay_Get_Pixel(layer, 2, 2, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 3, 2, layer, 2, 2);
Cube_Overlay_Move_Pixel(layer, 4, 2, layer, 3, 2);
Cube_Overlay_Move_Pixel(layer, 5, 2, layer, 4, 2);
Cube_Overlay_Move_Pixel(layer, 5, 3, layer, 5, 2);
Cube_Overlay_Move_Pixel(layer, 5, 4, layer, 5, 3);
Cube_Overlay_Move_Pixel(layer, 5, 5, layer, 5, 4);
Cube_Overlay_Move_Pixel(layer, 4, 5, layer, 5, 5);
Cube_Overlay_Move_Pixel(layer, 3, 5, layer, 4, 5);
Cube_Overlay_Move_Pixel(layer, 2, 5, layer, 3, 5);
Cube_Overlay_Move_Pixel(layer, 2, 4, layer, 2, 5);
Cube_Overlay_Move_Pixel(layer, 2, 3, layer, 2, 4);
Cube_Overlay_Set_Pixel(layer, 2, 3, origin_R, origin_G, origin_B);
break;
case 3:
// Rotate innermost layer
Cube_Overlay_Get_Pixel(layer, 3, 3, &origin_R, &origin_G, &origin_B);
Cube_Overlay_Move_Pixel(layer, 4, 3, layer, 3, 3);
Cube_Overlay_Move_Pixel(layer, 4, 4, layer, 4, 3);
Cube_Overlay_Move_Pixel(layer, 3, 4, layer, 4, 4);
Cube_Overlay_Set_Pixel(layer, 3, 4, origin_R, origin_G, origin_B);
break;
}
}
}
}
 
////////////////////////////
// Text control functions //
////////////////////////////
 
void Cube_Text_Init(uint8_t *string, uint8_t length, uint16_t R, uint16_t G, uint16_t B) {
// Ensure that the length of the string does not exceed the storage buffer
if (length > CUBE_STRING_MAX_LENGTH) length = CUBE_STRING_MAX_LENGTH;
 
Cube_Overlay_Clear();
 
// Copy the passed data into the buffer
uint8_t i;
for (i = 0; i < length; i++)
cube_data_ptr->string[i] = string[i];
cube_data_ptr->string_length = length;
cube_data_ptr->string_index = 0;
cube_data_ptr->string_line = 0;
cube_data_ptr->string_R = R;
cube_data_ptr->string_G = G;
cube_data_ptr->string_B = B;
}
 
void Cube_Text_Update(void) {
uint8_t layer;
uint16_t line;
 
// Rotate before drawing the new line at (0,0)
Cube_Overlay_Rotate_Shell(0, 0);
 
// Get the next vertical line of the character currently being drawn
if (cube_data_ptr->string_line == 5) {
line = 0x0; // Leave a space between characters
} else {
line = font[(cube_data_ptr->string[cube_data_ptr->string_index] * 5)
+ cube_data_ptr->string_line];
}
 
// Draw the line onto (0,0) using the specified color
for (layer = 8; layer != 0; layer--) {
if (line & 0x1) {
Cube_Overlay_Set_Pixel(layer-1, 0, 0, cube_data_ptr->string_R,
cube_data_ptr->string_G, cube_data_ptr->string_B);
} else {
Cube_Overlay_Set_Pixel(layer-1, 0, 0, 0x00, 0x00, 0x00);
}
line >>= 1;
}
 
// Increment the vertical line and the character as needed
if (cube_data_ptr->string_line == 5) {
cube_data_ptr->string_line = 0;
if (cube_data_ptr->string_index == cube_data_ptr->string_length-1) {
cube_data_ptr->string_index = 0;
} else {
cube_data_ptr->string_index += 1;
}
} else {
cube_data_ptr->string_line += 1;
}
}
 
void Cube_Text_Insert(uint8_t c, uint16_t R, uint16_t G, uint16_t B, uint16_t delay) {
// Save the character to insert
cube_data_ptr->string[0] = c;
cube_data_ptr->string_length = 1;
cube_data_ptr->string_line = 0;
cube_data_ptr->string_R = R;
cube_data_ptr->string_G = G;
cube_data_ptr->string_B = B;
 
if (delay == 0) {
int i;
for (i = 0; i < 6; i++) {
Cube_Text_Single_Char_Interupt();
}
} else {
// Start a timer to update the overlay with the inserted character
TIMER4_Stop();
TIMER4_Init(NULL, NULL, &Cube_Text_Single_Char_Interupt, delay);
TIMER4_Start();
}
}
 
void Cube_Text_Single_Char_Interupt(void) {
uint8_t layer;
uint8_t line;
 
// Rotate before drawing the new line at (0,0)
Cube_Overlay_Rotate_Shell(0, 0);
 
// Get the next vertical line of the character currently being drawn
if (cube_data_ptr->string_line == 0) {
line = 0x0; // Leave a space between characters
} else {
line = font[(cube_data_ptr->string[0] * 5) + cube_data_ptr->string_line - 1];
}
 
// Draw the line onto (0,0) using the specified color
for (layer = 8; layer != 0; layer--) {
if (line & 0x1) {
Cube_Overlay_Set_Pixel(layer-1, 0, 0, cube_data_ptr->string_R,
cube_data_ptr->string_G, cube_data_ptr->string_B);
} else {
Cube_Overlay_Set_Pixel(layer-1, 0, 0, 0x00, 0x00, 0x00);
}
line >>= 1;
}
 
// Increment the vertical line or stop the timer as needed
if (cube_data_ptr->string_line == 5) {
TIMER4_Stop();
} else {
cube_data_ptr->string_line += 1;
}
}
 
void Cube_Text_Interrupt(void) {
Cube_Text_Update();
}
 
/////////////////////////////////////////////
// Functions for processing streaming data //
/////////////////////////////////////////////
 
void Cube_Data_In(uint8_t c) {
// Reset upon receiving the start int8_t
if (c == CUBE_START_CHAR) {
cube_data_ptr->frame_length = 0;
cube_data_ptr->frame_index = 0;
cube_data_ptr->frame_checksum = 0;
cube_data_ptr->frame_command = 0;
cube_data_ptr->frame_escape = 0;
cube_data_ptr->frame_state = READ_LENGTH_MSB;
return;
}
// If the input is the escape int8_t, XOR the next int8_t received
if (c == CUBE_ESCAPE_CHAR) {
cube_data_ptr->frame_escape = 1;
return;
}
// XOR the input int8_t if needed
if (cube_data_ptr->frame_escape) {
c ^= CUBE_ESCAPE_XOR;
cube_data_ptr->frame_escape = 0;
}
// Process data
switch (cube_data_ptr->frame_state) {
case IDLE:
// Reflect the character back to the transmitter
UART1_Write(&c, 1);
break;
case READ_LENGTH_MSB: // Save MSB of length
cube_data_ptr->frame_length |= (c << 8);
cube_data_ptr->frame_state = READ_LENGTH_LSB;
break;
case READ_LENGTH_LSB: // Save LSB of length
cube_data_ptr->frame_length |= c;
cube_data_ptr->frame_state = READ_COMMAND;
break;
case READ_COMMAND: // Store the command byte
cube_data_ptr->frame_checksum += c;
cube_data_ptr->frame_command = c;
if (cube_data_ptr->frame_length == 1)
cube_data_ptr->frame_state = READ_CHECKSUM;
else
cube_data_ptr->frame_state = READ_DATA;
break;
case READ_DATA: // Read the passed data into the buffer
cube_data_ptr->frame_checksum += c;
cube_data_ptr->frame_buffer[cube_data_ptr->frame_index] = c;
cube_data_ptr->frame_index++;
if (cube_data_ptr->frame_index == cube_data_ptr->frame_length - 1)
cube_data_ptr->frame_state = READ_CHECKSUM;
break;
case READ_CHECKSUM: // Process frame if checksum is valid
cube_data_ptr->frame_checksum = 0xFF - cube_data_ptr->frame_checksum;
if (cube_data_ptr->frame_checksum == c) {
Cube_Data_In_Process_Frame();
}
cube_data_ptr->frame_state = IDLE;
cube_data_ptr->frame_index = 0;
cube_data_ptr->frame_length = 0;
break;
default:
break;
}
}
 
void Cube_Data_In_Process_Frame(void) {
// Here we process received frames depending on the command
uint8_t *frame = cube_data_ptr->frame_buffer;
switch (cube_data_ptr->frame_command) {
case CUBE_COMMAND_SET_BC:
TIMER5_Stop();
Delay_MS(1); // Need to wait for all SPI writes to complete
Cube_Write_DCS(frame[0]);
TIMER5_Start();
break;
case CUBE_COMMAND_CLEAR:
Cube_Clear();
break;
case CUBE_COMMAND_SET_PIXEL:
Cube_Set_Pixel(frame[0], frame[1], frame[2], frame[3], frame[4], frame[5]);
break;
case CUBE_COMMAND_SET_ALL:
Cube_Data_Direct_Write_All(&frame[0]);
break;
case CUBE_COMMAND_START_TEXT:
Cube_Text_Init(&frame[3], cube_data_ptr->frame_length - 4, frame[0], frame[1], frame[2]);
TIMER4_Start();
break;
case CUBE_COMMAND_STOP_TEXT:
TIMER4_Stop();
Cube_Overlay_Clear();
break;
default:
break;
}
}
 
void Cube_Data_Direct_Write_All(uint8_t *buffer) {
memcpy(cube_data_ptr->GCS, buffer, CUBE_LAYER_COUNT * GCS_LAYER_SIZE);
}
 
void Cube_Ethernet_Frame_In(void) {
uint8_t i,j,k;
uint8_t buffer[2048] = {0};
uint16_t length;
 
// Read and process the ethernet packet
if (!ETH_Read_Packet(buffer, &length)) {
// Check the opcode (first byte) to determine what to do
if (buffer[0] == CUBE_ETH_RESET) { // 0x1 - Reset into Ethernet mode
Reset_Board(BOARD_MODE_ETHERNET);
} else if (Get_Board_State() == BOARD_MODE_ETHERNET) {
ClearWDT();
if (buffer[0] == CUBE_EHT_IDLE) { // 0x2 - Reset back to idle mode
Reset_Board(BOARD_MODE_IDLE);
} else if (buffer[0] == CUBE_ETH_CLEAR) { // 0xA
Cube_Clear();
} else if (buffer[0] == CUBE_ETH_DCS) { // 0xB
// Byte 1 = global brightness value
Cube_Write_DCS(buffer[1]);
} else if (buffer[0] == CUBE_ETH_ROTATE) { // 0xC
// Byte 1 = directon to rotate
Cube_Rotate(buffer[1]);
} else if (buffer[0] == CUBE_ETH_ROTATE_LAYER) { // 0xD
// Byte 1 = layer to rotate
// Byte 2 = direction to rotate
Cube_Rotate_Shell(buffer[1], buffer[2]);
} else if (buffer[0] == CUBE_ETH_WRITE_ALL) { // 0x10
// Byte 1+ = pixel color data (R/G/B)
if (length == 0x0601) {
uint16_t index = 1;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_ROW_COUNT; k++) {
Cube_Set_Pixel(i, k, j, buffer[index], buffer[index+1], buffer[index+2]);
index = index + 3;
}
}
}
}
} else if (buffer[0] == CUBE_ETH_WRITE_PIXEL) { // 0x11
// Byte 1 = row index
// Byte 2 = column index
// Byte 3 = layer index
// Byte 4 = red channel
// Byte 5 = green channel
// Byte 6 = blue channel
Cube_Set_Pixel(buffer[3], buffer[1], buffer[2], buffer[4], buffer[5], buffer[6]);
} else if (buffer[0] == CUBE_ETH_WRITE_CHANNEL) { // 0x12
// Byte 1 = color channel, 0 = red, 1 = green, 2 = blue
// Byte 2+ = color data
uint16_t r, g, b;
uint16_t index = 2;
if (buffer[1] % 3 == 0) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
// Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, buffer[index], 0x00, 0x00);
index++;
}
}
}
} else if (buffer[1] % 3 == 1) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, r, buffer[index], b);
index++;
}
}
}
} else {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, r, g, buffer[index]);
index++;
}
}
}
}
} else if (buffer[0] == CUBE_ETH_WRITE_TEXT_SCROLL) { // 0x20
// Byte 1 = length of string
// Byte 2 = red channel
// Byte 3 = green channel
// Byte 4 = blue channel
// Byte 5 = update speed (ms)
// Byte 6+ = text string
if (buffer[1] != 0) {
TIMER4_Stop();
Cube_Text_Init(&buffer[6], buffer[1], buffer[2], buffer[3], buffer[4]);
TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, buffer[5]);
TIMER4_Start();
} else {
TIMER4_Stop();
Cube_Overlay_Clear();
}
} else if (buffer[0] == CUBE_ETH_WRITE_TEXT_STATIC) { // 0x21
// Byte 1 = length of string
// Byte 2 = red channel
// Byte 3 = green channel
// Byte 4 = blue channel
// Byte 5+ = text string
if (buffer[1] != 0) {
TIMER4_Stop();
Cube_Text_Init(&buffer[5], buffer[1], buffer[2], buffer[3], buffer[4]);
for (i = 0; i < buffer[1] * 5; i++) {
Cube_Text_Update();
}
} else {
TIMER4_Stop();
Cube_Overlay_Clear();
}
} else if (buffer[0] == CUBE_EHT_WRITE_TEXT_INSERT) { // 0x22
// Byte 1 = red channel
// Byte 2 = green channel
// Byte 3 = blue channel
// Byte 4 = delay x6 between shifts
// Byte 5 = character
TIMER4_Stop();
Cube_Text_Insert(buffer[5], buffer[1], buffer[2], buffer[3], buffer[4]);
} else if (buffer[0] == CUBE_ETH_WATERFALL) { // 0x30
// Byte 1 = height of column 0
// Byte 2 = height of column 1
// Byte 3 = height of column 2
// Byte 4 = height of column 3
// Byte 5 = height of column 4
// Byte 6 = height of column 5
// Byte 7 = height of column 6
// Byte 8 = height of column 7
Cube_Shift_Waterfall(&buffer[1]);
} else if (buffer[0] == CUBE_ETH_SPHERE) { // 0x31
// Byte 1 = layer (0 = innermost)
// Byte 2 = red channel
// Byte 3 = green channel
// Byte 4 = blue channel
Cube_Set_Sphere(buffer[1], buffer[2], buffer[3], buffer[4]);
}
}
}
}
/PIC Projects/Cerebot_32MX7_LED_Cube/ETHERNET.c
0,0 → 1,356
#include "defines.h"
#include "ETHERNET.h"
 
static ETH_DATA *eth_data;
 
/* Function to convert from virtual address to physical address
See 3.4.1 in reference manual for explanation */
uint32_t VA_TO_PA(uint32_t ptr) {
uint32_t ret = ptr & 0x1FFFFFFF;
return ret;
}
 
void ETH_Init(ETH_DATA *data, void(*tx_callback)(void), void(*rx_callback)(void)) {
// Save a pointer to the descriptor tables
eth_data = data;
eth_data->tx_callback = tx_callback;
eth_data->rx_callback = rx_callback;
 
// Bring the PHY reset line high to initialize the PHY
PHY_RESET_TRIS = 0;
PHY_RESET_LAT = 0;
Delay_US(100);
PHY_RESET_LAT = 1;
 
INTDisableInterrupts();
 
// Initialize the I/O lines (dont actually need this)
ETH_MDC_TRIS = 0;
ETH_MDIO_TRIS = 1;
ETH_TXEN_TRIS = 0;
ETH_TXD0_TRIS = 0;
ETH_TXD1_TRIS = 0;
ETH_RXCLK_TRIS = 1;
ETH_RXDV_TRIS = 1;
ETH_RXD0_TRIS = 1;
ETH_RXD1_TRIS = 1;
ETH_RXERR_TRIS = 1;
 
eth_data->TX_descriptor_index = 0;
eth_data->RX_descriptor_index = 0;
 
// Initialize values in the descriptor tables
uint8_t i;
for (i = 0; i < ETH_TX_DESCRIPTOR_COUNT; i++) {
// Set the NPV values for each descriptor (linear list)
eth_data->TX_ED_table.descriptor[i].NPV = 0;
// Set the EOWN values for each descriptor
eth_data->TX_ED_table.descriptor[i].EOWN = 0;
 
// Assign a data buffer to each descriptor
eth_data->TX_ED_table.descriptor[i].BUFFER_ADDR = VA_TO_PA((uint32_t)eth_data->TX_ED_buffer[i]);
}
for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
// Set the NPV values for each descriptor (linear list)
eth_data->RX_ED_table.descriptor[i].NPV = 0;
 
// Set the EOWN values for each descriptor
eth_data->RX_ED_table.descriptor[i].EOWN = 1;
 
// Assign a data buffer to each descriptor
eth_data->RX_ED_table.descriptor[i].BUFFER_ADDR = VA_TO_PA((uint32_t)eth_data->RX_ED_buffer[i]);
}
 
// On the last descriptor, save the address to the beginning of the list
eth_data->TX_ED_table.descriptor[ETH_TX_DESCRIPTOR_COUNT-1].NPV = 1;
eth_data->RX_ED_table.descriptor[ETH_RX_DESCRIPTOR_COUNT-1].NPV = 1;
 
// Set the last RX descriptor EOWN to software, thus using list configuration
// eth_data->TX_ED_table.descriptor[ETH_TX_DESCRIPTOR_COUNT-1].EOWN = 0;
// eth_data->RX_ED_table.descriptor[ETH_RX_DESCRIPTOR_COUNT-1].EOWN = 0;
 
// Loop the end of the descriptor table to the beginning (ring configuration)
eth_data->TX_ED_table.next_ED = VA_TO_PA((uint32_t)eth_data->TX_ED_table.descriptor);
eth_data->RX_ED_table.next_ED = VA_TO_PA((uint32_t)eth_data->RX_ED_table.descriptor);
 
// Save the head of the table to the corresponding ETH register
ETHTXST = VA_TO_PA((uint32_t)eth_data->TX_ED_table.descriptor);
ETHRXST = VA_TO_PA((uint32_t)eth_data->RX_ED_table.descriptor);
 
// Ethernet Initialization Sequence: see section 35.4.10 in the PIC32 Family Reference Manual
// Part 1. Ethernet Controller Initialization
IEC1bits.ETHIE = 0; // Disable ethernet interrupts
ETHCON1bits.ON = 0; // Disable the ethernet module
ETHCON1bits.TXRTS = 0; // Stop transmit logic
ETHCON1bits.RXEN = 0; // Stop receive logic
ETHCON1bits.AUTOFC = 0;
ETHCON1bits.MANFC = 0;
while (ETHSTATbits.ETHBUSY);
IFS1bits.ETHIF = 0; // Clear interrupt flags
ETHIENCLR = 0xFFFF; // Clear the ETHIEN register (interrupt enable)
 
// Part 2. MAC Init
EMAC1CFG1bits.SOFTRESET = 1; // Put the MACMII in reset
EMAC1CFG1bits.SOFTRESET = 0;
// Default I/O configuration, RMII operating mode
EMAC1SUPPbits.RESETRMII = 1; // Reset the MAC RMII module
EMAC1MCFGbits.RESETMGMT = 1; // Reset the MII management module
EMAC1MCFGbits.RESETMGMT = 0;
EMAC1MCFGbits.CLKSEL = 0x8; // Set the MIIM PHY clock to SYSCLK/40
while(EMAC1MINDbits.MIIMBUSY);
 
// Part 3. PHY Init
// Contrary to the ref manual, the ETH module needs to be enabled for the MIIM to work
 
ETHCON1bits.ON = 1; // Enable the ethernet module
uint16_t value;
// Reset the PHY chip
ETH_PHY_Write(PHY_ADDRESS, 0x0, 0x8000);
do {
value = ETH_PHY_Read(PHY_ADDRESS, 0x0);
} while (value & 0x8000 != 0);
 
// Delay to wait for the link to be established
// Something needs to be done about this. 5s is WAY too long to wait
Delay_MS(5000);
// Wait for auto-negotiation to finish
do {
value = ETH_PHY_Read(PHY_ADDRESS, 0x1F); // Acquire link status
} while (value & 0x1000 == 0);
 
ETHCON1bits.ON = 0; // Disable the ethernet module before changing other settings
// Part 4. MAC Configuration
EMAC1CFG1bits.RXENABLE = 1; // Enable the MAC receiving of frames
EMAC1CFG1bits.TXPAUSE = 1; // Enable PAUSE flow control frames
EMAC1CFG1bits.RXPAUSE = 1; // Enable processing of PAUSE control frames
EMAC1CFG2bits.AUTOPAD = 0; // No auto-detection for VLAN padding
EMAC1CFG2bits.VLANPAD = 0; // MAC does not perform padding of short frames
EMAC1CFG2bits.PADENABLE = 1; // Pad all short frames
EMAC1CFG2bits.CRCENABLE = 1; // Append a CRC to every frame
EMAC1CFG2bits.HUGEFRM = 1; // Allow frames of any length
EMAC1CFG2bits.LENGTHCK = 0; // Check the frame lengths to the length/type field
if ((value & 0x14) || (value & 0x18)) {
EMAC1CFG2bits.FULLDPLX = 1; // Operate in full-duplex mode
EMAC1IPGT = 0x15; // Back-to-back interpacket gap @ 0.96us/9.6us
// LED1_LAT = 1;
} else {
EMAC1CFG2bits.FULLDPLX = 0; // Operate in half-duplex mode
EMAC1IPGT = 0x12; // Back-to-back interpacket gap @ 0.96us/9.6us
// LED2_LAT = 1;
}
if ((value & 0x08) || (value & 0x18)) {
EMAC1SUPPbits.SPEEDRMII = 1; // 100Mbps mode
// LED3_LAT = 1;
} else {
EMAC1SUPPbits.SPEEDRMII = 0; // 10Mbps mode
// LED4_LAT = 1;
}
EMAC1IPGRbits.NB2BIPKTGP1 = 0xC; // Set some other delay gap values
EMAC1IPGRbits.NB2BIPKTGP2 = 0x12;
EMAC1CLRTbits.CWINDOW = 0x37; // Set collision window to count of frame bytes
EMAC1CLRTbits.RETX = 0xF; // Set number of retransmission attempts
EMAC1MAXF = 0x7F4; // Set the maximum frame length to 2046 bits
// Default MAC address is 00-04-A3-1A-4C-FC
// Set MAC address to 00-18-3E-00-D7-EB
EMAC1SA0 = 0xEBD7;
EMAC1SA1 = 0x003E;
EMAC1SA2 = 0x1800;
 
// Part 5. Ethernet Controller Initialization cont.
// Flow control is off by default!
ETHRXFCbits.HTEN = 0; // Disable hash table filtering
ETHRXFCbits.MPEN = 0; // Disable magic packet filtering
ETHRXFCbits.PMMODE = 0; // Disable pattern matching
ETHRXFCbits.CRCERREN = 0; // Disable CRC error collection filtering
ETHRXFCbits.CRCOKEN = 0; // Disable CRC filtering
ETHRXFCbits.RUNTERREN = 0; // Disable runt error collection filtering
ETHRXFCbits.RUNTEN = 0; // Disable runt filtering
ETHRXFCbits.UCEN = 1; // Enable unicast filtering
ETHRXFCbits.NOTMEEN = 0; // Disable acceptance of packets to other destinations
ETHRXFCbits.MCEN = 0; // Disable multicast filtering
ETHRXFCbits.BCEN = 0; // Disable broadcast filtering
 
ETHCON2bits.RXBUF_SZ = 0x7F; // Set RX data buffer size to 2032 bytes
 
ETHIENbits.TXBUSEIE = 1; // Enable interrupt on transmit BVCI bus error
ETHIENbits.RXBUSEIE = 1; // Enable interrupt on receive BVCI bus error
ETHIENbits.RXDONEIE = 1; // Enable interrupt on packet received
// ETHIENbits.PKTPENDIE = 1; // Enable interrupt on packet pending
// ETHIENbits.RXACTIE = 1;
ETHIENbits.TXDONEIE = 1; // Enable interrupt on packet sent
ETHIENbits.TXABORTIE = 1; // Enable interrupt on packet send aborted
 
IPC12bits.ETHIP = 1; // Set interrupt priority to 2
IPC12bits.ETHIS = 1; // Set intererupt sub-priority to 2
IEC1bits.ETHIE = 1; // Enable ethernet interrupts
 
EMAC1SUPPbits.RESETRMII = 0; // Bring the RMII module out of reset
ETHCON1bits.RXEN = 1; // Start receive logic
ETHCON1bits.ON = 1; // Enable the ethernet module
 
INTEnableInterrupts();
}
 
/* Reads from the specified register on the PHY chip */
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg) {
EMAC1MADR = reg | (address << 8);
EMAC1MCMDbits.READ = 1;
Nop();Nop();Nop();
while (EMAC1MINDbits.MIIMBUSY);
EMAC1MCMDbits.READ = 0;
return EMAC1MRDD;
}
 
/* Write to the specified register on the PHY chip */
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value) {
EMAC1MADR = reg | (address << 8);
EMAC1MWTD = value;
Nop();Nop();Nop();
while (EMAC1MINDbits.MIIMBUSY);
}
 
/* Queries the number of pending packets */
uint8_t ETH_Recv_Queue(void) {
return ETHSTATbits.BUFCNT;
}
 
/* Function to read a single packet (<2014 bytes) */
uint8_t ETH_Read_Packet(uint8_t *buffer, uint16_t *length) {
uint16_t i, j;
uint16_t size;
uint8_t descriptor_index = eth_data->RX_descriptor_index;
 
// Look for the first descriptor where EOWN is cleared and SOP/EOP is set
for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
if ((eth_data->RX_ED_table.descriptor[descriptor_index].EOWN == 0) &&
(eth_data->RX_ED_table.descriptor[descriptor_index].SOP == 1) &&
(eth_data->RX_ED_table.descriptor[descriptor_index].EOP == 1)) {
 
// Read the packet data values into the buffer
size = eth_data->RX_ED_table.descriptor[descriptor_index].BYTE_COUNT - 18;
for (j = 0; j < size; j++) {
buffer[j] = eth_data->RX_ED_buffer[descriptor_index][j+14];
}
*length = size;
 
// Reset the descriptors
eth_data->RX_ED_table.descriptor[descriptor_index].SOP = 0;
eth_data->RX_ED_table.descriptor[descriptor_index].EOP = 0;
eth_data->RX_ED_table.descriptor[descriptor_index].EOWN = 1;
 
eth_data->RX_descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
 
ETHCON1bits.BUFCDEC = 1;
return 0;
 
} else {
descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
}
}
 
return 1;
}
 
/* Function to send a single packet (<2018 bytes) */
uint8_t ETH_Write_Packet(ETH_MAC_ADDRESS dest, ETH_MAC_ADDRESS src, uint16_t length, uint8_t *buffer) {
uint16_t i;
uint16_t write_index = 0;
uint16_t read_index = 0;
uint16_t descriptor_index = eth_data->TX_descriptor_index;
 
// Do a quick sanity check to ensure that we have enough memory to send the message
if (length > ETH_TX_ED_BUFFER_SIZE - 14)
return 1;
 
// Fill the descriptor
eth_data->TX_ED_table.descriptor[descriptor_index].TSV.registers[0] = 0;
eth_data->TX_ED_table.descriptor[descriptor_index].TSV.registers[1] = 0;
eth_data->TX_ED_table.descriptor[descriptor_index].EOWN = 1;
eth_data->TX_ED_table.descriptor[descriptor_index].SOP = 1;
eth_data->TX_ED_table.descriptor[descriptor_index].EOP = 1;
 
for (i = 0; i < 6; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = dest.bytes[i];
write_index++;
}
for (i = 0; i < 6; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = src.bytes[i];
write_index++;
}
eth_data->TX_ED_buffer[descriptor_index][write_index] = length >> 8;
eth_data->TX_ED_buffer[descriptor_index][write_index+1] = length;
write_index += 2;
 
 
eth_data->TX_ED_table.descriptor[descriptor_index].BYTE_COUNT = length + 14;
 
for (i = 0; i < length; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = buffer[read_index];
write_index++;
read_index++;
}
 
// Wait for any previous transmits to finish before sending
while (ETHSTATbits.TXBUSY);
ETHCON1bits.TXRTS = 1;
while (ETHSTATbits.TXBUSY);
 
eth_data->TX_descriptor_index = (descriptor_index == ETH_TX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
return 0;
}
 
void __ISR(_ETH_VECTOR, ipl1) __ETH_Interrupt_Handler(void) {
// uint32_t value = ETHIRQ;
if (ETHIRQbits.TXBUSE) {
// TX bus error, something -should- be done
Reset_Board(BOARD_MODE_ETHERNET);
ETHIRQbits.TXBUSE = 0;
}
if (ETHIRQbits.RXBUSE) {
// RX bus error, something -should- be done
Reset_Board(BOARD_MODE_ETHERNET);
ETHIRQbits.RXBUSE = 0;
}
if (ETHIRQbits.RXDONE) {
// Call the previously saved function
if (eth_data->rx_callback != NULL)
(*eth_data->rx_callback)();
ETHIRQbits.RXDONE = 0;
}
// if (ETHIRQbits.PKTPEND) {
//
// ETHIRQbits.PKTPEND = 0;
// }
if (ETHIRQbits.TXDONE) {
// Call the previously saved function
if (eth_data->tx_callback != NULL)
(*eth_data->tx_callback)();
ETHIRQbits.TXDONE = 0;
}
if (ETHIRQbits.TXABORT) {
// TX aborted, do we care?
ETHIRQbits.TXABORT = 0;
}
if (ETHIRQbits.RXBUFNA) {
// This is a serious error!
// TODO: handle this
Reset_Board(BOARD_MODE_ETHERNET);
ETHIRQbits.RXBUFNA = 0;
}
if (ETHIRQbits.RXOVFLW) {
// This is a serious error!
// TODO: handle this
Reset_Board(BOARD_MODE_ETHERNET);
ETHIRQbits.RXOVFLW = 0;
}
 
IFS1bits.ETHIF = 0;
}
/PIC Projects/Cerebot_32MX7_LED_Cube/ETHERNET.h
0,0 → 1,162
#ifndef ETHERNET_H
#define ETHERNET_H
 
#define ETH_TX_DESCRIPTOR_COUNT 2
#define ETH_RX_DESCRIPTOR_COUNT 10
#define ETH_TX_ED_BUFFER_SIZE 2032
#define ETH_RX_ED_BUFFER_SIZE 2032
 
#ifdef CEREBOT_MX7CK
#define PHY_RESET_TRIS TRISAbits.TRISA6
#define PHY_RESET_LAT LATAbits.LATA6
#endif
#ifdef CEREBOT_32MX7
#define PHY_RESET_TRIS TRISEbits.TRISE9
#define PHY_RESET_LAT LATEbits.LATE9
#endif
#define ETH_MDC_TRIS TRISDbits.TRISD11
#define ETH_MDIO_TRIS TRISDbits.TRISD8
#define ETH_TXEN_TRIS TRISDbits.TRISD6
#define ETH_TXD0_TRIS TRISFbits.TRISF1
#define ETH_TXD1_TRIS TRISFbits.TRISF0
#define ETH_RXCLK_TRIS TRISGbits.TRISG9
#define ETH_RXDV_TRIS TRISGbits.TRISG8
#define ETH_RXD0_TRIS TRISBbits.TRISB12
#define ETH_RXD1_TRIS TRISBbits.TRISB13
#define ETH_RXERR_TRIS TRISBbits.TRISB11
 
#define PHY_ADDRESS 0x0
 
typedef union {
struct {
uint8_t BYTE_0;
uint8_t BYTE_1;
uint8_t BYTE_2;
uint8_t BYTE_3;
uint8_t BYTE_4;
uint8_t BYTE_5;
};
uint8_t bytes[6];
} ETH_MAC_ADDRESS;
 
typedef union {
struct {
// Bits 31:0
unsigned BYTE_COUNT : 16; // Total bytes in frame not counting collided bytes
unsigned COLLISION_COUNT : 4; // Number of collisions current packet incurred durrent transmit attempts
unsigned CRC_ERROR : 1; // Attached CRC did not match the internal generated CRC
unsigned LENGTH_CHECK_ERROR : 1; // Frame length field value in packet does not match actual data byte length and is not a Type field
unsigned LENGTH_OUT_OF_RANGE : 1; // Frame type/length field was larger than 1500 bytes
unsigned DONE : 1; // Transmit of packet was completed
unsigned MULTICASE : 1; // Destination address was a multicast address
unsigned BROADCAST : 1; // Destination address was a broadcast address
unsigned PACKET_DEFER : 1; // Packet was deferred for at least one attempt
unsigned EXCESSIVE_DEFER : 1; // Packet was defered in excess of 6071/24287 nibble(100Mbps)/bit(10Mbps) times
unsigned MAXIMUM_COLLISION : 1; // Packet aborted, number of collisions exceeded RETX
unsigned LATE_COLLISION : 1; // Collision occurred beyond the collision window (512 bit times)
unsigned GIANT : 1; // Frame byte count greater than MACMAXF
unsigned UNDERRUN : 1; // Failed to transfer complete packet to the transmit MAC module
// Bits 63:32
unsigned BYTES_TRANSMITTED : 16; // Total bytes transmitted on wire (including collisions)
unsigned CONTROL_FRAME : 1; // Frame transmitted was a control frame
unsigned PAUSE_CONTROL_FRAME : 1; // Frame transmitted was a control frame with a valid PAUSE Op code
unsigned BACKPRESSURE : 1; // Carrier-sense method backpressure was previously applied
unsigned VLAN_TAGGED : 1; // Frame length/type field contained 0x8100 (VLAN protocol identifier)
unsigned : 12;
};
uint32_t registers[2];
} ETH_TRANSMIT_STATUS_VECTOR;
 
typedef union {
struct {
// Bits 31:0
unsigned BYTE_COUNT : 16; // Length of received frame
unsigned LONG_DROP_EVENT : 1; // Packet over 50000 bit times occured or packet since last RSV was dropped
unsigned RXDV_EVENT : 1; // Last receive event seen not long enough to be a valid packet
unsigned CARRIER_EVENT : 1; // Carrier event detected, noted, and reported
unsigned CODE_VIOLATION : 1; // MII data does not represent a valid data code when MRXER asserted
unsigned CRC_ERROR : 1; // Frame CRC does not match the CRC calculated by the receiver MAC
unsigned LENGTH_CHECK_ERROR : 1; // Frame length field value doe snot match the actual data byte length
unsigned LENGTH_OUT_OF_RANGE : 1; // Frame type/length field was larger than 1500 bytes
unsigned RECEIVE_OK : 1; // Packet has a valid CRC and no symbol errors
unsigned MULTICAST : 1; // Packet had a valid multicast address
unsigned BROADCAST : 1; // Packet had a valid broadcast address
unsigned DRIBBLE_NIBBLE : 1; // An additional 1-7 bits received after packet
unsigned CONTROL_FRAME : 1; // Frame recognized as a control frame
unsigned PAUSE_CONTROL_FRAME : 1; // Frame recognized as a control frame with a valid PAUSE Op code
unsigned UNKNOWN_OP_CODE : 1; // Frame recognized as a control frame but with an unknown Op code
unsigned VLAN_TAGGED : 1; // Frame recognized as a VLAN tagged frame
unsigned : 1;
// Bits 63:32;
unsigned PKT_CHECKSUM : 16; // RX packet payload checksum of this descriptor's packet
unsigned : 8;
unsigned RUNT_PACKET : 1; // Runt packet
unsigned BROADCAST_OR_NOT_DEST : 1; // NOT unicast match AND NOT multicast match
unsigned HASH_TABLE_MATCH : 1; // Hash table match
unsigned MAGIC_PACKET_MATCH : 1; // Magic packet match
unsigned PATTERN_MATCH : 1; // Pattern match
unsigned UNICAST_MATCH : 1; // Unicast match
unsigned BROADCAST_MATCH : 1; // Broadcast match
unsigned MULTICAST_MATCH : 1; // Multicast match
};
uint32_t registers[2];
} ETH_RECEIVE_STATUS_VECTOR;
 
typedef struct {
unsigned : 7;
unsigned EOWN : 1; // Ethernet controller own bit (1 = ED owned by controller, do not modify)
unsigned NPV : 1; // Next ED pointer valid enable bit (1 = NEXT_ED field exists)
unsigned : 7;
unsigned BYTE_COUNT : 11; // Number of bytes to be transmited for this descriptor (1-2047)
unsigned : 3;
unsigned EOP : 1; // End of packet enable bit (1 = transmit end of packet delimiter)
unsigned SOP : 1; // Start of packet enable bit (1 = transmit start of packet delimiter)
uint32_t BUFFER_ADDR; // Starting point address of the data buffer
ETH_TRANSMIT_STATUS_VECTOR TSV; // Transmit status vector bits
} ETH_TX_ETHERNET_DESCRIPTOR;
 
typedef struct {
unsigned : 7;
unsigned EOWN : 1; // Ethernet controller own bit (1 = ED owned by controller, do not modify)
unsigned NPV : 1; // Next ED pointer valid enable bit (1 = NEXT_ED field exists)
unsigned : 7;
unsigned BYTE_COUNT : 11; // Number of bytes to be transmited for this descriptor (1-2047)
unsigned : 3;
unsigned EOP : 1; // End of packet enable bit (1 = transmit end of packet delimiter)
unsigned SOP : 1; // Start of packet enable bit (1 = transmit start of packet delimiter)
uint32_t BUFFER_ADDR; // Starting point address of the data buffer
ETH_RECEIVE_STATUS_VECTOR RSV; // Transmit status vector bits
} ETH_RX_ETHERNET_DESCRIPTOR;
 
typedef struct {
ETH_TX_ETHERNET_DESCRIPTOR descriptor[ETH_TX_DESCRIPTOR_COUNT];
uint32_t next_ED;
} ETH_TX_DESCRIPTOR_TABLE;
 
typedef struct {
ETH_RX_ETHERNET_DESCRIPTOR descriptor[ETH_RX_DESCRIPTOR_COUNT];
uint32_t next_ED;
} ETH_RX_DESCRIPTOR_TABLE;
 
typedef struct {
ETH_TX_DESCRIPTOR_TABLE TX_ED_table;
ETH_RX_DESCRIPTOR_TABLE RX_ED_table;
uint8_t TX_ED_buffer[ETH_TX_DESCRIPTOR_COUNT][ETH_TX_ED_BUFFER_SIZE];
uint8_t RX_ED_buffer[ETH_RX_DESCRIPTOR_COUNT][ETH_RX_ED_BUFFER_SIZE];
uint8_t TX_descriptor_index;
uint8_t RX_descriptor_index;
void (*tx_callback)(void);
void (*rx_callback)(void);
} ETH_DATA;
 
void ETH_Init(ETH_DATA *data, void(*tx_callback)(void), void(*rx_callback)(void));
 
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg);
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value);
 
uint8_t ETH_Recv_Queue(void);
uint8_t ETH_Read_Packet(uint8_t *buffer, uint16_t *length);
uint8_t ETH_Write_Packet(ETH_MAC_ADDRESS dest, ETH_MAC_ADDRESS src, uint16_t length, uint8_t *buffer);
 
#endif /* ETHERNET_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/UART API/CubeInterface.py
0,0 → 1,257
import serial
from CubeRawCommands import *
 
# Constants
CUBE_LAYER_COUNT = 8
CUBE_ROW_COUNT = 8
CUBE_COLUMN_COUNT = 8
CUBE_ROTATIONS = 7
GCS_REG_SIZE = 36
GCS_LAYER_SIZE = GCS_REG_SIZE * CUBE_ROW_COUNT
 
# 3 bytes per LED, 1536 total for the cube
cube_buffer = bytearray(CUBE_LAYER_COUNT*GCS_LAYER_SIZE)
rotation_counter = 0
 
# Specify the serial port to connect to
serial_port = serial.Serial()
 
'''Opens the serial port for sending commands through.'''
def Cube_Init(port, baudrate):
serial_port.port = port
serial_port.baudrate = baudrate
serial_port.open()
 
'''Clears the local buffer for LED values.'''
def Cube_Clear():
for i in range(len(cube_buffer)):
cube_buffer[i] = 0
 
'''Sets a specific pixel in the local buffer.'''
def Cube_Set_Pixel(layer, row, column, R, G, B):
# Set the specified pixel to the given color
R &= 0x0FFF
G &= 0x0FFF
B &= 0x0FFF
var = row * GCS_REG_SIZE + (column // 2 * 9)
offset = (layer * GCS_LAYER_SIZE) + var
if column % 2 == 0:
cube_buffer[offset+0] = R & 0xFF
cube_buffer[offset+1] = ((G << 4) | (R >> 8)) & 0xFF
cube_buffer[offset+2] = G >> 4
cube_buffer[offset+3] = B & 0xFF
cube_buffer[offset+4] = ((cube_buffer[offset+4] & 0xF0) | (B >> 8)) & 0xFF
elif column % 2 == 1:
cube_buffer[offset+4] = ((cube_buffer[offset+4] & 0x0F) | (R << 4)) & 0xFF
cube_buffer[offset+5] = R >> 4
cube_buffer[offset+6] = G & 0xFF
cube_buffer[offset+7] = ((B << 4) | (G >> 8)) & 0xFF
cube_buffer[offset+8] = B >> 4
 
'''Retreives a specific pixel in the local buffer.'''
def Cube_Get_Pixel(layer, row, column):
# Get and return the color for the specified pixel
R = G = B = 0
var = row * GCS_REG_SIZE + (column // 2 * 9)
offset = (layer * GCS_LAYER_SIZE) + var
if column % 2 == 0:
R = cube_buffer[offset+0] | ((cube_buffer[offset+1] & 0x0F) << 8);
G = (cube_buffer[offset+1] >> 4) | (cube_buffer[offset+2] << 4);
B = cube_buffer[offset+3] | ((cube_buffer[offset+4] & 0x0F) << 8);
elif column % 2 == 1:
R = (cube_buffer[offset+4] >> 4) | (cube_buffer[offset+5] << 4);
G = cube_buffer[offset+6] | ((cube_buffer[offset+7] & 0x0F) << 8);
B = (cube_buffer[offset+7] >> 4) | (cube_buffer[offset+8] << 4);
return [R,G,B]
 
'''Moves a value from one pixel to another in the local buffer.'''
def Cube_Move_Pixel(layer_1, row_1, column_1, layer_2, row_2, column_2):
old = Cube_Get_Pixel(layer1, row_1, column_1)
Cube_Set_Pixel(layer_2, row_2, column_2, old[0], old[1], old[2])
 
'''Rotates the specified shell in the local buffer.'''
def Cube_Rotate_Shell(shell, direction):
for layer in range(CUBE_LAYER_COUNT):
if direction == 1:
if shell == 0:
# Rotate outermost layer
old = Cube_Get_Pixel(layer, 0, 0);
Cube_Move_Pixel(layer, 0, 1, layer, 0, 0);
Cube_Move_Pixel(layer, 0, 2, layer, 0, 1);
Cube_Move_Pixel(layer, 0, 3, layer, 0, 2);
Cube_Move_Pixel(layer, 0, 4, layer, 0, 3);
Cube_Move_Pixel(layer, 0, 5, layer, 0, 4);
Cube_Move_Pixel(layer, 0, 6, layer, 0, 5);
Cube_Move_Pixel(layer, 0, 7, layer, 0, 6);
Cube_Move_Pixel(layer, 1, 7, layer, 0, 7);
Cube_Move_Pixel(layer, 2, 7, layer, 1, 7);
Cube_Move_Pixel(layer, 3, 7, layer, 2, 7);
Cube_Move_Pixel(layer, 4, 7, layer, 3, 7);
Cube_Move_Pixel(layer, 5, 7, layer, 4, 7);
Cube_Move_Pixel(layer, 6, 7, layer, 5, 7);
Cube_Move_Pixel(layer, 7, 7, layer, 6, 7);
Cube_Move_Pixel(layer, 7, 6, layer, 7, 7);
Cube_Move_Pixel(layer, 7, 5, layer, 7, 6);
Cube_Move_Pixel(layer, 7, 4, layer, 7, 5);
Cube_Move_Pixel(layer, 7, 3, layer, 7, 4);
Cube_Move_Pixel(layer, 7, 2, layer, 7, 3);
Cube_Move_Pixel(layer, 7, 1, layer, 7, 2);
Cube_Move_Pixel(layer, 7, 0, layer, 7, 1);
Cube_Move_Pixel(layer, 6, 0, layer, 7, 0);
Cube_Move_Pixel(layer, 5, 0, layer, 6, 0);
Cube_Move_Pixel(layer, 4, 0, layer, 5, 0);
Cube_Move_Pixel(layer, 3, 0, layer, 4, 0);
Cube_Move_Pixel(layer, 2, 0, layer, 3, 0);
Cube_Move_Pixel(layer, 1, 0, layer, 2, 0);
Cube_Set_Pixel(layer, 1, 0, old[0], old[1], old[2]);
elif shell == 1:
# Rotate second to outermost layer
old = Cube_Get_Pixel(layer, 1, 1);
Cube_Move_Pixel(layer, 1, 2, layer, 1, 1);
Cube_Move_Pixel(layer, 1, 3, layer, 1, 2);
Cube_Move_Pixel(layer, 1, 4, layer, 1, 3);
Cube_Move_Pixel(layer, 1, 5, layer, 1, 4);
Cube_Move_Pixel(layer, 1, 6, layer, 1, 5);
Cube_Move_Pixel(layer, 2, 6, layer, 1, 6);
Cube_Move_Pixel(layer, 3, 6, layer, 2, 6);
Cube_Move_Pixel(layer, 4, 6, layer, 3, 6);
Cube_Move_Pixel(layer, 5, 6, layer, 4, 6);
Cube_Move_Pixel(layer, 6, 6, layer, 5, 6);
Cube_Move_Pixel(layer, 6, 5, layer, 6, 6);
Cube_Move_Pixel(layer, 6, 4, layer, 6, 5);
Cube_Move_Pixel(layer, 6, 3, layer, 6, 4);
Cube_Move_Pixel(layer, 6, 2, layer, 6, 3);
Cube_Move_Pixel(layer, 6, 1, layer, 6, 2);
Cube_Move_Pixel(layer, 5, 1, layer, 6, 1);
Cube_Move_Pixel(layer, 4, 1, layer, 5, 1);
Cube_Move_Pixel(layer, 3, 1, layer, 4, 1);
Cube_Move_Pixel(layer, 2, 1, layer, 3, 1);
Cube_Set_Pixel(layer, 2, 1, old[0], old[1], old[2]);
elif shell == 2:
# Rotate second to innermost layer
old = Cube_Get_Pixel(layer, 2, 2);
Cube_Move_Pixel(layer, 2, 3, layer, 2, 2);
Cube_Move_Pixel(layer, 2, 4, layer, 2, 3);
Cube_Move_Pixel(layer, 2, 5, layer, 2, 4);
Cube_Move_Pixel(layer, 3, 5, layer, 2, 5);
Cube_Move_Pixel(layer, 4, 5, layer, 3, 5);
Cube_Move_Pixel(layer, 5, 5, layer, 4, 5);
Cube_Move_Pixel(layer, 5, 4, layer, 5, 5);
Cube_Move_Pixel(layer, 5, 3, layer, 5, 4);
Cube_Move_Pixel(layer, 5, 2, layer, 5, 3);
Cube_Move_Pixel(layer, 4, 2, layer, 5, 2);
Cube_Move_Pixel(layer, 3, 2, layer, 4, 2);
Cube_Set_Pixel(layer, 3, 2, old[0], old[1], old[2]);
elif shell == 3:
# Rotate innermost layer
old = Cube_Get_Pixel(layer, 3, 3);
Cube_Move_Pixel(layer, 3, 4, layer, 3, 3);
Cube_Move_Pixel(layer, 4, 4, layer, 3, 4);
Cube_Move_Pixel(layer, 4, 3, layer, 4, 4);
Cube_Set_Pixel(layer, 4, 3, old[0], old[1], old[2]);
else:
if shell == 0:
# Rotate outermost layer
old = Cube_Get_Pixel(layer, 0, 0);
Cube_Move_Pixel(layer, 1, 0, layer, 0, 0);
Cube_Move_Pixel(layer, 2, 0, layer, 1, 0);
Cube_Move_Pixel(layer, 3, 0, layer, 2, 0);
Cube_Move_Pixel(layer, 4, 0, layer, 3, 0);
Cube_Move_Pixel(layer, 5, 0, layer, 4, 0);
Cube_Move_Pixel(layer, 6, 0, layer, 5, 0);
Cube_Move_Pixel(layer, 7, 0, layer, 6, 0);
Cube_Move_Pixel(layer, 7, 1, layer, 7, 0);
Cube_Move_Pixel(layer, 7, 2, layer, 7, 1);
Cube_Move_Pixel(layer, 7, 3, layer, 7, 2);
Cube_Move_Pixel(layer, 7, 4, layer, 7, 3);
Cube_Move_Pixel(layer, 7, 5, layer, 7, 4);
Cube_Move_Pixel(layer, 7, 6, layer, 7, 5);
Cube_Move_Pixel(layer, 7, 7, layer, 7, 6);
Cube_Move_Pixel(layer, 6, 7, layer, 7, 7);
Cube_Move_Pixel(layer, 5, 7, layer, 6, 7);
Cube_Move_Pixel(layer, 4, 7, layer, 5, 7);
Cube_Move_Pixel(layer, 3, 7, layer, 4, 7);
Cube_Move_Pixel(layer, 2, 7, layer, 3, 7);
Cube_Move_Pixel(layer, 1, 7, layer, 2, 7);
Cube_Move_Pixel(layer, 0, 7, layer, 1, 7);
Cube_Move_Pixel(layer, 0, 6, layer, 0, 7);
Cube_Move_Pixel(layer, 0, 5, layer, 0, 6);
Cube_Move_Pixel(layer, 0, 4, layer, 0, 5);
Cube_Move_Pixel(layer, 0, 3, layer, 0, 4);
Cube_Move_Pixel(layer, 0, 2, layer, 0, 3);
Cube_Move_Pixel(layer, 0, 1, layer, 0, 2);
Cube_Set_Pixel(layer, 0, 1, old[0], old[1], old[2]);
if shell == 1:
# Rotate second to outermost layer
old = Cube_Get_Pixel(layer, 1, 1);
Cube_Move_Pixel(layer, 2, 1, layer, 1, 1);
Cube_Move_Pixel(layer, 3, 1, layer, 2, 1);
Cube_Move_Pixel(layer, 4, 1, layer, 3, 1);
Cube_Move_Pixel(layer, 5, 1, layer, 4, 1);
Cube_Move_Pixel(layer, 6, 1, layer, 5, 1);
Cube_Move_Pixel(layer, 6, 2, layer, 6, 1);
Cube_Move_Pixel(layer, 6, 3, layer, 6, 2);
Cube_Move_Pixel(layer, 6, 4, layer, 6, 3);
Cube_Move_Pixel(layer, 6, 5, layer, 6, 4);
Cube_Move_Pixel(layer, 6, 6, layer, 6, 5);
Cube_Move_Pixel(layer, 5, 6, layer, 6, 6);
Cube_Move_Pixel(layer, 4, 6, layer, 5, 6);
Cube_Move_Pixel(layer, 3, 6, layer, 4, 6);
Cube_Move_Pixel(layer, 2, 6, layer, 3, 6);
Cube_Move_Pixel(layer, 1, 6, layer, 2, 6);
Cube_Move_Pixel(layer, 1, 5, layer, 1, 6);
Cube_Move_Pixel(layer, 1, 4, layer, 1, 5);
Cube_Move_Pixel(layer, 1, 3, layer, 1, 4);
Cube_Move_Pixel(layer, 1, 2, layer, 1, 3);
Cube_Set_Pixel(layer, 1, 2, old[0], old[1], old[2]);
if shell == 2:
# Rotate second to innermost layer
old = Cube_Get_Pixel(layer, 2, 2);
Cube_Move_Pixel(layer, 3, 2, layer, 2, 2);
Cube_Move_Pixel(layer, 4, 2, layer, 3, 2);
Cube_Move_Pixel(layer, 5, 2, layer, 4, 2);
Cube_Move_Pixel(layer, 5, 3, layer, 5, 2);
Cube_Move_Pixel(layer, 5, 4, layer, 5, 3);
Cube_Move_Pixel(layer, 5, 5, layer, 5, 4);
Cube_Move_Pixel(layer, 4, 5, layer, 5, 5);
Cube_Move_Pixel(layer, 3, 5, layer, 4, 5);
Cube_Move_Pixel(layer, 2, 5, layer, 3, 5);
Cube_Move_Pixel(layer, 2, 4, layer, 2, 5);
Cube_Move_Pixel(layer, 2, 3, layer, 2, 4);
Cube_Set_Pixel(layer, 2, 3, old[0], old[1], old[2]);
if shell == 3:
# Rotate innermost layer
old = Cube_Get_Pixel(layer, 3, 3);
Cube_Move_Pixel(layer, 4, 3, layer, 3, 3);
Cube_Move_Pixel(layer, 4, 4, layer, 4, 3);
Cube_Move_Pixel(layer, 3, 4, layer, 4, 4);
Cube_Set_Pixel(layer, 3, 4, old[0], old[1], old[2]);
 
'''Rotates the entire cube in the local buffer.'''
def Cube_Rotate(direction):
# Rotate outermost layer
Cube_Rotate_Shell(0, direction);
# Rotate second to outermost layer
if ((rotation_counter != 1) and (rotation_counter != 5)):
Cube_Rotate_Shell(1, direction);
# Rotate second to innermost layer
if ((rotation_counter != 0) and (rotation_counter != 2) and (rotation_counter != 4) and (rotation_counter != 6)):
Cube_Rotate_Shell(2, direction);
# Rotate innermost layer
if ((rotation_counter == 3) or (rotation_counter == 7)):
Cube_Rotate_Shell(3, direction);
 
if (direction == 0):
if rotation_counter == CUBE_ROTATIONS - 1:
rotation_counter = 0
else:
rotation_counter = rotation_counter + 1
else:
if rotation_counter == 0:
rotation_counter = CUBE_ROTATIONS - 1
else:
rotation_counter = rotation_counter - 1
 
'''Write the local buffer to the cube.'''
def Cube_Update():
serial_port.write(CMD_Set_All(cube_buffer))
/PIC Projects/Cerebot_32MX7_LED_Cube/UART API/CubeMain.py
0,0 → 1,62
import serial,time
from CubeRawCommands import *
from CubeInterface import *
 
def Animation_Row_Column_Sweep(iterations, delay):
for z in range(iterations):
for i in range(3):
for j in range(CUBE_ROW_COUNT):
Cube_Clear();
for k in range(CUBE_COLUMN_COUNT):
if (i % 3 == 0):
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,j,k,0xFF,0x00,0x00)
elif (i % 3 == 1):
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,j,k,0x00,0xFF,0x00)
else:
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,j,k,0x00,0x00,0xFF)
Cube_Update()
time.sleep(delay)
for j in range(CUBE_ROW_COUNT):
Cube_Clear();
for k in range(CUBE_COLUMN_COUNT):
if (i % 3 == 0):
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,k,j,0xFF,0x00,0x00)
elif (i % 3 == 1):
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,k,j,0x00,0xFF,0x00)
else:
for a in range(CUBE_LAYER_COUNT):
Cube_Set_Pixel(a,k,j,0x00,0x00,0xFF)
Cube_Update()
time.sleep(delay)
for j in range(CUBE_LAYER_COUNT-1, -1, -1):
Cube_Clear();
if (i % 3 == 0):
for k in range(CUBE_LAYER_COUNT):
if (k == j):
for x in range(CUBE_ROW_COUNT):
for y in range(CUBE_COLUMN_COUNT):
Cube_Set_Pixel(k,x,y,0xFF,0x00,0x00)
elif (i % 3 == 1):
for k in range(CUBE_LAYER_COUNT):
if (k == j):
for x in range(CUBE_ROW_COUNT):
for y in range(CUBE_COLUMN_COUNT):
Cube_Set_Pixel(k,x,y,0x00,0xFF,0x00)
else:
for k in range(CUBE_LAYER_COUNT):
if (k == j):
for x in range(CUBE_ROW_COUNT):
for y in range(CUBE_COLUMN_COUNT):
Cube_Set_Pixel(k,x,y,0x00,0x00,0xFF)
Cube_Update()
time.sleep(delay)
 
if __name__ == '__main__':
Cube_Init('COM11', 256000)
 
Animation_Row_Column_Sweep(3,0)
/PIC Projects/Cerebot_32MX7_LED_Cube/UART API/CubeRawCommands.py
0,0 → 1,43
'''Generates the byte array for setting the global brightness.'''
def CMD_Set_BC(brightness):
barray = bytearray.fromhex('7E 00 02 0A')
barray.extend([brightness])
barray.extend([Calculate_Checksum(barray)])
return barray
 
'''Generates the byte array for clearing all pixels.'''
def CMD_Clear():
return bytearray.fromhex('7E 00 01 0B F4')
 
'''Generates the command for setting a specific pixel.'''
def CMD_Set_Pixel(layer, row, column, r, g, b):
barray = bytearray.fromhex('7E 00 07 10')
barray.extend([layer,row,column,r,g,b,])
barray.extend([Calculate_Checksum(barray)])
return barray
 
'''Generates the command for setting the entire cube.'''
def CMD_Set_All(leds):
barray = bytearray.fromhex('7E 09 01 11')
barray.extend(leds)
barray.extend([Calculate_Checksum(barray)])
return barray
 
'''Generates the command for setting the rotating overlay text.'''
def CMD_Start_Text(r, g, b, string):
length = len(string) + 4
barray = bytearray.fromhex('7E 00')
barray.extend([length, 0x20, r, g, b])
barray.extend(string.encode())
barray.extend([Calculate_Checksum(barray)])
return barray
 
'''Generates the command for stopping the rotating overlay text.'''
def CMD_Stop_Text():
return bytes.fromhex('7E 00 01 21 DE')
 
def Calculate_Checksum(barray):
s = 0
for entry in range(3,len(barray)):
s += barray[entry]
return 255 - (s & 0xFF)
/PIC Projects/Cerebot_32MX7_LED_Cube/TIMER4.c
0,0 → 1,60
#include "defines.h"
#include "TIMER4.h"
 
static TIMER4_DATA *timer_data_ptr;
 
void TIMER4_Init(TIMER4_DATA *data, void (*callback_ms)(void),
void (*callback_div)(void), uint32_t time_ms) {
if (data != NULL) // if ptr is null, use existing data
timer_data_ptr = data;
 
// The first callback function will be executed every ms
timer_data_ptr->callback_function_1 = callback_ms;
// The second callback function will be executed at the multiplier specified
timer_data_ptr->callback_function_2 = callback_div;
timer_data_ptr->divider = time_ms;
timer_data_ptr->count = 0;
 
INTDisableInterrupts();
 
T4CON = 0x0;
 
// Set timer to trigger every millisecond
uint16_t time = 5000;
T4CONSET = 0x0040; // Prescaler at 1:16
 
Nop();
TMR4 = 0x0; // Clear timer register
PR4 = time; // Load period register
IPC4SET = 0x00000005; // Set priority level = 1, sub-priority level = 1
IFS0CLR = 0x00010000; // Clear timer interrupt flag
IEC0SET = 0x00010000; // Enable timer interrupt
 
INTEnableInterrupts();
}
 
void TIMER4_Start(void) {
T4CONSET = 0x8000; // Start timer
}
 
void TIMER4_Stop(void) {
T4CONCLR = 0x8000; // Stop timer
}
 
void __ISR(_TIMER_4_VECTOR, ipl4) __TIMER_4_Interrupt_Handler(void) {
// Call the saved callback function
if (timer_data_ptr->callback_function_1 != NULL)
(*timer_data_ptr->callback_function_1)();
 
if (timer_data_ptr->divider != 0 && timer_data_ptr->callback_function_2 != NULL) {
if (timer_data_ptr->count == timer_data_ptr->divider) {
(*timer_data_ptr->callback_function_2)();
timer_data_ptr->count = 0;
} else {
timer_data_ptr->count++;
}
}
 
IFS0CLR = 0x00010000; // Clear the timer interrupt flag
}
/PIC Projects/Cerebot_32MX7_LED_Cube/TIMER4.h
0,0 → 1,17
#ifndef TIMER4_H
#define TIMER4_H
 
typedef struct {
void (*callback_function_1)(void);
void (*callback_function_2)(void);
uint32_t divider;
uint32_t count;
} TIMER4_DATA;
 
void TIMER4_Init(TIMER4_DATA *data, void (*callback_ms)(void),
void (*callback_div)(void), uint32_t time_ms);
void TIMER4_Start(void);
void TIMER4_Stop(void);
 
#endif /* TIMER4_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/UART1.c
0,0 → 1,105
#include "defines.h"
#include "UART1.h"
 
static UART1_DATA *uart_data_ptr;
 
/* Note: BRGH values are different from PIC18!
*
* Baud Rate Calculation (BRGH = 0):
* Baud Rate = PerfBusFreq / (16 * (BRG + 1))
* BRG = PerfBusFreq / (16 * Baud Rate) - 1
*
* Baud Rate Calculation (BRGH = 1):
* Baud Rate = PerfBusFreq / (4 * (BRG + 1))
* BRG = PerfBusFreq / (4 * Baud Rate) - 1
*/
 
void UART1_Init(UART1_DATA *data, void (*rx_callback)(uint8_t)) {
uart_data_ptr = data;
uart_data_ptr->rx_callback = rx_callback;
uart_data_ptr->buffer_out_len = 0;
uart_data_ptr->buffer_out_ind = 0;
 
INTDisableInterrupts();
 
IEC0CLR = 0x1C000000; // Disable all UART1 interrupts
IFS0CLR = 0x1C000000; // Clear any existing events
IPC6SET = 0x00000009; // Set Priority = 2, Subpriority = 1
U1MODE = 0x00008008; // UART enabled, BRGH = 1
U1STA = 0x00009400; // TX interrupt on buffer empty, RX interrupt on buffer not empty
 
// U1BRG = 173; // Set baud rate to 115200 @ 80MHz (0.22% error)
U1BRG = 86; // Set baud rate to 230400 @ 80MHz (0.22% error)
// U1BRG = 77; // Set baud rate to 256000 @ 80MHz (0.12% error)
// U1BRG = 42; // Set baud rate to 460800 @ 80MHz (0.94% error)
// U1BRG = 21; // Set baud rate to 921600 @ 80MHz (1.36% error)
IEC0SET = 0x0C000000; // Enable the RX and Error interrupts
 
INTEnableInterrupts();
}
 
uint8_t UART1_Write(uint8_t *string, uint32_t length) {
if (length > UART1_BUFFER_SIZE)
return 0;
if (uart_data_ptr->buffer_out_len != 0)
return 0;
 
// Put the data to send into the outbound buffer
uart_data_ptr->buffer_out_len = length;
uart_data_ptr->buffer_out_ind = 0;
uint8_t i;
for (i = 0; i < length; i++) {
uart_data_ptr->buffer_out[i] = string[i];
}
IEC0SET = 0x10000000; // Enable TX interrupt
return 1;
}
 
void __ISR(_UART_1_VECTOR, ipl2) __UART_1_Interrupt_Handler(void) {
// Process UART1 error flag
if (IFS0bits.U1EIF) {
if (U1STAbits.PERR) { // Process parity error
 
}
if (U1STAbits.FERR) { // Process frame error
 
}
if (U1STAbits.OERR) { // Process receive buffer overrun error
U1STAbits.OERR = 0; // Clear the overrun error if set
}
IFS0CLR = 0x04000000; // Clear the error flag
}
 
// Process UART1 recieve flag
if (IFS0bits.U1RXIF) {
// Read the data received from the last transfer
while (U1STAbits.URXDA) {
uint8_t c = U1RXREG;
// Call the RX callback function on each received data
if (uart_data_ptr->rx_callback != NULL) {
(*uart_data_ptr->rx_callback)(c);
}
}
IFS0CLR = 0x08000000; // Clear the recieve flag
}
 
// Process UART1 transmit flag
if (IFS0bits.U1TXIF && IEC0bits.U1TXIE) {
// Disable the transmit interrupt if all data has been sent
if (uart_data_ptr->buffer_out_ind == uart_data_ptr->buffer_out_len) {
IEC0CLR = 0x10000000;
uart_data_ptr->buffer_out_len = 0;
} else {
// Start filling the transmit buffer
while (!U1STAbits.UTXBF) {
U1TXREG = uart_data_ptr->buffer_out[uart_data_ptr->buffer_out_ind];
uart_data_ptr->buffer_out_ind++;
if (uart_data_ptr->buffer_out_ind == uart_data_ptr->buffer_out_len)
break;
}
}
IFS0CLR = 0x10000000; // Clear the transmit flag
}
}
/PIC Projects/Cerebot_32MX7_LED_Cube/BTN.c
0,0 → 1,61
#include "defines.h"
#include "BTN.h"
 
static BTN_DATA *btn_data_ptr;
 
void BTN_Init(BTN_DATA *data, void (*callback_1)(void), void (*callback_2)(void), void (*callback_3)(void)) {
btn_data_ptr = data;
btn_data_ptr->callback_function_1 = callback_1;
btn_data_ptr->callback_function_2 = callback_2;
btn_data_ptr->callback_function_3 = callback_3;
 
BTN1_TRIS = 1;
BTN2_TRIS = 1;
BTN3_TRIS = 1;
 
INTDisableInterrupts();
CNCONSET = 0x8000; // Turn on change notice interrupt
#if defined CEREBOT_32MX7
CNENSET = 0x80300; // Set interrupt on CN8/9/19
#elif defined CEREBOT_MX7CK
CNENSET = 0x00300; // Set interrupt on CN8/9
#endif
int32_t tmp = BTN1_PORT;
tmp = BTN2_PORT;
tmp = BTN3_PORT;
IPC6SET = 0xD0000; // Set priority level = 3, sub-priority level = 1
IFS1CLR = 0x1; // Clear interrupt flag
IEC1SET = 0x1; // Enable interrupt
 
INTEnableInterrupts();
}
 
void __ISR(_CHANGE_NOTICE_VECTOR, ipl3) __CN_Interrupt_Handler(void) {
// Upon interrupt, debounce input and call saved function
if (BTN1_PORT == 1) {
Delay_MS(BTN_DEBOUNCE_MS);
if (BTN1_PORT == 1) {
if (btn_data_ptr->callback_function_1 != NULL)
(*btn_data_ptr->callback_function_1)();
}
}
if (BTN2_PORT == 1) {
Delay_MS(BTN_DEBOUNCE_MS);
if (BTN2_PORT == 1) {
if (btn_data_ptr->callback_function_2 != NULL)
(*btn_data_ptr->callback_function_2)();
}
}
#ifdef CEREBOT_32MX7
if (BTN3_PORT == 1) {
Delay_MS(BTN_DEBOUNCE_MS);
if (BTN3_PORT == 1) {
if (btn_data_ptr->callback_function_3 != NULL)
(*btn_data_ptr->callback_function_3)();
}
}
#endif
IFS1CLR = 0x1; // Clear interrupt flag
}
/PIC Projects/Cerebot_32MX7_LED_Cube/PWM2.c
0,0 → 1,21
#include "defines.h"
#include "PWM2.h"
 
void PWM2_Init(void) {
OC2CON = 0x0000;
OC2R = 0x0001; // PWM initial duty cycle
OC2RS = 0x0001; // PWM duty cycle
OC2CON = 0x0006; // PWM off, 16-bit, timer 2, fault pin disabled
 
IFS0CLR = 0x00000100; // Disable Timer 2 interrupt
T2CONSET = 0x8000; // Turn on Timer 2
PR2 = 0x0003; // PWM period ~ 16-20Mhz
}
 
void PWM2_Start(void) {
OC2CONSET = 0x8000;
}
 
void PWM2_Stop(void) {
OC2CONCLR = 0x8000;
}
/PIC Projects/Cerebot_32MX7_LED_Cube/SPI1.c
0,0 → 1,118
#include "defines.h"
#include "SPI1.h"
 
static SPI1_DATA *spi_data_ptr;
 
void SPI1_Init(SPI1_DATA *data, void (*rx_callback)(uint8_t)) {
spi_data_ptr = data;
spi_data_ptr->buffer_out_ind = 0;
spi_data_ptr->buffer_out_len = 0;
spi_data_ptr->rx_callback = rx_callback;
INTDisableInterrupts();
 
// Note: FIFO enhanced buffer depth is 4/8/16 for 32/16/8 bit widths
// Alternative Configuration:
// The third value is the SPI bitrate which is 1/2 the frequency of the
// desired clock frequency. Thus 40Mhz / (20Mhz / 2) = 4.
// Note: SPI_OPEN_TBE_NOT_FULL should only be used at >10Mhz speeds
// SpiChnOpen(SPI_CHANNEL1, SPI_OPEN_MSTEN | SPI_OPEN_ENHBUF | SPI_OPEN_TBE_NOT_FULL | SPI_OPEN_RBF_NOT_EMPTY, 4);
// INTSetVectorPriority(INT_SPI_1_VECTOR, INT_PRIORITY_LEVEL_6);
// INTSetVectorSubPriority(INT_SPI_1_VECTOR, INT_SUB_PRIORITY_LEVEL_1);
// INTClearFlag(INT_SPI1E);
// INTClearFlag(INT_SPI1TX);
// INTClearFlag(INT_SPI1RX);
 
// FSCK = FPB / (2 * (SPIxBRG + 1))
IEC0CLR = 0x03800000; // Disable all SPI interrupts
SPI1CON = 0; // Stops and resets the SPI1.
uint32_t tmp = SPI1BUF; // Clears the receive buffer
IFS0CLR = 0x03800000; // Clear any existing event
IPC5CLR = 0x1F000000; // Clear the priority
IPC5SET = 0x19000000; // Set IPL=6, Subpriority 1
SPI1BRG = 0x1; // Use FPB/4 clock frequency
SPI1STATCLR = 0x40; // Clear the Overflow
#ifndef SPI_WRITE_ONLY
IEC0SET = 0x01800000; // Enable RX and Error interrupts
#endif
// Enhanced buffer, SPI on, 8 bits transfer, SMP=1, Master mode
// SPIxTXIF set on buffer empty, SPIxRXIF set on buffer not empty
SPI1CON = 0x18225;
 
INTEnableInterrupts();
}
 
uint8_t SPI1_Write(uint8_t *array, uint32_t length, void (*tx_callback)(void)) {
spi_data_ptr->tx_callback = tx_callback;
 
if (length > SPI1_BUFFER_OUT_SIZE)
return 0;
if (spi_data_ptr->buffer_out_len != 0)
return 0;
 
// Put the data to send into the outbound buffer
spi_data_ptr->buffer_out_len = length;
spi_data_ptr->buffer_out_ind = length-1;
int32_t i;
for (i = 0; i < length; i++) {
spi_data_ptr->buffer_out[i] = array[i];
}
IEC0SET = 0x02000000; // Enable TX interrupt
return 1;
}
 
void __ISR(_SPI_1_VECTOR, ipl6) __SPI_1_Interrupt_Handler(void) {
#ifndef SPI_WRITE_ONLY
// Process SPI1 error flag
if (IFS0bits.SPI1EIF) {
// Clear the receive overflow bit if it is set
if (SPI1STATbits.SPIROV) {
SPI1STATbits.SPIROV = 0;
}
IFS0CLR = 0x00800000; // Clear the error flag
}
 
// Process SPI1 receive flag
if (IFS0bits.SPI1RXIF) {
int32_t i;
// Read the data received from the last transfer
int32_t rxBufferCount = SPI1STATbits.RXBUFELM;
for (i = 0; i < rxBufferCount; i++) {
int8_t c = SPI1BUF;
// Call the RX callback function on the received data
if (spi_data_ptr->rx_callback != NULL)
(*spi_data_ptr->rx_callback)(c);
}
IFS0CLR = 0x01000000; // Clear the RX flag
}
#endif
 
// Process SPI1 transmit flag
if (IFS0bits.SPI1TXIF && IEC0bits.SPI1TXIE) {
int32_t i;
// Disable the transmit interrupt if all data has been sent
if (spi_data_ptr->buffer_out_len == 0) {
IEC0CLR=0x02000000;
if (spi_data_ptr->tx_callback != NULL)
(*spi_data_ptr->tx_callback)();
} else {
// Start transmitting the data in the buffer
int32_t txBufferFree = 16 - SPI1STATbits.TXBUFELM;
if (spi_data_ptr->buffer_out_len > txBufferFree) {
for (i = 0; i < txBufferFree; i++) {
SPI1BUF = spi_data_ptr->buffer_out[spi_data_ptr->buffer_out_ind];
spi_data_ptr->buffer_out_ind--;
}
spi_data_ptr->buffer_out_len -= txBufferFree;
} else {
for (i = 0; i < spi_data_ptr->buffer_out_len; i++) {
SPI1BUF = spi_data_ptr->buffer_out[spi_data_ptr->buffer_out_ind];
spi_data_ptr->buffer_out_ind--;
}
spi_data_ptr->buffer_out_len = 0;
}
}
IFS0CLR = 0x02000000; // Clear the TX flag
}
}
/PIC Projects/Cerebot_32MX7_LED_Cube/SPI1.h
0,0 → 1,23
#ifndef SPI1_H
#define SPI1_H
 
#define SPI1_BUFFER_OUT_SIZE 300
//#define SPI1_BUFFER_IN_SIZE 10
 
#define SPI_WRITE_ONLY
 
typedef struct {
uint8_t buffer_out[SPI1_BUFFER_OUT_SIZE];
uint32_t buffer_out_ind;
uint32_t buffer_out_len;
 
void (*tx_callback)(void);
void (*rx_callback)(uint8_t);
} SPI1_DATA;
 
void SPI1_Init(SPI1_DATA *data, void (*rx_callback)(uint8_t));
// Note: SPI1_Write() writes MSB -> LSB!
uint8_t SPI1_Write(uint8_t *array, uint32_t length, void (*tx_callback)(void));
 
#endif /* SPI1_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/SPI4.c
0,0 → 1,151
#include "defines.h"
#include "SPI4.h"
 
static SPI4_DATA *spi_data_ptr;
 
void SPI4_Init(SPI4_DATA *data) {
spi_data_ptr = data;
spi_data_ptr->buffer_out_ind = 0;
spi_data_ptr->buffer_out_len = 0;
spi_data_ptr->buffer_in_ind = 0;
spi_data_ptr->buffer_in_len = 0;
spi_data_ptr->write_blank = 0;
 
INTDisableInterrupts();
 
// Note: FIFO enhanced buffer depth is 4/8/16 for 32/16/8 bit widths
 
// FSCK = FPB / (2 * (SPIxBRG + 1))
IEC1CLR = 0x00000700; // Disable all SPI interrupts
SPI4CON = 0; // Stops and resets the SPI4.
uint32_t tmp = SPI4BUF; // Clears the receive buffer
IFS1CLR = 0x00000700; // Clear any existing event
IPC8CLR = 0x0000001F; // Clear the priority
IPC8SET = 0x0000001A; // Set IPL=6, Subpriority 2
SPI4BRG = 0x4; // Use FPB/10 clock frequency
SPI4STATCLR = 0x40; // Clear the Overflow
IEC1SET = 0x00000300; // Enable RX and Error interrupts
 
// Enhanced buffer, SPI on, 8 bits transfer, SMP=1, Master mode
// SPIxTXIF set on buffer empty, SPIxRXIF set on buffer not empty
SPI4CON = 0x18225;
 
INTEnableInterrupts();
}
 
uint8_t SPI4_Read(uint32_t length, void (*rx_callback)(uint8_t, uint8_t *)) {
spi_data_ptr->rx_callback = rx_callback;
 
// Ensure that the receiving buffer is large enough
if (length > SPI4_BUFFER_IN_SIZE)
return 0;
// Ensure that no previous transactions are in progress
if (spi_data_ptr->buffer_in_len != 0)
return 0;
 
spi_data_ptr->write_blank = 1;
spi_data_ptr->buffer_in_len = length;
spi_data_ptr->buffer_in_ind = 0;
SPI4_Write(NULL, length, NULL);
return 1;
}
 
uint8_t SPI4_Write(uint8_t *array, uint32_t length, void (*tx_callback)(void)) {
spi_data_ptr->tx_callback = tx_callback;
 
// We only care about the transmit length if we are sending data
if (length > SPI4_BUFFER_OUT_SIZE && !spi_data_ptr->write_blank)
return 0;
 
// Ensure that no previous transactions are in progress
if (spi_data_ptr->buffer_out_len != 0)
return 0;
 
// Put the data to send into the outbound buffer
spi_data_ptr->buffer_out_len = length;
spi_data_ptr->buffer_out_ind = 0;
 
// Copy only if we are actually going to transmit data
if (!spi_data_ptr->write_blank) {
int32_t i;
for (i = 0; i < length; i++) {
spi_data_ptr->buffer_out[i] = array[i];
}
}
IEC1SET = 0x00000400; // Enable TX interrupt
return 1;
}
 
void __ISR(_SPI_4_VECTOR, ipl6) __SPI_4_Interrupt_Handler(void) {
// Process SPI4 error flag
if (IFS1bits.SPI4EIF) {
// Clear the receive overflow bit if it is set
if (SPI4STATbits.SPIROV) {
SPI4STATbits.SPIROV = 0;
}
IFS1CLR = 0x00000100; // Clear the error flag
}
 
// Process SPI4 receive flag
if (IFS1bits.SPI4RXIF) {
uint32_t i;
// Read the data received from the last transfer
uint32_t rxBufferCount = SPI4STATbits.RXBUFELM;
for (i = 0; i < rxBufferCount; i++) {
int8_t c = SPI4BUF;
// Put the received data into the buffer
if (spi_data_ptr->buffer_in_len != 0) {
spi_data_ptr->buffer_in[spi_data_ptr->buffer_in_ind] = c;
spi_data_ptr->buffer_in_ind++;
// If done acquiring requested length, reset
if (spi_data_ptr->buffer_in_ind == spi_data_ptr->buffer_in_len) {
// Call the RX callback function on the received data
if (spi_data_ptr->rx_callback != NULL)
(*spi_data_ptr->rx_callback)(spi_data_ptr->buffer_in_len, spi_data_ptr->buffer_in);
spi_data_ptr->buffer_in_len = 0;
}
}
}
IFS1CLR = 0x00000200; // Clear the RX flag
}
 
// Process SPI4 transmit flag
if (IFS1bits.SPI4TXIF && IEC1bits.SPI4TXIE) {
int32_t i;
// Disable the transmit interrupt if all data has been sent
if (spi_data_ptr->buffer_out_len == 0) {
IEC1CLR=0x00000400;
spi_data_ptr->write_blank = 0;
// Call the TX callback function at end of transmission
if (spi_data_ptr->tx_callback != NULL)
(*spi_data_ptr->tx_callback)();
} else {
// Start transmitting the data in the buffer
int32_t txBufferFree = 16 - SPI4STATbits.TXBUFELM;
if (spi_data_ptr->buffer_out_len > txBufferFree) {
for (i = 0; i < txBufferFree; i++) {
if (spi_data_ptr->write_blank) {
SPI4BUF = 0x00;
} else {
SPI4BUF = spi_data_ptr->buffer_out[spi_data_ptr->buffer_out_ind];
spi_data_ptr->buffer_out_ind++;
}
}
spi_data_ptr->buffer_out_len -= txBufferFree;
} else {
for (i = 0; i < spi_data_ptr->buffer_out_len; i++) {
if (spi_data_ptr->write_blank) {
SPI4BUF = 0x00;
} else {
SPI4BUF = spi_data_ptr->buffer_out[spi_data_ptr->buffer_out_ind];
spi_data_ptr->buffer_out_ind++;
}
}
spi_data_ptr->buffer_out_len = 0;
}
}
IFS1CLR = 0x00000400; // Clear the TX flag
}
}
/PIC Projects/Cerebot_32MX7_LED_Cube/SPI4.h
0,0 → 1,26
#ifndef SPI4_H
#define SPI4_H
 
#define SPI4_BUFFER_OUT_SIZE 10
#define SPI4_BUFFER_IN_SIZE 10
 
typedef struct {
uint8_t buffer_out[SPI4_BUFFER_OUT_SIZE];
uint32_t buffer_out_ind;
uint32_t buffer_out_len;
uint8_t write_blank;
 
uint8_t buffer_in[SPI4_BUFFER_IN_SIZE];
uint32_t buffer_in_ind;
uint32_t buffer_in_len;
 
void (*tx_callback)(void);
void (*rx_callback)(uint8_t, uint8_t *);
} SPI4_DATA;
 
void SPI4_Init(SPI4_DATA *data);
uint8_t SPI4_Read(uint32_t length, void (*rx_callback)(uint8_t, uint8_t *));
uint8_t SPI4_Write(uint8_t *array, uint32_t length, void (*tx_callback)(void));
 
#endif /* SPI4_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/TIMER5.h
0,0 → 1,13
#ifndef TIMER5_H
#define TIMER5_H
 
typedef struct {
void (*callback_function)(void);
} TIMER5_DATA;
 
void TIMER5_Init(TIMER5_DATA *data, void (*callback)(void), uint32_t time_us);
void TIMER5_Start(void);
void TIMER5_Stop(void);
 
#endif /* TIMER5_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/UART1.h
0,0 → 1,17
#ifndef UART1_H
#define UART1_H
 
#define UART1_BUFFER_SIZE 128
 
typedef struct {
void (*rx_callback)(uint8_t c);
 
uint8_t buffer_out[UART1_BUFFER_SIZE];
uint32_t buffer_out_ind;
uint32_t buffer_out_len;
} UART1_DATA;
 
void UART1_Init(UART1_DATA *data, void (*rx_callback)(uint8_t));
uint8_t UART1_Write(uint8_t *string, uint32_t length);
 
#endif /* UART1_H */
/PIC Projects/Cerebot_32MX7_LED_Cube/glcdfont.h
0,0 → 1,264
#ifndef FONT5X7_H
#define FONT5X7_H
 
// Standard ASCII 5x7 font
// LSB = top of vertical line, 5 lines from left to right
 
const uint8_t font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
/PIC Projects/Cerebot_32MX7_LED_Cube/BTN.h
0,0 → 1,31
#ifndef BTN_H
#define BTN_H
 
// BTN1 = CN8, BTN2 = CN9, BTN3 = CN19 (32MX7 only)
// BTN1 = RG6, BTN2 = RG7, BTN3 = RD13 (32MX7 only)
// Note: Write to PORTx is effectively the same as write to LATx
#define BTN1_TRIS TRISGbits.TRISG6
#define BTN1_PORT PORTGbits.RG6
#define BTN2_TRIS TRISGbits.TRISG7
#define BTN2_PORT PORTGbits.RG7
 
#if defined CEREBOT_32MX7
#define BTN3_TRIS TRISDbits.TRISD13
#define BTN3_PORT PORTDbits.RD13
#elif defined CEREBOT_MX7CK
#define BTN3_TRIS TRISAbits.TRISA0
#define BTN3_PORT PORTAbits.RA0
#endif
 
#define BTN_DEBOUNCE_MS 1
 
typedef struct {
void (*callback_function_1)(void);
void (*callback_function_2)(void);
void (*callback_function_3)(void);
} BTN_DATA;
 
void BTN_Init(BTN_DATA *data, void (*callback_1)(void), void (*callback_2)(void), void (*callback_3)(void));
 
#endif /* BTN_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/PWM2.h
0,0 → 1,9
#ifndef PWM2_H
#define PWM2_H
 
void PWM2_Init(void);
void PWM2_Start(void);
void PWM2_Stop(void);
 
#endif /* PWM2_H */
 
/PIC Projects/Cerebot_32MX7_LED_Cube/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_16F1825_Sabertooth/funclist
0,0 → 1,32
___awdiv: CODE, 3925 0 84
_LED_2_On: CODE, 3201 0 3
_LED_2_Off: CODE, 2045 0 3
_I2C1_Init: CODE, 1856 0 91
_I2C1_Interrupt_Slave: CODE, 1430 0 426
_UART_Read: CODE, 3842 0 83
_I2C1_Read_Buffer: CODE, 3608 0 72
_I2C1_Master_Restart: CODE, 3680 0 79
_UART_Init: CODE, 3431 0 57
_main: CODE, 741 0 689
_Interrupt_Enable: CODE, 2042 0 3
_InterruptHandler: CODE, 4 0 29
_I2C1_Process_Receive: CODE, 3192 0 3
_UART_TX_Interrupt_Handler: CODE, 3488 0 58
_PWM_1_Set: CODE, 3311 0 37
_Interrupt_Init: CODE, 3 0 1
__initialization: CODE, 2037 0 2
_Controller_Read: CODE, 4009 0 87
_I2C1_Configure_Master: CODE, 3385 0 46
_Controller_Init: CODE, 2 0 1
_PWM_1_Init: CODE, 3253 0 27
_PWM_2_Set: CODE, 3348 0 37
_I2C1_Master_Send: CODE, 3759 0 83
_I2C1_Interrupt_Handler: CODE, 3227 0 26
_UART_RX_Interrupt_Handler: CODE, 1947 0 90
_PWM_2_Init: CODE, 3280 0 31
_I2C1_Get_Status: CODE, 3546 0 62
_LED_1_On: CODE, 3195 0 3
_I2C1_Interrupt_Master: CODE, 35 0 706
_LED_1_Off: CODE, 3198 0 3
_Pins_Init: CODE, 3204 0 23
Total: 2945
/PIC Projects/PICX_16F1825_Sabertooth/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_16F1825_Sabertooth/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_16F1825_Sabertooth/main.c
0,0 → 1,235
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "INTERRUPTS.h"
#include "PWM.h"
#include "I2C1.h"
#include "UART.h"
#include "CONTROLLER.h"
 
void Pins_Init(void) {
// Set all pins to digital I/O
ANSELA = 0x0;
ANSELC = 0x0;
 
// // Enable weak pull-up if WPU bit is set
// OPTION_REGbits.nWPUEN = 0;
 
// CCP2 on RC3
APFCON1bits.CCP2SEL = 0;
// TX/CK function on RA0
APFCON0bits.TXCKSEL = 1;
// RX/DT function on RA1
APFCON0bits.RXDTSEL = 1;
 
LED_1_LAT = 1;
LED_1_TRIS = 0;
LED_2_LAT = 0;
LED_2_TRIS = 0;
 
CCP_1_LAT = 0;
CCP_1_TRIS = 0;
CCP_2_LAT = 0;
CCP_2_TRIS = 0;
}
 
void LED_1_On(void) {
LED_1_LAT = 0;
}
 
void LED_1_Off(void) {
LED_1_LAT = 1;
}
 
void LED_2_On(void) {
LED_2_LAT = 1;
}
 
void LED_2_Off(void) {
LED_2_LAT = 0;
}
 
int main(void) {
// Set internal oscillator speed to 32MHz
OSCCONbits.SPLLEN = 1; // 4x PLL enable (overwritten by config bits)
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Initialize I/O
Pins_Init();
 
// Initialize PWM
PWM_1_Init();
PWM_2_Init();
 
// Initialize I2C
I2C1_DATA i2c_data;
I2C1_Init(&i2c_data);
I2C1_Configure_Master(I2C_100KHZ);
 
UART_DATA uart_data;
UART_Init(&uart_data);
 
Controller_Init();
 
// Initialize interrupts
Interrupt_Init();
Interrupt_Enable();
 
PWM_1_Set(PWM_NOMINAL);
PWM_2_Set(PWM_NOMINAL);
 
LED_1_On();
LED_2_On();
 
__delay_ms(1000);
 
LED_1_Off();
LED_2_Off();
 
CTRL_BTN_STATUS ctrl;
Controller_Read(&ctrl);
 
uint16_t pwm_left = PWM_NOMINAL;
uint16_t pwm_right = PWM_NOMINAL;
 
uint8_t median;
int16_t L_X, L_Y, R_X, R_Y;
uint8_t buffer[32];
uint8_t length;
uint8_t uart_state = UART_STATE_READ_CMD;
uint8_t uart_cmd;
 
while (1) {
if (!Controller_Read(&ctrl)) {
median = ctrl.REF / 2;
L_X = (int16_t)median - (int16_t)ctrl.L_X_CH;
L_Y = (int16_t)median - (int16_t)ctrl.L_Y_CH;
R_X = (int16_t)median - (int16_t)ctrl.R_X_CH;
R_Y = (int16_t)median - (int16_t)ctrl.R_Y_CH;
 
// Left stick = throttle, Right stick = steering
// if (L_X > -5 && L_X < 5 &&
// R_Y > -5 && R_Y < 5) {
// pwm_left = PWM_NOMINAL;
// pwm_right = PWM_NOMINAL;
// } else {
// pwm_left = PWM_NOMINAL + (L_X * 4);
// pwm_right = PWM_NOMINAL + (L_X * 4);
//
// pwm_left += R_Y * 4;
// pwm_right -= R_Y * 4;
// }
 
// Left stick = left control, Right stick = right control
if (L_X > -5 && L_X < 5 &&
R_X > -5 && R_X < 5) {
pwm_left = PWM_NOMINAL;
pwm_right = PWM_NOMINAL;
} else {
pwm_left = PWM_NOMINAL + (R_X * 4);
pwm_right = PWM_NOMINAL + (L_X * 4);
}
 
if (L_X < -5 || L_X > 5) LED_2_On();
else LED_2_Off();
 
if (R_X < -5 || R_X > 5) LED_1_On();
else LED_1_Off();
 
 
if (pwm_left > PWM_MAX)
pwm_left = PWM_MAX;
if (pwm_left < PWM_MIN)
pwm_left = PWM_MIN;
 
if (pwm_right > PWM_MAX)
pwm_right = PWM_MAX;
if (pwm_right < PWM_MIN)
pwm_right = PWM_MIN;
 
PWM_1_Set(pwm_left);
PWM_2_Set(pwm_right);
} else {
PWM_1_Set(PWM_NOMINAL);
PWM_2_Set(PWM_NOMINAL);
 
LED_1_Off();
LED_2_Off();
 
// If no controller is attached, switch control to UART
while(1) {
length = UART_Read(buffer);
for (uint8_t i = 0; i < length; i++) {
if (uart_state == UART_STATE_READ_CMD) {
if (buffer[i] == UART_CMD_RESET) {
RESET();
} else {
// Read and save first byte (command)
uart_cmd = buffer[i];
uart_state = UART_STATE_READ_DATA;
}
} else if (uart_state == UART_STATE_READ_DATA) {
uart_state = UART_STATE_READ_CMD;
 
// Process received data
if (uart_cmd == UART_CMD_LEFT_FORWARD) {
pwm_left = PWM_NOMINAL + (uint16_t) (buffer[i] * 2);
if (buffer[i] != 0) LED_2_On();
else LED_2_Off();
} else if (uart_cmd == UART_CMD_LEFT_BACKWARD) {
pwm_left = PWM_NOMINAL - (uint16_t) (buffer[i] * 2);
if (buffer[i] != 0) LED_2_On();
else LED_2_Off();
} else if (uart_cmd == UART_CMD_RIGHT_FORWARD) {
pwm_right = PWM_NOMINAL + (uint16_t) (buffer[i] * 2);
if (buffer[i] != 0) LED_1_On();
else LED_1_Off();
} else if (uart_cmd == UART_CMD_RIGHT_BACKWARD) {
pwm_right = PWM_NOMINAL - (uint16_t) (buffer[i] * 2);
if (buffer[i] != 0) LED_1_On();
else LED_1_Off();
}
 
if (pwm_left > PWM_MAX)
pwm_left = PWM_MAX;
if (pwm_left < PWM_MIN)
pwm_left = PWM_MIN;
 
if (pwm_right > PWM_MAX)
pwm_right = PWM_MAX;
if (pwm_right < PWM_MIN)
pwm_right = PWM_MIN;
 
PWM_1_Set(pwm_right);
PWM_2_Set(pwm_left);
}
}
}
}
}
}
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Mon Apr 21 17:09:08 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Makefile-default.mk
0,0 → 1,220
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c INTERRUPTS.c PWM.c I2C1.c CONTROLLER.c UART.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/PWM.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/CONTROLLER.p1 ${OBJECTDIR}/UART.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/PWM.p1.d ${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/CONTROLLER.p1.d ${OBJECTDIR}/UART.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/PWM.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/CONTROLLER.p1 ${OBJECTDIR}/UART.p1
 
# Source Files
SOURCEFILES=main.c INTERRUPTS.c PWM.c I2C1.c CONTROLLER.c UART.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1825
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/PWM.p1: PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM.p1.d
@${RM} ${OBJECTDIR}/PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/PWM.p1 PWM.c
@-${MV} ${OBJECTDIR}/PWM.d ${OBJECTDIR}/PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/CONTROLLER.p1: CONTROLLER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CONTROLLER.p1.d
@${RM} ${OBJECTDIR}/CONTROLLER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/CONTROLLER.p1 CONTROLLER.c
@-${MV} ${OBJECTDIR}/CONTROLLER.d ${OBJECTDIR}/CONTROLLER.p1.d
@${FIXDEPS} ${OBJECTDIR}/CONTROLLER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/PWM.p1: PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/PWM.p1.d
@${RM} ${OBJECTDIR}/PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/PWM.p1 PWM.c
@-${MV} ${OBJECTDIR}/PWM.d ${OBJECTDIR}/PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/CONTROLLER.p1: CONTROLLER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CONTROLLER.p1.d
@${RM} ${OBJECTDIR}/CONTROLLER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/CONTROLLER.p1 CONTROLLER.c
@-${MV} ${OBJECTDIR}/CONTROLLER.d ${OBJECTDIR}/CONTROLLER.p1.d
@${FIXDEPS} ${OBJECTDIR}/CONTROLLER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/configurations.xml
0,0 → 1,169
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>PWM.h</itemPath>
<itemPath>I2C1.h</itemPath>
<itemPath>CONTROLLER.h</itemPath>
<itemPath>UART.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>PWM.c</itemPath>
<itemPath>I2C1.c</itemPath>
<itemPath>CONTROLLER.c</itemPath>
<itemPath>UART.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1825</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="false"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1825_Sabertooth
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1825_Sabertooth.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1825_Sabertooth.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1825sabertooth.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1825sabertooth.tar
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1825_Sabertooth.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1825sabertooth/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1825sabertooth/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1825sabertooth.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1825sabertooth.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Thu Apr 03 21:51:18 EDT 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.20\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/private/private.xml
0,0 → 1,3
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>
/PIC Projects/PICX_16F1825_Sabertooth/nbproject/project.properties
--- PICX_16F1825_Sabertooth/nbproject/project.xml (nonexistent)
+++ PICX_16F1825_Sabertooth/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1825_Sabertooth</name>
+ <creation-uuid>a37f9b7c-e474-41b7-9a5b-bc6808e97a44</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1825_Sabertooth/INTERRUPTS.c
0,0 → 1,58
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "UART.h"
 
void Interrupt_Init() {
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// Check to see if we have an I2C interrupt
if (PIR1bits.SSP1IF) {
 
// Call the handler
I2C1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSP1IF = 0;
 
return;
}
 
if (PIR1bits.RCIF) {
 
// Call the handler
UART_RX_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.RCIF = 0;
 
return;
}
 
if (PIR1bits.TXIF) {
 
// Call the handler
UART_TX_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.TXIF = 0;
 
return;
}
 
}
/PIC Projects/PICX_16F1825_Sabertooth/UART.c
0,0 → 1,106
#include <xc.h>
#include "defines.h"
#include "UART.h"
 
static UART_DATA *data_ptr;
 
void UART_Init(UART_DATA *data) {
data_ptr = data;
 
APFCON0bits.RXDTSEL = 1; // Change RX from RB5 to RC5
APFCON0bits.TXCKSEL = 1; // Change TX from RB7 to RC4
UART_RX_TRIS = 1;
UART_TX_TRIS = 0;
 
SPBRG = 16; // Set baud rate to 115200 @ 32MHz
BAUDCONbits.BRG16 = 0; // 8-bit baud rate generator
TXSTAbits.BRGH = 1; // High baud rate select
 
TXSTAbits.SYNC = 0; // Async operation
RCSTAbits.CREN = 1; // Enable reception module
TXSTAbits.TXEN = 1; // Enable transmission module
RCSTAbits.SPEN = 1; // Enable EUSART module
 
PIE1bits.RCIE = 1; // UART RX interrupt starts enabled
PIE1bits.TXIE = 0; // UART TX interrupt starts disabled
 
// Initialize local variables
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
data_ptr->buffer_in_len = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
 
void UART_TX_Interrupt_Handler(void) {
// Send more data when transmit buffer is empty
if (data_ptr->buffer_out_ind != data_ptr->buffer_out_len) {
TXREG = data_ptr->buffer_out[data_ptr->buffer_out_ind];
data_ptr->buffer_out_ind++;
} else {
// Stop processing TX interrupts if there is no more data to send
while (!TXSTAbits.TRMT);
PIE1bits.TXIE = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
}
 
void UART_RX_Interrupt_Handler(void) {
char c = RCREG;
 
// Read received data into buffer
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = c;
if (data_ptr->buffer_in_write_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_write_ind = 0;
} else {
data_ptr->buffer_in_write_ind++;
}
 
// Increment read counter to keep only the latest data
if (data_ptr->buffer_in_len < UART_BUFFER_SIZE) {
data_ptr->buffer_in_len++;
} else {
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
 
// Reset receiver module on overrun error
if (RCSTAbits.OERR == 1) {
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
}
 
void UART_Write(char *data, char length) {
// Ensure that no transmission is currently running
while (PIE1bits.TXIE);
 
data_ptr->buffer_out_len = length;
data_ptr->buffer_out_ind = 0;
for (char i = 0; i < length; i++) {
data_ptr->buffer_out[i] = data[i];
}
 
// Start transmission
PIE1bits.TXIE = 1;
}
 
char UART_Read(char *buffer) {
PIE1bits.RCIE = 0; // Disable receiver interrupt
char length = data_ptr->buffer_in_len;
for (char i = 0; i < length; i++) {
buffer[i] = data_ptr->buffer_in[data_ptr->buffer_in_read_ind];
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
data_ptr->buffer_in_len -= length;
PIE1bits.RCIE = 1; // Re-enable receiver interrupt
return length;
}
/PIC Projects/PICX_16F1825_Sabertooth/UART.h
0,0 → 1,25
#ifndef UART_H
#define UART_H
 
#define UART_BUFFER_SIZE 30
 
typedef struct {
char buffer_in[UART_BUFFER_SIZE];
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_in_len;
 
char buffer_out[UART_BUFFER_SIZE];
char buffer_out_ind;
char buffer_out_len;
} UART_DATA;
 
void UART_Init(UART_DATA *data);
void UART_Write(char *data, char length);
char UART_Read(char *buffer);
 
void UART_TX_Interrupt_Handler(void);
void UART_RX_Interrupt_Handler(void);
 
#endif /* UART_H */
 
/PIC Projects/PICX_16F1825_Sabertooth/defines.h
0,0 → 1,45
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
//#define CONTROL_FROM_CONTROLLER
#define CONTROL_FROM_UART
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
#define LED_1_TRIS TRISCbits.TRISC2
#define LED_1_LAT LATCbits.LATC2
 
#define LED_2_TRIS TRISCbits.TRISC4
#define LED_2_LAT LATCbits.LATC4
 
#define CCP_1_TRIS TRISCbits.TRISC5
#define CCP_1_LAT LATCbits.LATC5
 
#define CCP_2_TRIS TRISCbits.TRISC3
#define CCP_2_LAT LATCbits.LATC3
 
#define I2C_1_CLK_TRIS TRISCbits.TRISC0
#define I2C_1_DAT_TRIS TRISCbits.TRISC1
 
#define UART_RX_TRIS TRISAbits.TRISA1
#define UART_TX_TRIS TRISAbits.TRISA0
// </editor-fold>
 
#define _XTAL_FREQ 32000000
 
#define PWM_NOMINAL 1500
#define PWM_MAX 1950
#define PWM_MIN 1050
 
#define UART_STATE_READ_CMD 0x1
#define UART_STATE_READ_DATA 0x2
 
#define UART_CMD_RESET 0x1
#define UART_CMD_LEFT_FORWARD 0x2
#define UART_CMD_LEFT_BACKWARD 0x3
#define UART_CMD_RIGHT_FORWARD 0x4
#define UART_CMD_RIGHT_BACKWARD 0x5
 
#endif /* DEFINES_H */
/PIC Projects/PICX_16F1825_Sabertooth/CONTROLLER.c
0,0 → 1,38
#include "defines.h"
#include "CONTROLLER.h"
#include "I2C1.h"
 
void Controller_Init(void) {
 
}
 
uint8_t Controller_Read(CTRL_BTN_STATUS *btns) {
uint8_t buffer[8];
uint8_t result, length, ret = 1;
 
// Read in the button values for each controller
I2C1_Master_Restart(CONTROLLER_ADDRESS, CONTROLLER_CMD_READ, 6);
do {
result = I2C1_Get_Status();
} while (!result);
if (result == I2C_RECV_OK) {
ret = 0;
 
// Save the read values
length = I2C1_Read_Buffer(buffer);
 
btns->REF = buffer[0];
btns->L_X_CH = buffer[1];
btns->L_Y_CH = buffer[2];
btns->R_X_CH = buffer[3];
btns->R_Y_CH = buffer[4];
btns->BTN = buffer[5];
}
 
return ret;
}
 
void Controller_Set_Led(uint8_t value) {
uint8_t c = value;
I2C1_Master_Send(CONTROLLER_ADDRESS, &c, 1);
}
/PIC Projects/PICX_16F1825_Sabertooth/CONTROLLER.h
0,0 → 1,23
#ifndef CONTROLLERS_H
#define CONTROLLERS_H
 
#define CONTROLLER_CMD_READ 0xA
#define CONTROLLER_CMD_WRITE 0xB
 
#define CONTROLLER_ADDRESS 0x10
 
typedef struct {
uint8_t REF;
uint8_t L_X_CH;
uint8_t L_Y_CH;
uint8_t R_X_CH;
uint8_t R_Y_CH;
uint8_t BTN;
} CTRL_BTN_STATUS;
 
void Controller_Init(void);
uint8_t Controller_Read(CTRL_BTN_STATUS *btns);
void Controller_Set_Led(uint8_t value);
 
#endif /* CONTROLLERS_H */
 
/PIC Projects/PICX_16F1825_Sabertooth/I2C1.c
0,0 → 1,534
#include "defines.h"
#include "I2C1.h"
 
static I2C1_DATA *i2c_data_p;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(I2C1_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint8_t length) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, &c, 1);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C1_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1ADD = addr << 1; // Set the slave address
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x6; // Enable Slave 7-bit address
SSP1STATbits.SMP = 1; // Slew Off
SSP1CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON3bits.PCIE = 1; // Interrupt on stop condition
SSP1CON3bits.SCIE = 0; // Disable interrupt on start condition
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
void I2C1_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C1_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C1_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C1_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSP1BUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C1_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSP1CON1bits.SSPOV == 1) {
SSP1CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP1STATbits.BF == 1) {
received_data = SSP1BUF;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// // Ignore anything except a start
// if (SSP1STATbits.S == 1) {
// i2c_data_p->buffer_in_len_tmp = 0;
// i2c_data_p->operating_state = I2C_STARTED;
// }
// break;
// }
// case I2C_STARTED:
// {
// In this case, we expect either an address or a stop bit
if (SSP1STATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
i2c_data_p->buffer_in_len_tmp = 0;
if (SSP1STATbits.D_nA == 0) {
// Address received
if (SSP1STATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NOADDR;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C1_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP1BUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSP1BUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP1STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP1STATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP1CON1bits.CKP == 0) {
SSP1CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C1_Process_Receive(uint8_t c) {
uint8_t ret = 0;
 
return ret;
}
/PIC Projects/PICX_16F1825_Sabertooth/I2C1.h
0,0 → 1,82
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 32
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2C1BUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C1_DATA;
 
void I2C1_Init(I2C1_DATA *data);
void I2C1_Interrupt_Handler(void);
void I2C1_Interrupt_Slave(void);
void I2C1_Interrupt_Master(void);
void I2C1_Configure_Slave(uint8_t address);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint8_t length);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
uint8_t I2C1_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1825_Sabertooth/INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1825_Sabertooth/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_16F1825_Sabertooth/PWM.c
0,0 → 1,68
#include "defines.h"
#include "PWM.h"
 
void PWM_1_Init(void) {
// Output pin initially blocked
CCP_1_TRIS = 1;
 
/* Initialize PWM module */
// PWM period = (PRx + 1] * 4 * 1/FOSC * TMRx_prescale
PR2 = 255; // 2ms @ 32MHz
CCP1CONbits.P1M = 0b00; // Single output, P1A modulated only
CCP1CONbits.CCP1M = 0b1100; // PWM mode, P1A active-high, P1B active-high
CCPTMRSbits.C1TSEL = 0b00; // CCP1 timer based off Timer2
 
// Idle the output till width is specified
// Pulse width = (CCPRxL:CCPxCON) * 1/FOSC * TMRx_prescale
CCPR1L = 0x00;
CCP1CONbits.DC1B = 0b00;
 
/* Initialize Timer 2 */
PIR1bits.TMR2IF = 0; // Clear the interrupt flag for Timer 2
T2CONbits.T2CKPS = 0b11; // Set a prescaler of 64
T2CONbits.TMR2ON = 1; // Enable the timer
 
// Wait for the timer to overflow before enabling output
while (!PIR1bits.TMR2IF);
CCP_1_TRIS = 0;
}
 
void PWM_2_Init(void) {
// Output pin initially blocked
CCP_2_TRIS = 1;
 
/* Initialize PWM module */
PR4 = 255; // 2ms @ 32MHz
// PWM period = (PRx + 1] * 4 * 1/FOSC * TMRx_prescale
CCP2CONbits.P2M = 0b00; // Single output, P2A modulated only
CCP2CONbits.CCP2M = 0b1100; // PWM mode, P2A active-high, P2B active-high
CCPTMRSbits.C2TSEL = 0b01; // CCP2 timer based off Timer4
 
// Idle the output till width is specified
// Pulse width = (CCPRxL:CCPxCON) * 1/FOSC * TMRx_prescale
CCPR2L = 0x00;
CCP2CONbits.DC2B = 0b00;
 
/* Initialize Timer 2 */
PIR3bits.TMR4IF = 0; // Clear the interrupt flag for Timer 2
T4CONbits.T4CKPS = 0b11; // Set a prescaler of 64
T4CONbits.TMR4ON = 1; // Enable the timer
 
// Wait for the timer to overflow before enabling output
while (!PIR3bits.TMR4IF);
CCP_2_TRIS = 0;
}
 
void PWM_1_Set(uint16_t width_us) {
// Set the pulse duration to the requested width
int value = width_us / 2;
CCPR1L = value >> 2;
CCP1CONbits.DC1B = value;
}
 
void PWM_2_Set(uint16_t width_us) {
// Set the pulse duration to the requested width
int value = width_us / 2;
CCPR2L = value >> 2;
CCP2CONbits.DC2B = value;
}
/PIC Projects/PICX_16F1825_Sabertooth/PWM.h
0,0 → 1,11
#ifndef PWM_H
#define PWM_H
 
void PWM_1_Init(void);
void PWM_2_Init(void);
 
void PWM_1_Set(uint16_t width);
void PWM_2_Set(uint16_t width);
 
#endif /* PWM_H */
 
/PIC Projects/PICX_16F1829_Analog_Controller/ADC.c
0,0 → 1,24
#include "defines.h"
#include "ADC.h"
 
void ADC_Init(void) {
ADCON0bits.ADON = 0; // Turn off ADC module
ADCON1bits.ADFM = 1; // Right justified data
ADCON1bits.ADCS = 0b110; // A/D conversion clock = FOSC/64
ADCON1bits.ADNREF = 0; // Negative reference is VSS
ADCON1bits.ADPREF = 0b00; // Positive reference is VDD
}
 
uint16_t ADC_Read(uint8_t channel) {
uint16_t ret;
 
ADCON0bits.CHS = channel; // Set channel
ADCON0bits.ADON = 1; // Turn ADC on
__delay_us(10); // Wait the acquisition time
ADCON0bits.GO_nDONE = 1; // Start conversion
while (ADCON0bits.GO_nDONE == 1); // Wait for conversion to finish
ret = ADRESH << 8; // Read ADC value
ret |= ADRESL;
 
return ret;
}
/PIC Projects/PICX_16F1829_Analog_Controller/ADC.h
0,0 → 1,9
#ifndef ADC_H
#define ADC_H
 
void ADC_Init(void);
 
uint16_t ADC_Read(uint8_t channel);
 
#endif /* ADC_H */
 
/PIC Projects/PICX_16F1829_Analog_Controller/I2C1.c
0,0 → 1,549
#include "defines.h"
#include "I2C1.h"
 
static I2C1_DATA *i2c_data_p;
extern uint8_t btn_values[6];
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(I2C1_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C1_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1ADD = addr << 1; // Set the slave address
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x6; // Enable Slave 7-bit address
SSP1STATbits.SMP = 1; // Slew Off
SSP1CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON3bits.PCIE = 1; // Interrupt on stop condition
SSP1CON3bits.SCIE = 0; // Disable interrupt on start condition
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
void I2C1_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C1_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C1_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C1_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSP1BUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C1_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSP1CON1bits.SSPOV == 1) {
SSP1CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP1STATbits.BF == 1) {
received_data = SSP1BUF;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// // Ignore anything except a start
// if (SSP1STATbits.S == 1) {
// i2c_data_p->buffer_in_len_tmp = 0;
// i2c_data_p->operating_state = I2C_STARTED;
// }
// break;
// }
// case I2C_STARTED:
// {
// In this case, we expect either an address or a stop bit
if (SSP1STATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
i2c_data_p->buffer_in_len_tmp = 0;
if (SSP1STATbits.D_nA == 0) {
// Address received
if (SSP1STATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NOADDR;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C1_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP1BUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSP1BUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP1STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP1STATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP1CON1bits.CKP == 0) {
SSP1CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C1_Process_Receive(uint8_t c) {
uint8_t ret = 0;
switch (c) {
case CMD_QUERY_BTN:
i2c_data_p->buffer_out[0] = btn_values[0];
i2c_data_p->buffer_out[1] = btn_values[1];
i2c_data_p->buffer_out[2] = btn_values[2];
i2c_data_p->buffer_out[3] = btn_values[3];
i2c_data_p->buffer_out[4] = btn_values[4];
i2c_data_p->buffer_out[5] = btn_values[5];
i2c_data_p->buffer_out_len = 6;
ret = 1;
break;
default:
break;
}
return ret;
}
/PIC Projects/PICX_16F1829_Analog_Controller/I2C1.h
0,0 → 1,82
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 32
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2C1BUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C1_DATA;
 
void I2C1_Init(I2C1_DATA *data);
void I2C1_Interrupt_Handler(void);
void I2C1_Interrupt_Slave(void);
void I2C1_Interrupt_Master(void);
void I2C1_Configure_Slave(uint8_t address);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
uint8_t I2C1_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1829_Analog_Controller/INTERRUPTS.c
0,0 → 1,39
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
 
void Interrupt_Init() {
 
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
// Check to see if we have an I2C1 interrupt
if (PIR1bits.SSP1IF) {
// Call the handler
I2C1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSP1IF = 0;
}
 
// // Check to see if we have an IO interrupt
// if (INTCONbits.IOCIF) {
// // Call the handler
// IO_Interrupt();
//
// return;
// }
}
/PIC Projects/PICX_16F1829_Analog_Controller/INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1829_Analog_Controller/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_16F1829_Analog_Controller/defines.h
0,0 → 1,56
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
 
#define I2C_1_CLK_TRIS TRISBbits.TRISB6
#define I2C_1_DAT_TRIS TRISBbits.TRISB4
 
#define ANALOG_L_BTN_TRIS TRISAbits.TRISA5
#define ANALOG_R_BTN_TRIS TRISAbits.TRISA2
 
#define ANALOG_L_BTN_WPU WPUAbits.WPUA5
#define ANALOG_R_BTN_WPU WPUAbits.WPUA2
 
#define ANALOG_L_BTN_PORT PORTAbits.RA5
#define ANALOG_R_BTN_PORT PORTAbits.RA2
 
#define ANALOG_L_X_TRIS TRISCbits.TRISC3
#define ANALOG_L_Y_TRIS TRISAbits.TRISA4
 
#define ANALOG_L_X_ANSEL ANSELCbits.ANSC3
#define ANALOG_L_Y_ANSEL ANSELAbits.ANSA4
 
#define ANALOG_R_X_TRIS TRISCbits.TRISC7
#define ANALOG_R_Y_TRIS TRISCbits.TRISC6
 
#define ANALOG_R_X_ANSEL ANSELCbits.ANSC7
#define ANALOG_R_Y_ANSEL ANSELCbits.ANSC6
 
#define LED_A_TRIS TRISCbits.TRISC5
#define LED_A_LAT LATCbits.LATC5
#define LED_B_TRIS TRISCbits.TRISC4
#define LED_B_LAT LATCbits.LATC4
 
// </editor-fold>
 
#define _XTAL_FREQ 32000000
 
#define CMD_QUERY_BTN 0x0A
#define CMD_SET_LEDS 0x0B
 
#define I2C1_SLAVE_ADDR 0x10
 
#define ANALOG_L_X_CH 7
#define ANALOG_L_Y_CH 3
 
#define ANALOG_R_X_CH 9
#define ANALOG_R_Y_CH 8
 
#define ANALOG_REF_CH 6
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_16F1829_Analog_Controller/funclist
0,0 → 1,17
_I2C1_Init: CODE, 1132 0 78
_I2C1_Interrupt_Slave: CODE, 618 0 359
_main: CODE, 977 0 155
_Interrupt_Enable: CODE, 1440 0 3
_LED_Off: CODE, 1443 0 3
_InterruptHandler: CODE, 4 0 13
_I2C1_Process_Receive: CODE, 1210 0 70
_Interrupt_Init: CODE, 1449 0 1
__initialization: CODE, 1430 0 7
_I2C1_Interrupt_Handler: CODE, 1397 0 22
_IO_Init: CODE, 1332 0 34
_I2C1_Configure_Slave: CODE, 1366 0 31
_ADC_Read: CODE, 1280 0 52
_LED_On: CODE, 1446 0 3
_ADC_Init: CODE, 1419 0 11
_I2C1_Interrupt_Master: CODE, 19 0 599
Total: 1441
/PIC Projects/PICX_16F1829_Analog_Controller/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_16F1829_Analog_Controller/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_16F1829_Analog_Controller/main.c
0,0 → 1,129
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT software controlled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "ADC.h"
 
uint8_t btn_values[6];
 
void IO_Init(void) {
ANSELA = 0x0;
ANSELB = 0x0;
ANSELC = 0x0;
 
WPUA = 0x0;
WPUB = 0x0;
WPUC = 0x0;
 
OPTION_REGbits.nWPUEN = 0;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
ANALOG_L_BTN_TRIS = 1;
ANALOG_R_BTN_TRIS = 1;
 
ANALOG_L_BTN_WPU = 1;
ANALOG_R_BTN_WPU = 1;
 
ANALOG_L_X_TRIS = 1;
ANALOG_L_Y_TRIS = 1;
 
ANALOG_R_X_TRIS = 1;
ANALOG_R_Y_TRIS = 1;
 
ANALOG_L_X_ANSEL = 1;
ANALOG_L_Y_ANSEL = 1;
 
ANALOG_R_X_ANSEL = 1;
ANALOG_R_Y_ANSEL = 1;
 
LED_A_LAT = 0;
LED_B_LAT = 0;
LED_A_TRIS = 0;
LED_B_TRIS = 0;
}
 
void LED_On(void) {
LED_A_LAT = 1;
}
 
void LED_Off(void) {
LED_A_LAT = 0;
}
 
int main(void) {
 
// Set internal oscillator speed to 32MHz
OSCCONbits.SPLLEN = 1; // 4x PLL enable (overwritten by config bits)
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Initialize I/O
IO_Init();
 
// Delay a bit to allow I2C lines to stabilize
__delay_ms(10);
 
// Initialize I2C1 in slave mode
I2C1_DATA i2c1_data;
I2C1_Init(&i2c1_data);
I2C1_Configure_Slave(I2C1_SLAVE_ADDR);
 
// Initialize ADC
ADC_Init();
// Initialize interrupts
Interrupt_Init();
Interrupt_Enable();
 
LED_On();
__delay_ms(1000);
LED_Off();
 
uint8_t buffer[8];
uint8_t length, result;
 
while (1) {
btn_values[0] = ADC_Read(ANALOG_REF_CH) >> 2; // 0xFF
btn_values[1] = ADC_Read(ANALOG_L_X_CH) >> 2; // 0x7E (-1)
btn_values[2] = ADC_Read(ANALOG_L_Y_CH) >> 2; // 0x7C (-3)
btn_values[3] = ADC_Read(ANALOG_R_X_CH) >> 2; // 0x81 (+2)
btn_values[4] = ADC_Read(ANALOG_R_Y_CH) >> 2; // 0x7D (-2)
btn_values[5] = (ANALOG_L_BTN_PORT << 1) | ANALOG_R_BTN_PORT;
 
// // Check if an I2C message was received
// result = I2C1_Get_Status();
// if (result) {
// length = I2C1_Read_Buffer(buffer);
// if (length == 2 && buffer[0] == CMD_SET_LEDS) {
// if (buffer[1])
// LED_On();
// else
// LED_Off();
// }
// }
}
}
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Makefile-default.mk
0,0 → 1,188
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c I2C1.c INTERRUPTS.c ADC.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/ADC.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/ADC.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/ADC.p1
 
# Source Files
SOURCEFILES=main.c I2C1.c INTERRUPTS.c ADC.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1829
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/ADC.p1: ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ADC.p1.d
@${RM} ${OBJECTDIR}/ADC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/ADC.p1 ADC.c
@-${MV} ${OBJECTDIR}/ADC.d ${OBJECTDIR}/ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/ADC.p1: ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ADC.p1.d
@${RM} ${OBJECTDIR}/ADC.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/ADC.p1 ADC.c
@-${MV} ${OBJECTDIR}/ADC.d ${OBJECTDIR}/ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sun Apr 06 01:52:36 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1829_Analog_Controller
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1829_Analog_Controller.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1829_Analog_Controller.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1829analogcontroller.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1829analogcontroller.tar
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1829_Analog_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1829analogcontroller/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1829analogcontroller/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1829analogcontroller.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1829analogcontroller.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/configurations.xml
0,0 → 1,165
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>I2C1.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>ADC.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>I2C1.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>ADC.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1829</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="require"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Mon Feb 24 19:41:18 EST 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.20\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/private/private.xml
0,0 → 1,6
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/C:/Users/Kevin/Documents/Code/PICX_16F1829_Analog_Controller/main.c</file>
</open-files>
</project-private>
/PIC Projects/PICX_16F1829_Analog_Controller/nbproject/project.properties
--- PICX_16F1829_Analog_Controller/nbproject/project.xml (nonexistent)
+++ PICX_16F1829_Analog_Controller/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1829_Analog_Controller</name>
+ <creation-uuid>a37f9b7c-e474-41b7-9a5b-bc6808e97a44</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_12F1840_Clock/I2C1.c
0,0 → 1,318
#include "defines.h"
#include "I2C1.h"
 
extern I2C1_DATA i2c_data;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(void) {
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
i2c_data.buffer_in_len = 0;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
i2c_data.operating_state = I2C_IDLE;
i2c_data.return_status = 0;
 
i2c_data.master_dest_addr = 0;
i2c_data.master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (uint8_t i = 0; i < length; i++) {
i2c_data.buffer_in[i] = msg[i];
}
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data.buffer_in[0] = msg;
i2c_data.buffer_in_len = length;
i2c_data.master_dest_addr = address;
i2c_data.buffer_in_read_ind = 0;
i2c_data.buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data.operating_state = I2C_SEND_ADDR;
i2c_data.master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
void I2C1_Interrupt_Handler() {
// If we are in the middle of sending data
if (i2c_data.master_status == I2C_MASTER_SEND) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data.master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data.buffer_in_read_ind < i2c_data.buffer_in_len) {
SSP1BUF = i2c_data.buffer_in[i2c_data.buffer_in_read_ind];
i2c_data.buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data.master_status == I2C_MASTER_RECV) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data.operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data.master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data.buffer_in[i2c_data.buffer_in_write_ind] = SSP1BUF;
i2c_data.buffer_in_write_ind++;
if (i2c_data.buffer_in_write_ind < i2c_data.buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data.operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data.operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data.master_status == I2C_MASTER_RESTART) {
switch (i2c_data.operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data.master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data.buffer_in[0];
i2c_data.operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data.operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data.operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data.master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data.buffer_in[i2c_data.buffer_in_write_ind] = SSP1BUF;
i2c_data.buffer_in_write_ind++;
if (i2c_data.buffer_in_write_ind < i2c_data.buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data.operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data.operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data.operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data.operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data.master_status = I2C_MASTER_IDLE;
i2c_data.return_status = I2C_RECV_OK;
break;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
// if (i2c_data.operating_mode == I2C_MODE_MASTER) {
if (i2c_data.master_status != I2C_MASTER_IDLE || i2c_data.buffer_in_len == 0) {
return 0;
} else {
return i2c_data.return_status;
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data.buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data.buffer_in_len != 0) {
buffer[i] = i2c_data.buffer_in[i2c_data.buffer_in_read_ind];
i++;
if (i2c_data.buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data.buffer_in_read_ind = 0;
} else {
i2c_data.buffer_in_read_ind++;
}
i2c_data.buffer_in_len--;
}
return i;
}
/PIC Projects/PICX_12F1840_Clock/NEOPIXEL.c
0,0 → 1,167
#include "defines.h"
#include "NEOPIXEL.h"
 
extern NEOPIXEL_DATA neopixel_data;
 
void NeoPixel_Init(void) {
 
// Clear buffer
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data.values[i] = 0x0;
}
 
neopixel_data.offset = 0;
 
// Output pin initially blocked
NEOPIXEL_TRIS = 1;
 
/* Initialize PWM module */
PR2 = 0x09; // 1.25us @ 32MHz
CCP1CONbits.P1M = 0b00; // Single output, P1A modulated only
CCP1CONbits.CCP1M = 0b1100; // PWM mode, P1A active-high, P1B active-high
 
// Idle the output till width is specified
CCPR1L = 0x00;
CCP1CONbits.DC1B = 0b00;
 
/* Initialize Timer 2 */
PIR1bits.TMR2IF = 0; // Clear the interrupt flag for Timer 2
T2CONbits.T2CKPS = 0b00; // Set a prescaler of 1:1
T2CONbits.TMR2ON = 1; // Enable the timer
 
// Wait for the timer to overflow before enabling output
while (!PIR1bits.TMR2IF);
NEOPIXEL_TRIS = 0;
}
 
void NeoPixel_Offet(uint8_t value) {
neopixel_data.offset = value;
}
 
void NeoPixel_Clear(void) {
// Clear buffer
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data.values[i] = 0x0;
}
}
 
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier) {
uint8_t i = ((index + neopixel_data.offset) % NEOPIXEL_LENGTH);
if (G == 0)
neopixel_data.values[(i * 3) + 0] = 0;
else
neopixel_data.values[(i * 3) + 0] = (G * multiplier) - 1;
if (R == 0)
neopixel_data.values[(i * 3) + 1] = 0;
else
neopixel_data.values[(i * 3) + 1] = (R * multiplier) - 1;
if (B == 0)
neopixel_data.values[(i * 3) + 2] = 0;
else
neopixel_data.values[(i * 3) + 2] = (B * multiplier) - 1;
}
 
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier) {
uint8_t i = ((index + neopixel_data.offset) % NEOPIXEL_LENGTH);
 
if (G != 0)
neopixel_data.values[(i * 3) + 0] |= (G * multiplier) - 1;
if (R != 0)
neopixel_data.values[(i * 3) + 1] |= (R * multiplier) - 1;
if (B != 0)
neopixel_data.values[(i * 3) + 2] |= (B * multiplier) - 1;
}
 
void NeoPixel_Write_All(void) {
for (uint8_t i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
NeoPixel_Write_One(neopixel_data.values[i]);
}
// Delay for 50us to latch data
__delay_us(50);
}
 
void NeoPixel_Write_One(uint8_t value) {
// Enable timer and wait for it to overflow
T2CONbits.TMR2ON = 1;
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 7
if (value & 0x80) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 6
if (value & 0x40) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 5
if (value & 0x20) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 4
if (value & 0x10) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 3
if (value & 0x08) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 2
if (value & 0x04) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 1
if (value & 0x02) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 0
if (value & 0x01) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
 
// Idle line low
while (!PIR1bits.TMR2IF);
asm("NOP");
asm("NOP");
asm("NOP");
asm("NOP");
asm("NOP");
CCPR1L = 0b00000000;
 
// Disable and reset timer
while (!PIR1bits.TMR2IF);
asm("NOP");
asm("NOP");
T2CONbits.TMR2ON = 0;
TMR2 = 0x0;
}
/PIC Projects/PICX_12F1840_Clock/NEOPIXEL.h
0,0 → 1,34
#ifndef NEOPIXEL_H
#define NEOPIXEL_H
 
#define NEOPIXEL_LENGTH 60
 
#define NEOPIXEL_LOGIC_1 0b00000110
#define NEOPIXEL_LOGIC_0 0b00000011
 
// Color Definitions (base of 16 levels)
#define CLEAR 0x00,0x00,0x00
#define RED 0x10,0x00,0x00
#define ORANGE 0x08,0x02,0x00
#define YELLOW 0x08,0x08,0x00
#define GREEN 0x00,0x10,0x00
#define TEAL 0x00,0x08,0x04
#define BLUE 0x00,0x00,0x10
#define PURPLE 0x08,0x00,0x08
#define WHITE 0x08,0x08,0x08
 
typedef struct {
uint8_t values[NEOPIXEL_LENGTH * 3];
uint8_t offset;
} NEOPIXEL_DATA;
 
void NeoPixel_Init(void);
void NeoPixel_Offet(uint8_t value);
void NeoPixel_Clear(void);
void NeoPixel_Set(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier);
void NeoPixel_Or(uint8_t index, uint8_t R, uint8_t G, uint8_t B, uint8_t multiplier);
void NeoPixel_Write_All(void);
void NeoPixel_Write_One(uint8_t value);
 
#endif /* NEOPIXEL_H */
 
/PIC Projects/PICX_12F1840_Clock/TSL2561.c
0,0 → 1,216
#include "defines.h"
#include "I2C1.h"
#include "TSL2561.h"
 
extern TSL2561_DATA tsl2561_data;
 
void TSL2561_Init(uint8_t address) {
tsl2561_data.address = address;
tsl2561_data.integration = TSL2561_INTEGRATIONTIME_13MS;
tsl2561_data.gain = TSL2561_GAIN_16X;
 
uint8_t buffer[1];
I2C1_Master_Restart(tsl2561_data.address, TSL2561_REGISTER_ID, 1);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(buffer);
 
// Set default integration time and gain
TSL2561_Set_Timing(tsl2561_data.integration);
TSL2561_Set_Gain(tsl2561_data.gain);
 
// Start the chip in power-down mode
TSL2561_Disable();
}
 
void TSL2561_Enable() {
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
 
void TSL2561_Disable() {
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
 
void TSL2561_Set_Gain(tsl2561Gain_t gain) {
TSL2561_Enable();
tsl2561_data.gain = gain;
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data.integration | tsl2561_data.gain);
TSL2561_Disable();
}
 
void TSL2561_Set_Timing(tsl2561IntegrationTime_t integration) {
TSL2561_Enable();
tsl2561_data.integration = integration;
TSL2561_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data.integration | tsl2561_data.gain);
TSL2561_Disable();
}
 
uint32_t TSL2561_Calculate_Lux(uint16_t ch0, uint16_t ch1) {
uint32_t chScale, channel0, channel1, ratio1, ratio, temp, lux;
uint16_t b, m;
 
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: // No scaling ... integration time = 402ms
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
}
 
// Scale for gain (1x or 16x)
if (!tsl2561_data.gain)
chScale = chScale << 4;
 
// scale the channel values
channel0 = (ch0 * chScale) >> TSL2561_LUX_CHSCALE;
channel1 = (ch1 * chScale) >> TSL2561_LUX_CHSCALE;
 
// find the ratio of the channel values (Channel1/Channel0)
ratio1 = 0;
if (channel0 != 0)
ratio1 = (channel1 << (TSL2561_LUX_RATIOSCALE+1)) / channel0;
 
// round the ratio value
ratio = (ratio1 + 1) >> 1;
 
#ifdef TSL2561_PACKAGE_CS
if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1C)) {
b = TSL2561_LUX_B1C; m = TSL2561_LUX_M1C;
} else if (ratio <= TSL2561_LUX_K2C) {
b = TSL2561_LUX_B2C; m = TSL2561_LUX_M2C;
} else if (ratio <= TSL2561_LUX_K3C) {
b = TSL2561_LUX_B3C; m = TSL2561_LUX_M3C;
} else if (ratio <= TSL2561_LUX_K4C) {
b = TSL2561_LUX_B4C; m = TSL2561_LUX_M4C;
} else if (ratio <= TSL2561_LUX_K5C) {
b = TSL2561_LUX_B5C; m = TSL2561_LUX_M5C;
} else if (ratio <= TSL2561_LUX_K6C) {
b = TSL2561_LUX_B6C; m = TSL2561_LUX_M6C;
} else if (ratio <= TSL2561_LUX_K7C) {
b = TSL2561_LUX_B7C; m = TSL2561_LUX_M7C;
} else if (ratio > TSL2561_LUX_K8C) {
b = TSL2561_LUX_B8C; m = TSL2561_LUX_M8C;
}
#else
// if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1T)) {
if ((ratio <= TSL2561_LUX_K1T)) {
b = TSL2561_LUX_B1T; m = TSL2561_LUX_M1T;
} else if (ratio <= TSL2561_LUX_K2T) {
b = TSL2561_LUX_B2T; m = TSL2561_LUX_M2T;
} else if (ratio <= TSL2561_LUX_K3T) {
b = TSL2561_LUX_B3T; m = TSL2561_LUX_M3T;
} else if (ratio <= TSL2561_LUX_K4T) {
b = TSL2561_LUX_B4T; m = TSL2561_LUX_M4T;
} else if (ratio <= TSL2561_LUX_K5T) {
b = TSL2561_LUX_B5T; m = TSL2561_LUX_M5T;
} else if (ratio <= TSL2561_LUX_K6T) {
b = TSL2561_LUX_B6T; m = TSL2561_LUX_M6T;
} else if (ratio <= TSL2561_LUX_K7T) {
b = TSL2561_LUX_B7T; m = TSL2561_LUX_M7T;
} else if (ratio > TSL2561_LUX_K8T) {
b = TSL2561_LUX_B8T; m = TSL2561_LUX_M8T;
}
#endif
// temp = ((channel0 * b) - (channel1 * m));
// TODO: Change this back once they fix compiler
temp = (channel0 * b);
temp -= (channel1 * m);
 
// // do not allow negative lux value
// if (temp < 0)
// temp = 0;
 
// round lsb (2^(LUX_SCALE-1))
temp += (1 << (TSL2561_LUX_LUXSCALE-1));
 
// strip off fractional portion
lux = temp >> TSL2561_LUX_LUXSCALE;
 
return lux;
}
 
uint32_t TSL2561_Get_Full_Luminosity() {
uint32_t x;
 
// Enable the device by setting the control bit to 0x03
TSL2561_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
__delay_ms(15);
break;
case TSL2561_INTEGRATIONTIME_101MS:
__delay_ms(105);
break;
default:
__delay_ms(405);
break;
}
 
x = TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
 
TSL2561_Disable();
 
return x;
}
 
uint16_t TSL2561_Get_Luminosity(uint8_t channel) {
// Enable the device by setting the control bit to 0x03
TSL2561_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data.integration) {
case TSL2561_INTEGRATIONTIME_13MS:
__delay_ms(15);
break;
case TSL2561_INTEGRATIONTIME_101MS:
__delay_ms(105);
break;
default:
__delay_ms(405);
break;
}
 
if (channel == 0) {
// Reads two byte value from channel 0 (visible + infrared)
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
} else if (channel == 1) {
// Reads two byte value from channel 1 (infrared)
return TSL2561_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
}
 
TSL2561_Disable();
 
// Unknown channel!
return 0;
}
 
void TSL2561_Write_2_Bytes(uint8_t reg, uint8_t value) {
uint8_t buffer[2];
buffer[0] = reg;
buffer[1] = value;
I2C1_Master_Send(tsl2561_data.address, 2, buffer);
while (!I2C1_Get_Status());
}
 
uint16_t TSL2561_Read_2_Bytes(uint8_t reg) {
uint8_t buffer[2];
uint16_t ret;
 
I2C1_Master_Restart(tsl2561_data.address, reg, 2);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(buffer);
ret = buffer[1] << 8;
ret |= buffer[0];
 
return ret;
}
/PIC Projects/PICX_12F1840_Clock/funclist
0,0 → 1,35
___awdiv: CODE, 1571 0 84
_DS3231_Init: CODE, 4000 0 29
_I2C1_Init: CODE, 3834 0 18
_I2C1_Read_Buffer: CODE, 4058 0 38
_TSL2561_Set_Timing: CODE, 3874 0 22
_I2C1_Master_Restart: CODE, 1930 0 45
___awmod: CODE, 1655 0 72
_TSL2561_Disable: CODE, 3751 0 6
_main: CODE, 19 0 394
_Interrupt_Enable: CODE, 3748 0 3
_InterruptHandler: CODE, 4 0 13
_TSL2561_Write_2_Bytes: CODE, 4029 0 29
__initialization: CODE, 3919 0 21
_DS3231_Get_Status: CODE, 3896 0 23
___lwdiv: CODE, 1727 0 55
_I2C1_Configure_Master: CODE, 3971 0 29
_TSL2561_Read_2_Bytes: CODE, 1882 0 48
_NeoPixel_Or: CODE, 1066 0 158
_DS3231_Get_Time: CODE, 1224 0 155
_NeoPixel_Set: CODE, 804 0 262
_I2C1_Master_Send: CODE, 1782 0 50
_I2C1_Interrupt_Handler: CODE, 413 0 391
_NeoPixel_Init: CODE, 1832 0 50
_TSL2561_Init: CODE, 1975 0 44
_NeoPixel_Clear: CODE, 3817 0 17
_TSL2561_Set_Gain: CODE, 3852 0 22
_NeoPixel_Offet: CODE, 3766 0 10
_NeoPixel_Write_One: CODE, 1379 0 101
_I2C1_Get_Status: CODE, 3776 0 12
___wmul: CODE, 2019 0 29
_NeoPixel_Write_All: CODE, 3943 0 28
_TSL2561_Get_Luminosity: CODE, 1480 0 91
___bmul: CODE, 3800 0 17
_TSL2561_Enable: CODE, 3757 0 9
Total: 2375
/PIC Projects/PICX_12F1840_Clock/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_12F1840_Clock/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_12F1840_Clock/main.c
0,0 → 1,114
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "NEOPIXEL.h"
#include "DS3231.h"
#include "TSL2561.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
/* Config Register CONFIGL @ 0x8007 */
#pragma config CPD = OFF // Data memory code protection is disabled
#pragma config BOREN = OFF // Brown-out Reset disabled
#pragma config IESO = OFF // Internal/External Switchover mode is disabled
#pragma config FOSC = INTOSC // INTOSC oscillator: I/O function on CLKIN pin
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor is disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config WDTE = OFF // WDT disabled
#pragma config CP = OFF // Program memory code protection is disabled
#pragma config PWRTE = ON // PWRT enabled
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
 
/* Config Register CONFIG2 @ 0x8008 */
#pragma config PLLEN = ON // 4x PLL disabled
#pragma config WRT = OFF // Write protection off
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
#pragma config BORV = HI // Brown-out Reset Voltage (Vbor), high trip point selected.
#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming
// </editor-fold>
 
I2C1_DATA i2c_data;
NEOPIXEL_DATA neopixel_data;
TSL2561_DATA tsl2561_data;
DS3231_TIME time;
 
int main() {
// Oscillator configuration (32Mhz HFINTOSC)
OSCCONbits.SCS = 0b00;
OSCCONbits.IRCF = 0b1110;
ANSELA = 0x00; // All pins set to digital I/O
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
WPUA = 0x00; // Disable weak pull-ups
 
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
while (!OSCSTATbits.HFIOFS);
 
Interrupt_Enable();
 
I2C1_Init();
I2C1_Configure_Master(I2C_1MHZ);
 
NeoPixel_Init();
NeoPixel_Offet(30);
 
DS3231_Init();
 
TSL2561_Init(TSL2561_ADDR_FLOAT);
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
// TSL2561_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
TSL2561_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
uint16_t full;
uint8_t multiplier, multiplier_2;
 
// time.sec = 0;
// time.min = 16;
// time.hour = 7;
// time.h_mil = 0;
// time.h_am_pm = 1;
//
// DS3231_Set_Time(&time);
 
while(1) {
// ~37200 seems to be the max value at 16X gain, 101ms period
full = TSL2561_Get_Luminosity(0);
multiplier = (full / 3100) + 1; // 12 levels (1-12)
multiplier_2 = (multiplier / 7) + 1; // 2 levels (1-2)
 
// NeoPixel_Clear();
// for (uint8_t i = 0; i < multiplier; i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00, 1);
// }
// NeoPixel_Write_All();
 
DS3231_Get_Time(&time);
NeoPixel_Clear();
 
// Draw markers
NeoPixel_Set(00, RED, multiplier_2);
NeoPixel_Set(30, RED, multiplier_2);
NeoPixel_Set(05, ORANGE, multiplier_2);
NeoPixel_Set(35, ORANGE, multiplier_2);
NeoPixel_Set(10, YELLOW, multiplier_2);
NeoPixel_Set(40, YELLOW, multiplier_2);
NeoPixel_Set(15, GREEN, multiplier_2);
NeoPixel_Set(45, GREEN, multiplier_2);
NeoPixel_Set(20, BLUE, multiplier_2);
NeoPixel_Set(50, BLUE, multiplier_2);
NeoPixel_Set(25, PURPLE, multiplier_2);
NeoPixel_Set(55, PURPLE, multiplier_2);
 
// Draw time
NeoPixel_Or((time.hour * 5) % 60, BLUE, multiplier + 4);
NeoPixel_Or(time.min, GREEN, multiplier + 4);
NeoPixel_Or(time.sec, RED, multiplier + 4);
NeoPixel_Write_All();
}
}
/PIC Projects/PICX_12F1840_Clock/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sun Mar 30 17:07:11 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_12F1840_Clock/nbproject/Makefile-default.mk
0,0 → 1,220
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c NEOPIXEL.c INTERRUPTS.c I2C1.c DS3231.c TSL2561.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/DS3231.p1 ${OBJECTDIR}/TSL2561.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/NEOPIXEL.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/DS3231.p1.d ${OBJECTDIR}/TSL2561.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/DS3231.p1 ${OBJECTDIR}/TSL2561.p1
 
# Source Files
SOURCEFILES=main.c NEOPIXEL.c INTERRUPTS.c I2C1.c DS3231.c TSL2561.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=12F1840
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/NEOPIXEL.p1: NEOPIXEL.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/NEOPIXEL.p1.d
@${RM} ${OBJECTDIR}/NEOPIXEL.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/NEOPIXEL.p1 NEOPIXEL.c
@-${MV} ${OBJECTDIR}/NEOPIXEL.d ${OBJECTDIR}/NEOPIXEL.p1.d
@${FIXDEPS} ${OBJECTDIR}/NEOPIXEL.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/DS3231.p1: DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/DS3231.p1.d
@${RM} ${OBJECTDIR}/DS3231.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/DS3231.p1 DS3231.c
@-${MV} ${OBJECTDIR}/DS3231.d ${OBJECTDIR}/DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TSL2561.p1: TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TSL2561.p1.d
@${RM} ${OBJECTDIR}/TSL2561.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TSL2561.p1 TSL2561.c
@-${MV} ${OBJECTDIR}/TSL2561.d ${OBJECTDIR}/TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/NEOPIXEL.p1: NEOPIXEL.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/NEOPIXEL.p1.d
@${RM} ${OBJECTDIR}/NEOPIXEL.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/NEOPIXEL.p1 NEOPIXEL.c
@-${MV} ${OBJECTDIR}/NEOPIXEL.d ${OBJECTDIR}/NEOPIXEL.p1.d
@${FIXDEPS} ${OBJECTDIR}/NEOPIXEL.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/DS3231.p1: DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/DS3231.p1.d
@${RM} ${OBJECTDIR}/DS3231.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/DS3231.p1 DS3231.c
@-${MV} ${OBJECTDIR}/DS3231.d ${OBJECTDIR}/DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TSL2561.p1: TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TSL2561.p1.d
@${RM} ${OBJECTDIR}/TSL2561.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TSL2561.p1 TSL2561.c
@-${MV} ${OBJECTDIR}/TSL2561.d ${OBJECTDIR}/TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" --ram=default,-160-16f -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_12F1840_Clock/nbproject/configurations.xml
0,0 → 1,169
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>NEOPIXEL.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>I2C1.h</itemPath>
<itemPath>DS3231.h</itemPath>
<itemPath>TSL2561.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>NEOPIXEL.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>I2C1.c</itemPath>
<itemPath>DS3231.c</itemPath>
<itemPath>TSL2561.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC12F1840</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0xfff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0xfff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_Clock/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_12F1840_Clock
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_12F1840_Clock/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_12F1840_Clock/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_12F1840_Clock.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_12F1840_Clock.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx12f1840clock.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx12f1840clock.tar
/PIC Projects/PICX_12F1840_Clock/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_12F1840_Clock.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx12f1840clock/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx12f1840clock/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx12f1840clock.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx12f1840clock.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_12F1840_Clock/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Mon Mar 10 00:43:05 EDT 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_12F1840_Clock/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.20\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_Clock/nbproject/private/private.xml
0,0 → 1,3
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>
/PIC Projects/PICX_12F1840_Clock/nbproject/project.properties
--- PICX_12F1840_Clock/nbproject/project.xml (nonexistent)
+++ PICX_12F1840_Clock/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_12F1840_Clock</name>
+ <creation-uuid>7fe93e92-3ae3-42d5-9338-2afa3dbfcf6b</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_12F1840_Clock/DS3231.c
0,0 → 1,113
#include "defines.h"
#include "DS3231.h"
#include "I2C1.h"
 
void DS3231_Init() {
uint8_t reg[3];
reg[0] = DS3231_CONTROL;
/* Control Register (0x0E)
* Bit 7 - !EOSC
* Bit 6 - BBSQW
* Bit 5 - CONV
* Bit 4 - RS2
* Bit 3 - RS1
* Bit 2 - INTCN
* Bit 1 - A2IE
* Bit 0 - A1IE
*/
reg[1] = 0x04;
 
/* Control Register 2 (0x0F)
* Bit 3 = EN32kHZ
*/
reg[2] = 0x00;
 
// Set the configuration registers
I2C1_Master_Send(DS3231_ADDRESS, 3, reg);
while (!I2C1_Get_Status());
}
 
uint8_t DS3231_Get_Status(void) {
/* Status Register (0x0F)
* Bit 7 - OSF
* Bit 3 - EN32kHz
* Bit 2 - BSY
* Bit 1 - A2F
* Bit 0 - A1F
*/
uint8_t value;
I2C1_Master_Restart(DS3231_ADDRESS, 0x0F, 1);
while (!I2C1_Get_Status());
I2C1_Read_Buffer(&value);
return value;
}
 
void DS3231_Set_Time(DS3231_TIME *time) {
 
// Format the data in a way that the chip expects
#ifndef DS3231_TIME_ONLY
uint8_t output[8];
#else
uint8_t output[4];
#endif
output[0] = DS3231_SECONDS;
output[1] = ((time->sec / 10) << 4) | (time->sec % 10);
output[2] = ((time->min / 10) << 4) | (time->min % 10);
output[3] = ((time->hour / 10) << 4) | (time->hour % 10);
#ifndef DS3231_TIME_ONLY
if (!time->h_mil) {
output[3] |= (time->h_am_pm) ? 0x60 : 0x40;
}
output[4] = time->day;
output[5] = ((time->date / 10) << 4) | (time->date % 10);
output[6] = ((time->month / 10) << 4) | (time->month % 10);
output[7] = ((time->year / 10) << 4) | (time->year % 10);
#endif
 
// Check the status to make sure that it isnt currently busy
while (DS3231_Get_Status() & 0x04);
 
// Write the data to the chip
#ifndef DS3231_TIME_ONLY
I2C1_Master_Send(DS3231_ADDRESS, 8, output);
#else
I2C1_Master_Send(DS3231_ADDRESS, 4, output);
#endif
while (!I2C1_Get_Status());
}
 
void DS3231_Get_Time(DS3231_TIME *time) {
 
// Check the status to make sure that it isnt currently busy
while (DS3231_Get_Status() & 0x04);
 
// Request time data from the chip
#ifndef DS3231_TIME_ONLY
uint8_t input[7];
I2C1_Master_Restart(DS3231_ADDRESS, 0x00, 7);
#else
uint8_t input[3];
I2C1_Master_Restart(DS3231_ADDRESS, 0x00, 3);
#endif
while (!I2C1_Get_Status());
I2C1_Read_Buffer(input);
 
// Parse BCD format into decimal and return
time->sec = ((input[0] >> 4) * 10) + (input[0] & 0x0F);
time->min = ((input[1] >> 4) * 10) + (input[1] & 0x0F);
if (input[2] & 0x40) {
time->h_mil = 0;
time->h_am_pm = (input[2] & 0x20) ? 1 : 0;
time->hour = (((input[2] >> 4) & 0x01) * 10) + (input[2] & 0x0F);
} else {
time->h_mil = 1;
time->hour = ((input[2] >> 4) * 10) + (input[2] & 0x0F);
}
#ifndef DS3231_TIME_ONLY
time->day = input[3];
time->date = ((input[4] >> 4) * 10) + (input[4] & 0x0F);
time->month = ((input[5] >> 4) * 10) + (input[5] & 0x0F);
time->year = ((input[6] >> 4) * 10) + (input[6] & 0x0F);
#endif
}
/PIC Projects/PICX_12F1840_Clock/DS3231.h
0,0 → 1,54
#ifndef RTC_DS3231_H
#define RTC_DS3231_H
 
#define DS3231_ADDRESS 0x68
 
#define DS3231_SECONDS 0x00
#define DS3231_MINUTES 0x01
#define DS3231_HOUR 0x02
#define DS3231_DAY 0x03
#define DS3231_DATE 0x04
#define DS3231_MONTH 0x05
#define DS3231_YEAR 0x06
 
#define DS3231_ALARM1_SECONDS 0x07
#define DS3231_ALARM1_MINUTES 0x08
#define DS3231_ALARM1_HOUR 0x09
#define DS3231_ALARM1_DAY_DATE 0x0A
 
#define DS3231_ALARM2_MINUTES 0x0B
#define DS3231_ALARM2_HOUR 0x0C
#define DS3231_ALARM2_DAY_DATE 0x0D
 
#define DS3231_CONTROL 0x0E
#define DS3231_STATUS 0x0F
 
#define DS3231_TIME_ONLY
 
typedef struct {
uint8_t sec;
uint8_t min;
uint8_t hour;
uint8_t h_mil;
uint8_t h_am_pm;
#ifndef DS3231_TIME_ONLY
uint8_t day;
uint8_t date;
uint8_t month;
uint8_t year;
#endif
} DS3231_TIME;
 
void DS3231_Init(void);
 
uint8_t DS3231_Get_Status(void);
 
void DS3231_Set_Time(DS3231_TIME *time);
 
void DS3231_Get_Time(DS3231_TIME *time);
 
//void DS3231_Set_Alarm1(uint8_t sec, uint8_t min, uint8_t hour, uint8_t date, bit mil, bit am_pm, bit dt_dy);
//void DS3231_Set_Alarm2(uint8_t min, uint8_t hour, uint8_t date, bit mil, bit am_pm, bit dt_dy);
 
#endif
 
/PIC Projects/PICX_12F1840_Clock/I2C1.h
0,0 → 1,69
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 8
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
} I2C1_DATA;
 
void I2C1_Init(void);
void I2C1_Interrupt_Handler(void);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
 
#endif
/PIC Projects/PICX_12F1840_Clock/INTERRUPTS.c
0,0 → 1,41
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
 
void Interrupt_Enable() {
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
}
 
void interrupt InterruptHandler(void) {
// Check to see if we have an I2C1 interrupt
if (PIR1bits.SSP1IF) {
I2C1_Interrupt_Handler();
PIR1bits.SSP1IF = 0;
}
 
//#ifndef UART_TX_ONLY
// // Check to see if we have an interrupt on USART1 RX
// if (PIR1bits.RCIF) {
// UART_Recv_Interrupt_Handler();
// PIR1bits.RCIF = 0;
// if (INTCONbits.TMR0IF)
// tmr0_rollover = 1;
// }
//#endif
 
// // Check to see if we have an interrupt on USART1 TX
// if (PIR1bits.TXIF) {
// UART_Send_Interrupt_Handler();
//// PIR1bits.TXIF = 0;
// if (INTCONbits.TMR0IF)
// tmr0_rollover = 1;
// }
 
}
/PIC Projects/PICX_12F1840_Clock/TSL2561.h
0,0 → 1,131
#ifndef LUX_TSL2561_H
#define LUX_TSL2561_H
 
#define TSL2561_VISIBLE 2 // channel 0 - channel 1
#define TSL2561_INFRARED 1 // channel 1
#define TSL2561_FULLSPECTRUM 0 // channel 0
 
// 3 i2c address options!
#define TSL2561_ADDR_LOW 0x29
#define TSL2561_ADDR_FLOAT 0x39
#define TSL2561_ADDR_HIGH 0x49
 
// Lux calculations differ slightly for CS package
//#define TSL2561_PACKAGE_CS
#define TSL2561_PACKAGE_T_FN_CL
 
#define TSL2561_READBIT (0x01)
 
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
#define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
#define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
#define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write
 
#define TSL2561_CONTROL_POWERON (0x03)
#define TSL2561_CONTROL_POWEROFF (0x00)
 
#define TSL2561_LUX_LUXSCALE (14) // Scale by 2^14
#define TSL2561_LUX_RATIOSCALE (9) // Scale ratio by 2^9
#define TSL2561_LUX_CHSCALE (10) // Scale channel values by 2^10
#define TSL2561_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^TSL2561_LUX_CHSCALE
#define TSL2561_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^TSL2561_LUX_CHSCALE
 
// T, FN and CL package values
#define TSL2561_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
#define TSL2561_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
#define TSL2561_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
#define TSL2561_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
#define TSL2561_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
#define TSL2561_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
#define TSL2561_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
#define TSL2561_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
#define TSL2561_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
#define TSL2561_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
#define TSL2561_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
#define TSL2561_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
#define TSL2561_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
#define TSL2561_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
#define TSL2561_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
#define TSL2561_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
#define TSL2561_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
#define TSL2561_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
#define TSL2561_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
#define TSL2561_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
 
// CS package values
#define TSL2561_LUX_K1C (0x0043) // 0.130 * 2^RATIO_SCALE
#define TSL2561_LUX_B1C (0x0204) // 0.0315 * 2^LUX_SCALE
#define TSL2561_LUX_M1C (0x01ad) // 0.0262 * 2^LUX_SCALE
#define TSL2561_LUX_K2C (0x0085) // 0.260 * 2^RATIO_SCALE
#define TSL2561_LUX_B2C (0x0228) // 0.0337 * 2^LUX_SCALE
#define TSL2561_LUX_M2C (0x02c1) // 0.0430 * 2^LUX_SCALE
#define TSL2561_LUX_K3C (0x00c8) // 0.390 * 2^RATIO_SCALE
#define TSL2561_LUX_B3C (0x0253) // 0.0363 * 2^LUX_SCALE
#define TSL2561_LUX_M3C (0x0363) // 0.0529 * 2^LUX_SCALE
#define TSL2561_LUX_K4C (0x010a) // 0.520 * 2^RATIO_SCALE
#define TSL2561_LUX_B4C (0x0282) // 0.0392 * 2^LUX_SCALE
#define TSL2561_LUX_M4C (0x03df) // 0.0605 * 2^LUX_SCALE
#define TSL2561_LUX_K5C (0x014d) // 0.65 * 2^RATIO_SCALE
#define TSL2561_LUX_B5C (0x0177) // 0.0229 * 2^LUX_SCALE
#define TSL2561_LUX_M5C (0x01dd) // 0.0291 * 2^LUX_SCALE
#define TSL2561_LUX_K6C (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6C (0x0101) // 0.0157 * 2^LUX_SCALE
#define TSL2561_LUX_M6C (0x0127) // 0.0180 * 2^LUX_SCALE
#define TSL2561_LUX_K7C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7C (0x0037) // 0.00338 * 2^LUX_SCALE
#define TSL2561_LUX_M7C (0x002b) // 0.00260 * 2^LUX_SCALE
#define TSL2561_LUX_K8C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8C (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8C (0x0000) // 0.000 * 2^LUX_SCALE
 
enum {
TSL2561_REGISTER_CONTROL = 0x00,
TSL2561_REGISTER_TIMING = 0x01,
TSL2561_REGISTER_THRESHHOLDL_LOW = 0x02,
TSL2561_REGISTER_THRESHHOLDL_HIGH = 0x03,
TSL2561_REGISTER_THRESHHOLDH_LOW = 0x04,
TSL2561_REGISTER_THRESHHOLDH_HIGH = 0x05,
TSL2561_REGISTER_INTERRUPT = 0x06,
TSL2561_REGISTER_CRC = 0x08,
TSL2561_REGISTER_ID = 0x0A,
TSL2561_REGISTER_CHAN0_LOW = 0x0C,
TSL2561_REGISTER_CHAN0_HIGH = 0x0D,
TSL2561_REGISTER_CHAN1_LOW = 0x0E,
TSL2561_REGISTER_CHAN1_HIGH = 0x0F
};
 
typedef enum {
TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms
TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms
TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms
} tsl2561IntegrationTime_t;
 
typedef enum {
TSL2561_GAIN_0X = 0x00, // No gain
TSL2561_GAIN_16X = 0x10 // 16x gain
} tsl2561Gain_t;
 
typedef struct __TSL25611_DATA {
uint8_t address;
tsl2561IntegrationTime_t integration;
tsl2561Gain_t gain;
} TSL2561_DATA;
 
void TSL2561_Init(uint8_t address);
void TSL2561_Enable(void);
void TSL2561_Disable(void);
void TSL2561_Set_Timing(tsl2561IntegrationTime_t integration);
void TSL2561_Set_Gain(tsl2561Gain_t gain);
uint32_t TSL2561_Calculate_Lux(uint16_t ch0, uint16_t ch1);
uint32_t TSL2561_Get_Full_Luminosity(void);
uint16_t TSL2561_Get_Luminosity(uint8_t channel);
 
void TSL2561_Write_2_Bytes(uint8_t reg, uint8_t value);
uint16_t TSL2561_Read_2_Bytes(uint8_t reg);
 
#endif /* LUX_TSL2561_H */
 
/PIC Projects/PICX_12F1840_Clock/defines.h
0,0 → 1,15
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// Preprocessor define for __delay_ms() and __delay_us()
#define _XTAL_FREQ 32000000
 
#define NEOPIXEL_TRIS TRISAbits.TRISA5
#define I2C_1_CLK_TRIS TRISAbits.TRISA1
#define I2C_1_DAT_TRIS TRISAbits.TRISA2
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_12F1840_Clock/INTERRUPTS.h
0,0 → 1,12
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandlerHigh(void);
 
#endif
/PIC Projects/PICX_12F1840_Clock/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_12F1840_NeoPixel/INTERRUPTS.c
0,0 → 1,41
#include <xc.h>
#include "defines.h"
#include "INTERRUPTS.h"
 
void Interrupt_Enable() {
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
}
 
void interrupt InterruptHandler(void) {
// // Check to see if we have an I2C interrupt
// if (PIR1bits.SSPIF) {
// I2C_Interrupt_Handler();
// PIR1bits.SSPIF = 0;
// }
 
//#ifndef UART_TX_ONLY
// // Check to see if we have an interrupt on USART1 RX
// if (PIR1bits.RCIF) {
// UART_Recv_Interrupt_Handler();
// PIR1bits.RCIF = 0;
// if (INTCONbits.TMR0IF)
// tmr0_rollover = 1;
// }
//#endif
 
// // Check to see if we have an interrupt on USART1 TX
// if (PIR1bits.TXIF) {
// UART_Send_Interrupt_Handler();
//// PIR1bits.TXIF = 0;
// if (INTCONbits.TMR0IF)
// tmr0_rollover = 1;
// }
 
}
/PIC Projects/PICX_12F1840_NeoPixel/INTERRUPTS.h
0,0 → 1,12
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandlerHigh(void);
 
#endif
/PIC Projects/PICX_12F1840_NeoPixel/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_12F1840_NeoPixel/NEOPIXEL.c
0,0 → 1,136
#include <xc.h>
#include "defines.h"
#include "NEOPIXEL.h"
 
static NEOPIXEL_DATA* neopixel_data_ptr;
 
void NeoPixel_Init(NEOPIXEL_DATA *data) {
neopixel_data_ptr = data;
 
// Clear buffer
for (char i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
neopixel_data_ptr->values[i] = 0x0;
}
 
// Output pin initially blocked
NEOPIXEL_TRIS = 1;
 
/* Initialize PWM module */
PR2 = 0x09; // 1.25us @ 32MHz
CCP1CONbits.P1M = 0b00; // Single output, P1A modulated only
CCP1CONbits.CCP1M = 0b1100; // PWM mode, P1A active-high, P1B active-high
 
// Idle the output till width is specified
CCPR1L = 0x00;
CCP1CONbits.DC1B = 0b00;
 
/* Initialize Timer 2 */
PIR1bits.TMR2IF = 0; // Clear the interrupt flag for Timer 2
T2CONbits.T2CKPS = 0b00; // Set a prescaler of 1:1
T2CONbits.TMR2ON = 1; // Enable the timer
 
// Wait for the timer to overflow before enabling output
while (!PIR1bits.TMR2IF);
NEOPIXEL_TRIS = 0;
}
 
void NeoPixel_Set(char index, char R, char G, char B) {
if (index >= NEOPIXEL_LENGTH) return;
 
neopixel_data_ptr->values[(index * 3) + 0] = G;
neopixel_data_ptr->values[(index * 3) + 1] = R;
neopixel_data_ptr->values[(index * 3) + 2] = B;
}
 
void NeoPixel_Write_All(void) {
for (char i = 0; i < NEOPIXEL_LENGTH * 3; i++) {
NeoPixel_Write_One(neopixel_data_ptr->values[i]);
}
// Delay for 50us to latch data
__delay_us(50);
}
 
void NeoPixel_Write_One(char value) {
// Enable timer and wait for it to overflow
T2CONbits.TMR2ON = 1;
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 7
if (value & 0x80) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 6
if (value & 0x40) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 5
if (value & 0x20) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 4
if (value & 0x10) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 3
if (value & 0x08) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 2
if (value & 0x04) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 1
if (value & 0x02) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
while (!PIR1bits.TMR2IF);
 
// Set pulse width for bit 0
if (value & 0x01) {
CCPR1L = NEOPIXEL_LOGIC_1; // ~800ns high, ~450ns low (logic 1)
} else {
CCPR1L = NEOPIXEL_LOGIC_0; // ~400ns high, ~850ns low (logic 0)
}
 
// Idle line low
while (!PIR1bits.TMR2IF);
asm("NOP");
asm("NOP");
asm("NOP");
asm("NOP");
asm("NOP");
CCPR1L = 0b00000000;
 
// Disable and reset timer
while (!PIR1bits.TMR2IF);
asm("NOP");
asm("NOP");
T2CONbits.TMR2ON = 0;
TMR2 = 0x0;
}
/PIC Projects/PICX_12F1840_NeoPixel/NEOPIXEL.h
0,0 → 1,30
#ifndef NEOPIXEL_H
#define NEOPIXEL_H
 
#define NEOPIXEL_LENGTH 60
 
#define NEOPIXEL_LOGIC_1 0b00000110
#define NEOPIXEL_LOGIC_0 0b00000011
 
// Color Definitions
#define CLEAR 0x00,0x00,0x00
#define RED 0xFF,0x00,0x00
#define ORANGE 0x8F,0x20,0x00
#define YELLOW 0x8F,0x8F,0x00
#define GREEN 0x00,0xFF,0x00
#define TEAL 0x00,0x8F,0x40
#define BLUE 0x00,0x00,0xFF
#define PURPLE 0x8F,0x00,0x8F
#define WHITE 0x6F,0x6F,0x6F
 
typedef struct {
char values[NEOPIXEL_LENGTH * 3];
} NEOPIXEL_DATA;
 
void NeoPixel_Init(NEOPIXEL_DATA *data);
void NeoPixel_Set(char index, char R, char G, char B);
void NeoPixel_Write_All(void);
void NeoPixel_Write_One(char value);
 
#endif /* NEOPIXEL_H */
 
/PIC Projects/PICX_12F1840_NeoPixel/defines.h
0,0 → 1,10
#ifndef DEFINES_H
#define DEFINES_H
 
// Preprocessor define for __delay_ms() and __delay_us()
#define _XTAL_FREQ 32000000
 
#define NEOPIXEL_TRIS TRISAbits.TRISA5
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_12F1840_NeoPixel/funclist
0,0 → 1,10
___awmod: CODE, 404 0 71
_main: CODE, 13 0 185
_InterruptHandler: CODE, 4 0 7
__initialization: CODE, 591 0 12
_NeoPixel_Set: CODE, 198 0 105
_NeoPixel_Init: CODE, 475 0 55
_NeoPixel_Write_One: CODE, 303 0 101
___wmul: CODE, 562 0 29
_NeoPixel_Write_All: CODE, 530 0 32
Total: 597
/PIC Projects/PICX_12F1840_NeoPixel/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_12F1840_NeoPixel/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_12F1840_NeoPixel/main.c
0,0 → 1,63
#include <xc.h>
#include "defines.h"
#include "INTERRUPTS.h"
#include "NEOPIXEL.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
/* Config Register CONFIGL @ 0x8007 */
#pragma config CPD = OFF // Data memory code protection is disabled
#pragma config BOREN = OFF // Brown-out Reset disabled
#pragma config IESO = OFF // Internal/External Switchover mode is disabled
#pragma config FOSC = INTOSC // INTOSC oscillator: I/O function on CLKIN pin
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor is disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config WDTE = OFF // WDT disabled
#pragma config CP = OFF // Program memory code protection is disabled
#pragma config PWRTE = OFF // PWRT disabled
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
 
/* Config Register CONFIG2 @ 0x8008 */
#pragma config PLLEN = ON // 4x PLL disabled
#pragma config WRT = OFF // Write protection off
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
#pragma config BORV = HI // Brown-out Reset Voltage (Vbor), high trip point selected.
#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming
// </editor-fold>
 
NEOPIXEL_DATA neopixel_data;
 
int main() {
 
// Oscillator configuration (32Mhz HFINTOSC)
OSCCONbits.SCS = 0b00;
OSCCONbits.IRCF = 0b1110;
ANSELA = 0x00; // All pins set to digital I/O
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
 
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
while (!OSCSTATbits.HFIOFS);
 
// Interrupt_Enable();
NeoPixel_Init(&neopixel_data);
 
for (char i = 0; i < 60; i++) {
if (i % 6 == 0)
NeoPixel_Set(i, RED);
else if (i % 6 == 1)
NeoPixel_Set(i, ORANGE);
else if (i % 6 == 2)
NeoPixel_Set(i, YELLOW);
else if (i % 6 == 3)
NeoPixel_Set(i, GREEN);
else if (i % 6 == 4)
NeoPixel_Set(i, BLUE);
else
NeoPixel_Set(i, PURPLE);
}
while(1) {
NeoPixel_Write_All();
}
}
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Makefile-default.mk
0,0 → 1,172
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c NEOPIXEL.c INTERRUPTS.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/NEOPIXEL.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/NEOPIXEL.p1 ${OBJECTDIR}/INTERRUPTS.p1
 
# Source Files
SOURCEFILES=main.c NEOPIXEL.c INTERRUPTS.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=12F1840
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/NEOPIXEL.p1: NEOPIXEL.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/NEOPIXEL.p1.d
@${RM} ${OBJECTDIR}/NEOPIXEL.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/NEOPIXEL.p1 NEOPIXEL.c
@-${MV} ${OBJECTDIR}/NEOPIXEL.d ${OBJECTDIR}/NEOPIXEL.p1.d
@${FIXDEPS} ${OBJECTDIR}/NEOPIXEL.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/NEOPIXEL.p1: NEOPIXEL.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/NEOPIXEL.p1.d
@${RM} ${OBJECTDIR}/NEOPIXEL.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/NEOPIXEL.p1 NEOPIXEL.c
@-${MV} ${OBJECTDIR}/NEOPIXEL.d ${OBJECTDIR}/NEOPIXEL.p1.d
@${FIXDEPS} ${OBJECTDIR}/NEOPIXEL.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" --ram=default,-160-16f -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sat Mar 29 14:57:13 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_12F1840_NeoPixel
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_12F1840_NeoPixel.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_12F1840_NeoPixel.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx12f1840neopixel.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx12f1840neopixel.tar
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_12F1840_NeoPixel.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx12f1840neopixel/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx12f1840neopixel/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx12f1840neopixel.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx12f1840neopixel.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/configurations.xml
0,0 → 1,163
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>NEOPIXEL.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>NEOPIXEL.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC12F1840</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0xfff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0xfff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="5.0"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/private/SuppressibleMessageMemo.properties
0,0 → 1,3
#
#Mon Mar 10 00:43:05 EDT 2014
pk3/CHECK_4_HIGH_VOLTAGE_VPP=true
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/private/configurations.xml
0,0 → 1,25
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<projectmakefile>Makefile</projectmakefile>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>900A:=&lt;rev>0002:=&lt;man>Microchip Technology Inc.:=&lt;prod>PICkit 3:=&lt;sn>BUR114189291:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc8\v1.20\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
<placeholder2>place holder 2</placeholder2>
</mdbdebugger>
<runprofile version="6">
<args></args>
<rundir></rundir>
<buildfirst>true</buildfirst>
<console-type>0</console-type>
<terminal-type>0</terminal-type>
<remove-instrumentation>0</remove-instrumentation>
<environment>
</environment>
</runprofile>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/private/private.xml
0,0 → 1,3
<?xml version="1.0" encoding="UTF-8"?><project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>
/PIC Projects/PICX_12F1840_NeoPixel/nbproject/project.properties
--- PICX_12F1840_NeoPixel/nbproject/project.xml (nonexistent)
+++ PICX_12F1840_NeoPixel/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_12F1840_NeoPixel</name>
+ <creation-uuid>7fe93e92-3ae3-42d5-9338-2afa3dbfcf6b</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1829_Controller/CPS.c
0,0 → 1,129
#include "defines.h"
#include "CPS.h"
 
static CPS_DATA *cps_data_p;
 
void CPS_Init(CPS_DATA* data) {
cps_data_p = data;
for (uint8_t i = 0; i < 4; i++) {
cps_data_p->btn_pressed[i] = 0;
cps_data_p->btn_last_value[i] = 0;
cps_data_p->btn_avg_value[i] = 0;
cps_data_p->btn_pct_value[i] = 0;
}
 
cps_data_p->channels[0] = 8;
cps_data_p->channels[1] = 9;
 
/* Initialize FVR for the upper threshold (Ref+) */
FVRCONbits.CDAFVR = 0b01; // Gain of 1x (1.024V)
FVRCONbits.FVREN = 1; // Enable FVR module
 
/* Initialize DAC for the lower threshold (Ref-) to Vss */
DACCON0bits.DACEN = 0; // Disable DAC
DACCON0bits.DACLPS = 0; // Negative reference source selected
DACCON0bits.DACOE = 0; // Output not routed to DACOUT pin
DACCON0bits.DACPSS = 0b00; // Vss used as positive source
// DACCON0bits.DACNSS = 0; // Vss used as negative source
// Output voltage formula:
// V_out = ((V_source+ - V_source-) * (DACR / 32)) + V_source-
DACCON1bits.DACR = 0b00000; // Voltage output set to 0v
 
// /* Initialize DAC for the lower threshold (Ref-) to variable setting */
// DACCON0bits.DACEN = 1; // Enable DAC
// DACCON0bits.DACLPS = 1; // Positive reference source selected
// DACCON0bits.DACOE = 0; // Output not routed to DACOUT pin
// DACCON0bits.DACPSS = 0b10; // FVR buffer2 used as positive source
//// DACCON0bits.DACNSS = 0; // Vss used as negative source
// // Output voltage formula:
// // V_out = ((V_source+ - V_source-) * (DACR / 32)) + V_source-
// DACCON1bits.DACR = 0b10000; // Voltage output set to 0.512v
 
/* Initialize Timer 0 */
OPTION_REGbits.TMR0CS = 0; // Clock source is FOSC/4
OPTION_REGbits.PSA = 0; // Prescaler enabled
OPTION_REGbits.PS = 0b110; // Prescaler of 1:128
 
/* Initialize Timer 1 */
T1CONbits.TMR1CS = 0b11; // Clock source is Capacitive Sensing Oscillator
T1CONbits.T1CKPS = 0b00; // 1:1 Prescale value
T1GCONbits.TMR1GE = 1; // Counting is controlled by the gate function
T1GCONbits.T1GPOL = 1; // Gate is active high
T1GCONbits.T1GTM = 1; // Gate toggle mode is enabled
T1GCONbits.T1GSPM = 0; // Gate single-pulse mode is disabled
T1GCONbits.T1GSS = 0b01; // Gate source is Timer 0 overflow
T1CONbits.TMR1ON = 1; // Enables timer 1
 
/* Initialize CPS Module */
CPSCON0bits.CPSRM = 1; // DAC and FVR used for Vref- and Vref+
CPSCON0bits.CPSRNG = 0b11; // Osc in high range (100uA)
CPSCON0bits.T0XCS = 0; // Timer 0 clock runs at FOSC/4
CPSCON1 = cps_data_p->channels[0];
cps_data_p->channel = 0;
CPSCON0bits.CPSON = 1; // CPS module is enabled
 
/* Initialize timer interrupts and clear timers */
INTCONbits.TMR0IE = 1; // Timer 0 interrupt enabled
PIE1bits.TMR1IE = 0; // Timer 1 interrupt disabled
CPS_Reset();
}
 
void CPS_Timer_0_Interrupt_Handler() {
uint16_t value = TMR1;
int32_t percent;
if (value < 10) {
return;
}
 
// Calculate percentage change
percent = (int32_t)cps_data_p->btn_avg_value[cps_data_p->channel]-(int32_t)value;
if (percent < 0)
percent = 0;
else {
percent *= 100;
percent /= cps_data_p->btn_avg_value[cps_data_p->channel];
}
 
cps_data_p->btn_last_value[cps_data_p->channel] = value;
cps_data_p->btn_pct_value[cps_data_p->channel] = percent;
 
if (percent < CPS_PCT_OFF) {
// Calculate average
cps_data_p->btn_avg_value[cps_data_p->channel] +=
// ((int32_t)value - (int32_t)cps_data_p->btn_avg_value[cps_data_p->channel])/CPS_AVG_COUNT;
((int32_t)value - (int32_t)cps_data_p->btn_avg_value[cps_data_p->channel]) >> 4;
// Set flag to indicate that button is not pressed
cps_data_p->btn_pressed[cps_data_p->channel] = 0;
} else if (percent > CPS_PCT_ON) {
// Set flag to indicate that button was pressed
cps_data_p->btn_pressed[cps_data_p->channel] = 1;
}
 
cps_data_p->channel = cps_data_p->channel + 1;
if (cps_data_p->channel == CPS_NUM_CHANNELS)
cps_data_p->channel = 0;
 
CPSCON1 = cps_data_p->channels[cps_data_p->channel];
 
CPS_Reset();
}
 
void CPS_Reset() {
TMR1 = 0;
TMR0 = 0;
}
 
void CPS_Enable() {
INTCONbits.TMR0IE = 1; // Timer 0 interrupt enabled
T1CONbits.TMR1ON = 1;
CPSCON0bits.CPSON = 1;
CPS_Reset();
}
 
void CPS_Disable() {
INTCONbits.TMR0IE = 0;
CPSCON0bits.CPSON = 0;
T1CONbits.TMR1ON = 0;
}
/PIC Projects/PICX_16F1829_Controller/CPS.h
0,0 → 1,31
#ifndef CPS_H
#define CPS_H
 
// Size of rolling average buffer
#define CPS_AVG_COUNT 16
 
// Number of capacitance button inputs
#define CPS_NUM_CHANNELS 2
 
// Value of capacitance change to register button press
#define CPS_PCT_ON 40
#define CPS_PCT_OFF 40
 
typedef struct {
uint8_t channel;
uint8_t channels[CPS_NUM_CHANNELS];
uint8_t btn_pressed[CPS_NUM_CHANNELS];
uint16_t btn_last_value[CPS_NUM_CHANNELS];
uint16_t btn_avg_value[CPS_NUM_CHANNELS];
uint8_t btn_pct_value[CPS_NUM_CHANNELS];
} CPS_DATA;
 
void CPS_Init(CPS_DATA *data);
void CPS_Timer_0_Interrupt_Handler(void);
void CPS_Reset(void);
 
void CPS_Enable(void);
void CPS_Disable(void);
 
#endif
 
/PIC Projects/PICX_16F1829_Controller/I2C1.c
0,0 → 1,544
#include "defines.h"
#include "I2C1.h"
 
static I2C1_DATA *i2c_data_p;
extern BTN_STATUS btns;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C1_Init(I2C1_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C1_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP1ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP1STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C1_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C1_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C1_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
 
SSP1ADD = addr << 1; // Set the slave address
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x6; // Enable Slave 7-bit address
SSP1STATbits.SMP = 1; // Slew Off
SSP1CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON3bits.PCIE = 1; // Interrupt on stop condition
SSP1CON3bits.SCIE = 0; // Disable interrupt on start condition
SSP1CON1bits.SSPEN = 1; // Enable MSSP1 Module
}
 
void I2C1_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C1_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C1_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C1_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSP1BUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP1BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C1_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSP1CON1bits.SSPOV == 1) {
SSP1CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP1STATbits.BF == 1) {
received_data = SSP1BUF;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// // Ignore anything except a start
// if (SSP1STATbits.S == 1) {
// i2c_data_p->buffer_in_len_tmp = 0;
// i2c_data_p->operating_state = I2C_STARTED;
// }
// break;
// }
// case I2C_STARTED:
// {
// In this case, we expect either an address or a stop bit
if (SSP1STATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
i2c_data_p->buffer_in_len_tmp = 0;
if (SSP1STATbits.D_nA == 0) {
// Address received
if (SSP1STATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NOADDR;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C1_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP1BUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSP1BUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP1STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP1STATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP1CON1bits.CKP == 0) {
SSP1CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C1_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C1_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C1_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C1BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C1_Process_Receive(uint8_t c) {
uint8_t ret = 0;
switch (c) {
case CMD_QUERY_BTN:
i2c_data_p->buffer_out[0] = btns.w;
i2c_data_p->buffer_out_len = 1;
ret = 1;
break;
default:
break;
}
 
return ret;
}
/PIC Projects/PICX_16F1829_Controller/I2C2.c
0,0 → 1,534
#include "defines.h"
#include "I2C2.h"
 
static I2C2_DATA *i2c_data_p;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C2_Init(I2C2_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE4bits.SSP2IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C2_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_2_CLK_TRIS = 1;
I2C_2_DAT_TRIS = 1;
 
SSP2STAT = 0x0;
SSP2CON1 = 0x0;
SSP2CON2 = 0x0;
SSP2CON3 = 0x0;
SSP2CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed == 0x01) {
SSP2ADD = 0x13; // Operate at 400KHz (32MHz)
SSP2STATbits.SMP = 1; // Disable Slew Rate Control
} else if (speed == 0x02) {
SSP2ADD = 0x07; // Operate at 1Mhz (32Mhz)
SSP2STATbits.SMP = 1; // Disable Slew Rate Control
} else {
SSP2ADD = 0x4F; // Operate at 100KHz (32MHz)
SSP2STATbits.SMP = 0; // Enable Slew Rate Control
}
SSP2CON1bits.SSPEN = 1; // Enable MSSP2 Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C2_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSP2CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C2_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSP2CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C2_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C2_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP2CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C2_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_2_CLK_TRIS = 1;
I2C_2_DAT_TRIS = 1;
 
SSP2ADD = addr << 1; // Set the slave address
 
SSP2STAT = 0x0;
SSP2CON1 = 0x0;
SSP2CON2 = 0x0;
SSP2CON3 = 0x0;
SSP2CON1bits.SSPM = 0xE; // Enable Slave 7-bit w/ start/stop interrupts
SSP2STATbits.SMP = 1; // Slew Off
SSP2CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON3bits.PCIE = 1; // Interrupt on stop condition
SSP1CON3bits.SCIE = 0; // Disable interrupt on start condition
SSP2CON1bits.SSPEN = 1; // Enable MSSP2 Module
}
 
void I2C2_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C2_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C2_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C2_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP2BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP2CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSP2BUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP2BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP2CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP2CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP2BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP2CON2bits.ACKDT = 0; // ACK
SSP2CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP2CON2bits.ACKDT = 1; // NACK
SSP2CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP2CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSP2BUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP2CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP2BUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP2CON2bits.ACKSTAT) {
SSP2CON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
uint8_t tmp = (i2c_data_p->master_dest_addr << 1);
tmp |= 0x01;
SSP2BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP2CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP2CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSP2BUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSP2CON2bits.ACKDT = 0; // ACK
SSP2CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSP2CON2bits.ACKDT = 1; // NACK
SSP2CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSP2CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSP2CON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C2_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSP2OV (overflow bit)
if (SSP2CON1bits.SSPOV == 1) {
SSP2CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP2STATbits.BF == 1) {
received_data = SSP2BUF;
// DBG_PRINT_I2C("I2C: data read from buffer: %x\r\n", SSP2BUF);
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
// {
// // Ignore anything except a start
// if (SSP2STATbits.S == 1) {
// i2c_data_p->buffer_in_len_tmp = 0;
// i2c_data_p->operating_state = I2C_STARTED;
// }
// break;
// }
// case I2C_STARTED:
{
// In this case, we expect either an address or a stop bit
if (SSP2STATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP2STATbits.D_nA == 0) {
// Address received
if (SSP2STATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NOADDR;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C2_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP2BUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSP2BUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP2STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP2STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C2BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP2STATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2C2BUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP2STATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP2CON1bits.CKP == 0) {
SSP2CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C2_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C2_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C2_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2C2BUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C2_Process_Receive(uint8_t c) {
uint8_t ret = 0;
 
return ret;
}
/PIC Projects/PICX_16F1829_Controller/INTERRUPTS.c
0,0 → 1,120
#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "I2C2.h"
#include "IO.h"
#include "CPS.h"
 
void Interrupt_Init() {
 
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
uint8_t tmr0_rollover = 0;
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// // Check to see if we have an SPI2 interrupt
// if (PIR3bits.SSP2IF) {
// // Call the handler
// SPI2_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR3bits.SSP2IF = 0;
//
// return;
// }
 
 
// Check to see if we have an interrupt on Timer 0 (CPS)
if (INTCONbits.TMR0IF) {
CPS_Timer_0_Interrupt_Handler();
INTCONbits.TMR0IF = 0;
return;
}
// Check to see if we have an I2C1 interrupt
if (PIR1bits.SSP1IF) {
// Call the handler
I2C1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSP1IF = 0;
 
if (INTCONbits.TMR0IF) {
tmr0_rollover = 1;
}
}
 
// Check to see if we have an I2C2 interrupt
if (PIR4bits.SSP2IF) {
// Call the handler
I2C2_Interrupt_Handler();
 
// Clear the interrupt flag
PIR4bits.SSP2IF = 0;
 
if (INTCONbits.TMR0IF) {
tmr0_rollover = 1;
}
}
 
 
// If Timer 0 rolls over while servicing another interrupt handler,
// reset the timers as the sample will be inaccurate.
if (tmr0_rollover) {
INTCONbits.TMR0IF = 0;
CPS_Reset();
}
 
// // Check to see if we have an IO interrupt
// if (INTCONbits.IOCIF) {
// // Call the handler
// IO_Interrupt();
//
// return;
// }
 
// // Check to see if we have an interrupt on USART1 RX
// if (PIR1bits.RC1IF) {
// // Call the interrupt handler
// UART1_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.RC1IF = 0;
//
// return;
// }
 
// // Check to see if we have an interrupt on USART1 TX
// if (PIR1bits.TX1IF) {
// // Call the interrupt handler
// UART1_Send_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.TX1IF = 0;
//
// return;
// }
 
// // Check to see if we have an interrupt on USART2 RX
// if (PIR3bits.RC2IF) {
// DBG_PRINT_INT("INT: UART2 RX\r\n");
// // Call the interrupt handler
// uart_2_recv_interrupt_handler();
//
// // Clear the interrupt flag
// PIR3bits.RC2IF = 0;
// }
}
/PIC Projects/PICX_16F1829_Controller/IO.c
0,0 → 1,63
#include "defines.h"
#include "IO.h"
#include "MCP23009.h"
 
void IO_Init(void) {
// Set all pins to digital I/O
ANSELA = 0x0;
ANSELB = 0x0;
ANSELC = 0x0;
 
// Enable weak pull-up if WPU bit is set
OPTION_REGbits.nWPUEN = 0;
 
// Initialize interrupt inputs
LSM303_INT_TRIS = 1;
L3GD20_INT_TRIS = 1;
BTN_INT_TRIS = 1;
 
// Initialize UART pins
UART_RX_TRIS = 1;
UART_TX_TRIS = 0;
 
// Initialize I2C address pins
I2C_ADDR_0_TRIS = 1;
I2C_ADDR_1_TRIS = 1;
I2C_ADDR_2_TRIS = 1;
I2C_ADDR_3_TRIS = 1;
// Enable the weak-pullup on the address pins
I2C_ADDR_0_WPU = 1;
I2C_ADDR_1_WPU = 1;
I2C_ADDR_2_WPU = 1;
I2C_ADDR_3_WPU = 1;
 
// Initialize I2C pins (dont really need to as the I2C code does it)
I2C_1_CLK_TRIS = 1;
I2C_1_DAT_TRIS = 1;
I2C_2_CLK_TRIS = 1;
I2C_2_DAT_TRIS = 1;
 
// Set the CPS pins
CPS_L_TRIS = 1;
CPS_R_TRIS = 1;
CPS_L_ANSL = 1;
CPS_R_ANSL = 1;
CPS_R_WPU = 0;
CPS_L_WPU = 0;
}
 
void IO_IOC_Enable(void) {
// Clear all IOC flags
IOCAF = 0x0;
IOCBF = 0x0;
 
// Trigger interrupt on BTN_INT on falling edge
IOCANbits.IOCAN2 = 1;
// Enable IOC interrupts
INTCONbits.IOCIE = 1;
}
 
void IO_Interrupt(void) {
Reset_Board(OP_STATE_ACTIVE);
}
/PIC Projects/PICX_16F1829_Controller/TLC59116.c
0,0 → 1,93
#include "defines.h"
#include "TLC59116.h"
#include "I2C2.h"
 
void TLC59116_Init(void) {
uint8_t buffer[25];
 
buffer[0] = TLC59116_AUTO_INCR_ALL | 0x00; // Register Select
buffer[1] = TLC59116_AUTO_INCR_ALL | 0x00; // MODE1
buffer[2] = 0x00; // MODE2
buffer[3] = 0x00; // PWM0
buffer[4] = 0x00; // PWM1
buffer[5] = 0x00; // PWM2
buffer[6] = 0x00; // PWM3
buffer[7] = 0x00; // PWM4
buffer[8] = 0x00; // PWM5
buffer[9] = 0x00; // PWM6
buffer[10] = 0x00; // PWM7
buffer[11] = 0x00; // PWM8
buffer[12] = 0x00; // PWM9
buffer[13] = 0x00; // PWM10
buffer[14] = 0x00; // PWM11
buffer[15] = 0x00; // PWM12
buffer[16] = 0x00; // PWM13
buffer[17] = 0x00; // PWM14
buffer[18] = 0x00; // PWM15
buffer[19] = 0xFF; // GRPPWM (maximum brightness)
buffer[20] = 0x00; // GRPFREQ (not used)
buffer[21] = 0xFF; // LEDOUT0 (brightness and group dimming enabled)
buffer[22] = 0xFF; // LEDOUT1
buffer[23] = 0xFF; // LEDOUT2
buffer[24] = 0xFF; // LEDOUT3
 
I2C2_Master_Send(TLC59116_ADDR, 25, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
}
 
//void TLC59116_Write(uint8_t led, uint8_t brightness) {
// uint8_t buffer[2];
//
// buffer[0] = led + 0x02; // Register Select
// buffer[1] = brightness;
//
// I2C2_Master_Send(TLC59116_ADDR, 2, buffer);
// uint8_t result;
// do {
// result = I2C2_Get_Status();
// } while (!result);
//}
 
void TLC59116_Write_All(LED_VALUES *values) {
uint8_t buffer[17];
 
buffer[0] = TLC59116_AUTO_INCR_ALL | TLC59116_REG_PWM0; // Register Select
buffer[1] = values->w[0];
buffer[2] = values->w[1];
buffer[3] = values->w[2];
buffer[4] = values->w[3];
buffer[5] = values->w[4];
buffer[6] = values->w[5];
buffer[7] = values->w[6];
buffer[8] = values->w[7];
buffer[9] = values->w[8];
buffer[10] = values->w[9];
buffer[11] = values->w[10];
buffer[12] = values->w[11];
buffer[13] = values->w[12];
buffer[14] = values->w[13];
buffer[15] = values->w[14];
buffer[16] = values->w[15];
 
I2C2_Master_Send(TLC59116_ADDR, 17, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
}
 
void TLC59116_Write_BC(uint8_t brightness) {
uint8_t buffer[2];
 
buffer[0] = TLC59116_REG_GRPPWM; // Register Select
buffer[1] = brightness;
 
I2C2_Master_Send(TLC59116_ADDR, 2, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
}
/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 */
 
/PIC Projects/PICX_16F1829_Controller/funclist
0,0 → 1,42
_I2C2_Interrupt_Master: CODE, 50 0 706
_Get_Last_Reset: CODE, 5000 0 43
___aldiv: CODE, 6014 0 130
_I2C1_Init: CODE, 2079 0 91
_I2C1_Interrupt_Slave: CODE, 3072 0 426
_I2C1_Read_Buffer: CODE, 5565 0 78
_CPS_Reset: CODE, 4772 0 5
_I2C2_Init: CODE, 1928 0 91
_I2C2_Interrupt_Slave: CODE, 2653 0 419
_I2C2_Read_Buffer: CODE, 5487 0 78
_main: CODE, 1462 0 466
_Interrupt_Enable: CODE, 2045 0 3
_Direction_Rotate_Clockwise: CODE, 5421 0 66
_I2C2_Master_Restart: CODE, 5643 0 79
_Direction_Rotate_CClockwise: CODE, 5355 0 66
_InterruptHandler: CODE, 4 0 44
___lmul: CODE, 5135 0 47
_Check_I2C_Idle: CODE, 5182 0 49
_Read_Address: CODE, 4798 0 15
_I2C1_Process_Receive: CODE, 2048 0 31
_Interrupt_Init: CODE, 3 0 1
__initialization: CODE, 4929 0 31
_MCP23009_Init: CODE, 5089 0 46
_I2C2_Process_Receive: CODE, 4764 0 3
_TLC59116_Init: CODE, 5805 0 85
_CPS_Timer_0_Interrupt_Handler: CODE, 2312 0 341
_I2C2_Configure_Master: CODE, 5043 0 46
_I2C1_Interrupt_Handler: CODE, 4837 0 26
_MCP23009_Query: CODE, 4963 0 37
_IO_Init: CODE, 4895 0 34
_I2C2_Master_Send: CODE, 5722 0 83
_I2C1_Configure_Slave: CODE, 4863 0 32
_I2C2_Interrupt_Handler: CODE, 2019 0 26
_TLC59116_Write_All: CODE, 2170 0 142
_Reset_Board: CODE, 4789 0 9
i1_CPS_Reset: CODE, 4767 0 5
_I2C1_Get_Status: CODE, 5293 0 62
_CPS_Init: CODE, 5890 0 124
_I2C1_Interrupt_Master: CODE, 756 0 706
_I2C2_Get_Status: CODE, 5231 0 62
_Idle_Animation: CODE, 3498 0 598
Total: 5432
/PIC Projects/PICX_16F1829_Controller/l.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/PIC Projects/PICX_16F1829_Controller/l.obj
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/PIC Projects/PICX_16F1829_Controller/main.c
0,0 → 1,376
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT software controlled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "INTERRUPTS.h"
#include "IO.h"
#include "I2C1.h"
#include "I2C2.h"
#include "CPS.h"
#include "TLC59116.h"
#include "MCP23009.h"
 
persistent uint8_t op_state;
 
void Reset_Board(uint8_t next_state) {
op_state = next_state;
RESET();
}
 
uint8_t Get_Last_Reset(void) {
uint8_t ret;
if (PCONbits.nPOR == 0) {
ret = RESET_POR;
} else if (PCONbits.nBOR == 0) {
ret = RESET_BOR;
} else if (STATUSbits.nTO == 0) {
ret = RESET_WDT;
} else if (PCONbits.nRMCLR == 0) {
ret = RESET_MCLR;
} else if (PCONbits.STKOVF || PCONbits.STKUNF) {
ret = RESET_STK;
} else if (PCONbits.nRI == 0) {
ret = RESET_RST;
} else {
ret = RESET_POR;
}
 
PCON = 0x0F;
STATUSbits.nPD = 1;
STATUSbits.nTO = 1;
return ret;
}
 
uint8_t Read_Address(void) {
uint8_t ret = I2C1_SLAVE_PREFIX;
if (!I2C_ADDR_3_PORT)
ret |= 0x08;
if (!I2C_ADDR_2_PORT)
ret |= 0x04;
if (!I2C_ADDR_1_PORT)
ret |= 0x02;
if (!I2C_ADDR_0_PORT)
ret |= 0x01;
 
return ret;
}
 
BTN_STATUS btns;
LED_VALUES leds = {0x00};
 
int main(void) {
uint8_t buffer[32];
uint8_t result, length;
uint8_t i2c_slave_addr;
// uint8_t op_state;
uint8_t i;
 
// Set internal oscillator speed to 32MHz
OSCCONbits.SPLLEN = 1; // 4x PLL enable (overwritten by config bits)
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Initialize I/O
IO_Init();
 
uint8_t last_reset = Get_Last_Reset();
if (last_reset == RESET_POR || last_reset == RESET_BOR ||
last_reset == RESET_MCLR || last_reset == RESET_WDT ||
last_reset == RESET_STK) {
op_state = OP_STATE_IDLE;
}
// if (last_reset == RESET_RST) {
// op_state = OP_STATE_ACTIVE;
// }
 
i2c_slave_addr = Read_Address();
 
// Delay a bit to allow I2C lines to stabilize
__delay_ms(10);
 
// Initialize I2C1 in slave mode
I2C1_DATA i2c1_data;
I2C1_Init(&i2c1_data);
I2C1_Configure_Slave(i2c_slave_addr);
 
// Initialize I2C2 in master mode
I2C2_DATA i2c2_data;
I2C2_Init(&i2c2_data);
I2C2_Configure_Master(I2C_1MHZ);
 
CPS_DATA cps_data;
CPS_Init(&cps_data);
 
// Initialize interrupts
Interrupt_Init();
Interrupt_Enable();
 
MCP23009_Init(&btns);
MCP23009_Query();
 
TLC59116_Init();
// TLC59116_Write_All(&leds);
 
if (op_state == OP_STATE_IDLE) {
// IO_IOC_Enable();
Idle_Animation();
} else if (op_state == OP_STATE_ACTIVE) {
uint8_t button_R = 0, button_L = 0;
uint8_t dir_state = DIR_S;
leds.single.LED_S = DIR_BRIGHTNESS;
TLC59116_Write_All(&leds);
while (1) {
// Check if an I2C message was received
do {
result = I2C1_Get_Status();
} while (!result);
length = I2C1_Read_Buffer(buffer);
if (length == 1 && buffer[0] == CMD_RESET) {
Reset_Board(OP_STATE_IDLE);
} else if (length == 1 && buffer[0] == CMD_ACTIVE) {
Reset_Board(OP_STATE_ACTIVE);
} else if (length == 17 && buffer[0] == CMD_SET_LEDS) {
for (i = 0; i < 16; i++) {
leds.w[i] = buffer[i + 1];
}
// Reset the direction LEDs
if (dir_state == DIR_S)
leds.single.LED_S = DIR_BRIGHTNESS;
else if (dir_state == DIR_W)
leds.single.LED_W = DIR_BRIGHTNESS;
else if (dir_state == DIR_N)
leds.single.LED_N = DIR_BRIGHTNESS;
else if (dir_state == DIR_E)
leds.single.LED_E = DIR_BRIGHTNESS;
TLC59116_Write_All(&leds);
}
 
// Check if either capacitive buttons were pressed
if (cps_data.btn_pressed[0] && button_R == 0) {
// Right button went from unpressed -> pressed
dir_state = Direction_Rotate_CClockwise(dir_state);
TLC59116_Write_All(&leds);
}
if (cps_data.btn_pressed[1] && button_L == 0) {
// Left button went from unpressed -> pressed
dir_state = Direction_Rotate_Clockwise(dir_state);
TLC59116_Write_All(&leds);
}
// Save the previous button state
button_R = cps_data.btn_pressed[0];
button_L = cps_data.btn_pressed[1];
 
// Poll the hardware buttons
I2C2_Master_Restart(MCP23009_ADDR, MCP23009_GPIOA, 1);
do {
result = I2C2_Get_Status();
} while (!result);
length = I2C2_Read_Buffer(buffer);
btns.w = buffer[0];
// Change the direction according to the user's perspective
if (dir_state == DIR_W) {
uint8_t tmp = btns.BTN_R_S;
btns.BTN_R_S = btns.BTN_R_W;
btns.BTN_R_W = btns.BTN_R_N;
btns.BTN_R_N = btns.BTN_R_E;
btns.BTN_R_E = tmp;
} else if (dir_state == DIR_E) {
uint8_t tmp = btns.BTN_R_S;
btns.BTN_R_S = btns.BTN_R_E;
btns.BTN_R_E = btns.BTN_R_N;
btns.BTN_R_N = btns.BTN_R_W;
btns.BTN_R_W = tmp;
} else if (dir_state == DIR_N) {
uint8_t tmp = btns.BTN_R_S;
btns.BTN_R_S = btns.BTN_R_N;
btns.BTN_R_N = tmp;
tmp = btns.BTN_R_E;
btns.BTN_R_E = btns.BTN_R_W;
btns.BTN_R_W = tmp;
}
}
}
}
 
uint8_t Direction_Rotate_Clockwise(uint8_t dir_state) {
uint8_t ret;
switch (dir_state) {
case DIR_S:
leds.single.LED_S = 0x00;
leds.single.LED_W = DIR_BRIGHTNESS;
ret = DIR_W;
break;
case DIR_W:
leds.single.LED_W = 0x00;
leds.single.LED_N = DIR_BRIGHTNESS;
ret = DIR_N;
break;
case DIR_N:
leds.single.LED_N = 0x00;
leds.single.LED_E = DIR_BRIGHTNESS;
ret = DIR_E;
break;
case DIR_E:
leds.single.LED_E = 0x00;
leds.single.LED_S = DIR_BRIGHTNESS;
ret = DIR_S;
break;
}
return ret;
}
 
uint8_t Direction_Rotate_CClockwise(uint8_t dir_state) {
uint8_t ret;
switch (dir_state) {
case DIR_S:
leds.single.LED_S = 0x00;
leds.single.LED_E = DIR_BRIGHTNESS;
ret = DIR_E;
break;
case DIR_E:
leds.single.LED_E = 0x00;
leds.single.LED_N = DIR_BRIGHTNESS;
ret = DIR_N;
break;
case DIR_N:
leds.single.LED_N = 0x00;
leds.single.LED_W = DIR_BRIGHTNESS;
ret = DIR_W;
break;
case DIR_W:
leds.single.LED_W = 0x00;
leds.single.LED_S = DIR_BRIGHTNESS;
ret = DIR_S;
break;
}
return ret;
}
 
void Check_I2C_Idle(void) {
uint8_t buffer[32];
uint8_t result, length, i;
 
// Check if an I2C message was received
result = I2C1_Get_Status();
if (result) {
length = I2C1_Read_Buffer(buffer);
if (length == 1 && buffer[0] == CMD_RESET) {
Reset_Board(OP_STATE_IDLE);
} else if (length == 1 && buffer[0] == CMD_ACTIVE) {
Reset_Board(OP_STATE_ACTIVE);
}
}
}
 
void Idle_Animation(void) {
LED_VALUES leds = {0};
uint8_t led_direction_bar[8] = {1,0,0,0,0,0,0,0};
uint8_t led_direction_dir[8] = {1,0,0,0};
uint8_t led_direction_ind[8] = {1,0,0,0};
uint8_t led_8_high_thres = 0x80; // Max brightness of the middle section
uint8_t led_8_next_thresh = 0x40; // Threshold to start the next LED
uint8_t led_4_high_thres = 0x80; // Max brightness of the side sections
uint8_t led_4_next_thresh = 0x74; // Threshold to start the next LED
uint8_t i, next_led;
 
for (i = 0; i < 16; i++) leds.w[i] = 0x00;
while (1) {
 
// Check to see if a new message was received
Check_I2C_Idle();
 
// Update the LEDs in the middle section
for (i = 0; i < 8; i++) {
// Change the LED brightness depending on its direction
if (led_direction_bar[i] == 1) {
leds.w[i]++;
} else if (led_direction_bar[i] == 2) {
leds.w[i]--;
}
 
// Change direction if peak brightness is reached
// When the brightness reaches a middle threshold, start
// increasing the brightness of the next LED
if (led_direction_bar[i] == 1 && leds.w[i] == led_8_high_thres) {
led_direction_bar[i] = 2;
} else if (led_direction_bar[i] == 1 && leds.w[i] == led_8_next_thresh) {
next_led = (i == 7) ? 0 : i + 1;
led_direction_bar[next_led] = 1;
} else if (led_direction_bar[i] == 2 && leds.w[i] == 0x00) {
led_direction_bar[i] = 0;
}
}
 
// Update the LEDs in the right section
for (i = 0; i < 4; i++) {
// Change the LED brightness depending on its direction
if (led_direction_dir[i] == 1) {
leds.w[i+8]++;
} else if (led_direction_dir[i] == 2) {
leds.w[i+8]--;
}
 
// Change direction if peak brightness is reached
// When the brightness reaches a middle threshold, start
// increasing the brightness of the next LED
if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_high_thres) {
led_direction_dir[i] = 2;
} else if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_next_thresh) {
next_led = (i == 3) ? 0 : i + 1;
led_direction_dir[next_led] = 1;
} else if (led_direction_dir[i] == 2 && leds.w[i+8] == 0x00) {
led_direction_dir[i] = 0;
}
}
 
// Update the LEDs in the left section
for (i = 0; i < 4; i++) {
// Change the LED brightness depending on its direction
if (led_direction_ind[i] == 1) {
leds.w[i+12]++;
} else if (led_direction_ind[i] == 2) {
leds.w[i+12]--;
}
 
// Change direction if peak brightness is reached
// When the brightness reaches a middle threshold, start
// increasing the brightness of the next LED
if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_high_thres) {
led_direction_ind[i] = 2;
} else if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_next_thresh) {
next_led = (i == 3) ? 0 : i + 1;
led_direction_ind[next_led] = 1;
} else if (led_direction_ind[i] == 2 && leds.w[i+12] == 0x00) {
led_direction_ind[i] = 0;
}
}
 
// Write the LED values to the controller
TLC59116_Write_All(&leds);
 
// Delay a bit to slow down the animation
__delay_ms(1);
}
}
/PIC Projects/PICX_16F1829_Controller/nbproject/Makefile-default.mk
0,0 → 1,252
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c I2C1.c INTERRUPTS.c I2C2.c TLC59116.c MCP23009.c IO.c CPS.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C2.p1 ${OBJECTDIR}/TLC59116.p1 ${OBJECTDIR}/MCP23009.p1 ${OBJECTDIR}/IO.p1 ${OBJECTDIR}/CPS.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/I2C1.p1.d ${OBJECTDIR}/INTERRUPTS.p1.d ${OBJECTDIR}/I2C2.p1.d ${OBJECTDIR}/TLC59116.p1.d ${OBJECTDIR}/MCP23009.p1.d ${OBJECTDIR}/IO.p1.d ${OBJECTDIR}/CPS.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/I2C1.p1 ${OBJECTDIR}/INTERRUPTS.p1 ${OBJECTDIR}/I2C2.p1 ${OBJECTDIR}/TLC59116.p1 ${OBJECTDIR}/MCP23009.p1 ${OBJECTDIR}/IO.p1 ${OBJECTDIR}/CPS.p1
 
# Source Files
SOURCEFILES=main.c I2C1.c INTERRUPTS.c I2C2.c TLC59116.c MCP23009.c IO.c CPS.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16LF1829
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C2.p1: I2C2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C2.p1.d
@${RM} ${OBJECTDIR}/I2C2.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C2.p1 I2C2.c
@-${MV} ${OBJECTDIR}/I2C2.d ${OBJECTDIR}/I2C2.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C2.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TLC59116.p1: TLC59116.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TLC59116.p1.d
@${RM} ${OBJECTDIR}/TLC59116.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TLC59116.p1 TLC59116.c
@-${MV} ${OBJECTDIR}/TLC59116.d ${OBJECTDIR}/TLC59116.p1.d
@${FIXDEPS} ${OBJECTDIR}/TLC59116.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/MCP23009.p1: MCP23009.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/MCP23009.p1.d
@${RM} ${OBJECTDIR}/MCP23009.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/MCP23009.p1 MCP23009.c
@-${MV} ${OBJECTDIR}/MCP23009.d ${OBJECTDIR}/MCP23009.p1.d
@${FIXDEPS} ${OBJECTDIR}/MCP23009.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IO.p1: IO.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IO.p1.d
@${RM} ${OBJECTDIR}/IO.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IO.p1 IO.c
@-${MV} ${OBJECTDIR}/IO.d ${OBJECTDIR}/IO.p1.d
@${FIXDEPS} ${OBJECTDIR}/IO.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/CPS.p1: CPS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CPS.p1.d
@${RM} ${OBJECTDIR}/CPS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/CPS.p1 CPS.c
@-${MV} ${OBJECTDIR}/CPS.d ${OBJECTDIR}/CPS.p1.d
@${FIXDEPS} ${OBJECTDIR}/CPS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C1.p1: I2C1.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C1.p1.d
@${RM} ${OBJECTDIR}/I2C1.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C1.p1 I2C1.c
@-${MV} ${OBJECTDIR}/I2C1.d ${OBJECTDIR}/I2C1.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C1.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPTS.p1: INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/INTERRUPTS.p1 INTERRUPTS.c
@-${MV} ${OBJECTDIR}/INTERRUPTS.d ${OBJECTDIR}/INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C2.p1: I2C2.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C2.p1.d
@${RM} ${OBJECTDIR}/I2C2.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/I2C2.p1 I2C2.c
@-${MV} ${OBJECTDIR}/I2C2.d ${OBJECTDIR}/I2C2.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C2.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TLC59116.p1: TLC59116.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TLC59116.p1.d
@${RM} ${OBJECTDIR}/TLC59116.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/TLC59116.p1 TLC59116.c
@-${MV} ${OBJECTDIR}/TLC59116.d ${OBJECTDIR}/TLC59116.p1.d
@${FIXDEPS} ${OBJECTDIR}/TLC59116.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/MCP23009.p1: MCP23009.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/MCP23009.p1.d
@${RM} ${OBJECTDIR}/MCP23009.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/MCP23009.p1 MCP23009.c
@-${MV} ${OBJECTDIR}/MCP23009.d ${OBJECTDIR}/MCP23009.p1.d
@${FIXDEPS} ${OBJECTDIR}/MCP23009.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/IO.p1: IO.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/IO.p1.d
@${RM} ${OBJECTDIR}/IO.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/IO.p1 IO.c
@-${MV} ${OBJECTDIR}/IO.d ${OBJECTDIR}/IO.p1.d
@${FIXDEPS} ${OBJECTDIR}/IO.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/CPS.p1: CPS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/CPS.p1.d
@${RM} ${OBJECTDIR}/CPS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/CPS.p1 CPS.c
@-${MV} ${OBJECTDIR}/CPS.d ${OBJECTDIR}/CPS.p1.d
@${FIXDEPS} ${OBJECTDIR}/CPS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,+speed,-space,-debug --addrqual=require --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1829_Controller/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Wed Mar 19 00:58:38 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_16F1829_Controller/nbproject/configurations.xml
0,0 → 1,173
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>I2C1.h</itemPath>
<itemPath>INTERRUPTS.h</itemPath>
<itemPath>I2C2.h</itemPath>
<itemPath>TLC59116.h</itemPath>
<itemPath>MCP23009.h</itemPath>
<itemPath>IO.h</itemPath>
<itemPath>CPS.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>I2C1.c</itemPath>
<itemPath>INTERRUPTS.c</itemPath>
<itemPath>I2C2.c</itemPath>
<itemPath>TLC59116.c</itemPath>
<itemPath>MCP23009.c</itemPath>
<itemPath>IO.c</itemPath>
<itemPath>CPS.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16LF1829</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="require"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1829_Controller/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1829_Controller
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1829_Controller/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1829_Controller/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1829_Controller.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1829_Controller.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1829controller.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1829controller.tar
/PIC Projects/PICX_16F1829_Controller/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1829_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1829controller/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1829controller/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1829controller.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1829controller.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1829_Controller/nbproject/project.properties
--- PICX_16F1829_Controller/nbproject/project.xml (nonexistent)
+++ PICX_16F1829_Controller/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1829_Controller</name>
+ <creation-uuid>a37f9b7c-e474-41b7-9a5b-bc6808e97a44</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1829_Controller/I2C1.h
0,0 → 1,82
#ifndef I2C1_H
#define I2C1_H
 
#define MAXI2C1BUF 32
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C1BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2C1BUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C1_DATA;
 
void I2C1_Init(I2C1_DATA *data);
void I2C1_Interrupt_Handler(void);
void I2C1_Interrupt_Slave(void);
void I2C1_Interrupt_Master(void);
void I2C1_Configure_Slave(uint8_t address);
void I2C1_Configure_Master(uint8_t speed);
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C1_Master_Recv(uint8_t address, uint8_t length);
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C1_Get_Status(void);
uint8_t I2C1_Buffer_Len(void);
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
uint8_t I2C1_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1829_Controller/I2C2.h
0,0 → 1,82
#ifndef I2C2_H
#define I2C2_H
 
#define MAXI2C2BUF 32
 
// I2C Operating Speed
#define I2C_100KHZ 0x0
#define I2C_400KHZ 0x1
#define I2C_1MHZ 0x2
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2C2BUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2C2BUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C2_DATA;
 
void I2C2_Init(I2C2_DATA *data);
void I2C2_Interrupt_Handler(void);
void I2C2_Interrupt_Slave(void);
void I2C2_Interrupt_Master(void);
void I2C2_Configure_Slave(uint8_t address);
void I2C2_Configure_Master(uint8_t speed);
void I2C2_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C2_Master_Recv(uint8_t address, uint8_t length);
void I2C2_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C2_Get_Status(void);
uint8_t I2C2_Buffer_Len(void);
uint8_t I2C2_Read_Buffer(uint8_t *buffer);
uint8_t I2C2_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1829_Controller/MCP23009.c
0,0 → 1,40
#include "defines.h"
#include "MCP23009.h"
#include "I2C2.h"
 
static BTN_STATUS *status_ptr;
 
void MCP23009_Init(BTN_STATUS *status) {
status_ptr = status;
uint8_t buffer[8];
 
buffer[0] = 0x00; // Starting register address
buffer[1] = 0xFF; // IODIR, Set all pins as inputs
buffer[2] = 0xFF; // IPOL, Reported values are inverted
// buffer[3] = 0xFF; // GPINTEN, Enable interrupt-on-change
buffer[3] = 0x00; // GPINTEN, Disable interrupt-on-change
buffer[4] = 0x00; // DEFVAL, IOC default values
buffer[5] = 0x00; // INTCON, IOC compare to previous value
buffer[6] = 0x00; // IOCON, Incrementing address, active-low interrupt cleared on GPIO read
buffer[7] = 0xFF; // GPPU, Enable pull-ups on all pins
 
I2C2_Master_Send(MCP23009_ADDR, 8, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
}
 
void MCP23009_Query(void) {
uint8_t buffer[2];
 
I2C2_Master_Restart(MCP23009_ADDR, MCP23009_GPIOA, 1);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
I2C2_Read_Buffer(buffer);
 
status_ptr->w = buffer[0];
}
/PIC Projects/PICX_16F1829_Controller/IO.h
0,0 → 1,13
#ifndef IO_H
#define IO_H
 
typedef struct {
uint8_t btn_change;
} IO_DATA;
 
void IO_Init(void);
void IO_IOC_Enable(void);
void IO_Interrupt(void);
 
#endif /* IO_H */
 
/PIC Projects/PICX_16F1829_Controller/MCP23009.h
0,0 → 1,23
#ifndef MCP23009_H
#define MCP23009_H
 
#define MCP23009_ADDR 0x20
 
#define MCP23009_IODIRA 0x00
#define MCP23009_IPOLA 0x01
#define MCP23009_GPINTENA 0x02
#define MCP23009_DEFVALA 0x03
#define MCP23009_INTCONA 0x04
#define MCP23009_IOCON 0x05
#define MCP23009_GPPUA 0x06
#define MCP23009_INTFA 0x07
#define MCP23009_INTCAPA 0x08
#define MCP23009_GPIOA 0x09
#define MCP23009_OLATA 0x0A
 
void MCP23009_Init(BTN_STATUS *status);
void MCP23009_Query(void);
void MSP23009_Interrupt(void);
 
#endif /* MCP23009_H */
 
/PIC Projects/PICX_16F1829_Controller/TLC59116.h
0,0 → 1,56
#ifndef TLC59116_H
#define TLC59116_H
 
#define TLC59116_ADDR 0x60
#define TLC59116_ALLCALL 0x68
 
// Write to this register to reset chip
#define TLC59116_RESET 0x6B
 
// Increment all registers, rollover from 00000 to 11011
#define TLC59116_AUTO_INCR_ALL 0x80
// Increment brightness registers, rollover from 00010 to 10001
#define TLC59116_AUTO_INCR_BRIGHTNESS 0xA0
// Increment global control registers, rollover from 10010 to 10011
#define TLC59116_AUTO_INCR_GLBL_CTRL 0xC0
// Increment individual and global registers, rollover from 00010 to 10011
#define TLC59116_AUTO_INCR_INDV_CTRL 0xE0
 
#define TLC59116_REG_MODE1 0x00
#define TLC59116_REG_MODE2 0x01
#define TLC59116_REG_PWM0 0x02
#define TLC59116_REG_PWM1 0x03
#define TLC59116_REG_PWM2 0x04
#define TLC59116_REG_PWM3 0x05
#define TLC59116_REG_PWM4 0x06
#define TLC59116_REG_PWM5 0x07
#define TLC59116_REG_PWM6 0x08
#define TLC59116_REG_PWM7 0x09
#define TLC59116_REG_PWM8 0x0A
#define TLC59116_REG_PWM9 0x0B
#define TLC59116_REG_PWM10 0x0C
#define TLC59116_REG_PWM11 0x0D
#define TLC59116_REG_PWM12 0x0E
#define TLC59116_REG_PWM13 0x0F
#define TLC59116_REG_PWM14 0x10
#define TLC59116_REG_PWM15 0x11
#define TLC59116_REG_GRPPWM 0x12
#define TLC59116_REG_GRPFREQ 0x13
#define TLC59116_REG_LEDOUT0 0x14
#define TLC59116_REG_LEDOUT1 0x15
#define TLC59116_REG_LEDOUT2 0x16
#define TLC59116_REG_LEDOUT3 0x17
#define TLC59116_REG_SUBADR1 0x18
#define TLC59116_REG_SUBADR2 0x19
#define TLC59116_REG_SUBADR3 0x1A
#define TLC59116_REG_ALLCALLADR 0x1B
#define TLC59116_REG_IREF 0x1C
#define TLC59116_REG_EFLAG1 0x1D
#define TLC59116_REG_EFLAG2 0x1E
 
void TLC59116_Init(void);
void TLC59116_Write_All(LED_VALUES *values);
void TLC59116_Write_BC(uint8_t brightness);
 
#endif /* TLC59116_H */
 
/PIC Projects/PICX_16F1829_Controller/INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1829_Controller/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_12F1840_CPS/base_CPS.c
0,0 → 1,131
#include <xc.h>
#include "defines.h"
#include "base_CPS.h"
 
static CPS_DATA *cps_data_p;
 
void CPS_Init(CPS_DATA* data) {
cps_data_p = data;
for (char i = 0; i < 4; i++) {
cps_data_p->btn_pressed[i] = 0;
cps_data_p->btn_last_value[i] = 0;
cps_data_p->btn_avg_value[i] = 0;
cps_data_p->btn_pct_value[i] = 0;
}
 
/* Initialize port direction */
CPS_0_TRIS = 1;
CPS_1_TRIS = 1;
 
/* Initialize FVR for the upper threshold (Ref+) */
FVRCONbits.CDAFVR = 0b01; // Gain of 1x (1.024V)
FVRCONbits.FVREN = 1; // Enable FVR module
 
/* Initialize DAC for the lower threshold (Ref-) to Vss */
DACCON0bits.DACEN = 0; // Disable DAC
DACCON0bits.DACLPS = 0; // Negative reference source selected
DACCON0bits.DACOE = 0; // Output not routed to DACOUT pin
DACCON0bits.DACPSS = 0b00; // Vss used as positive source
// DACCON0bits.DACNSS = 0; // Vss used as negative source
// Output voltage formula:
// V_out = ((V_source+ - V_source-) * (DACR / 32)) + V_source-
DACCON1bits.DACR = 0b00000; // Voltage output set to 0v
 
// /* Initialize DAC for the lower threshold (Ref-) to variable setting */
// DACCON0bits.DACEN = 1; // Enable DAC
// DACCON0bits.DACLPS = 1; // Positive reference source selected
// DACCON0bits.DACOE = 0; // Output not routed to DACOUT pin
// DACCON0bits.DACPSS = 0b10; // FVR buffer2 used as positive source
//// DACCON0bits.DACNSS = 0; // Vss used as negative source
// // Output voltage formula:
// // V_out = ((V_source+ - V_source-) * (DACR / 32)) + V_source-
// DACCON1bits.DACR = 0b10000; // Voltage output set to 0.512v
 
/* Initialize Timer 0 */
OPTION_REGbits.TMR0CS = 0; // Clock source is FOSC/4
OPTION_REGbits.PSA = 0; // Prescaler enabled
OPTION_REGbits.PS = 0b111; // Prescaler of 1:256
 
/* Initialize Timer 1 */
T1CONbits.TMR1CS = 0b11; // Clock source is Capacitive Sensing Oscillator
T1CONbits.T1CKPS = 0b00; // 1:1 Prescale value
T1GCONbits.TMR1GE = 1; // Counting is controlled by the gate function
T1GCONbits.T1GPOL = 1; // Gate is active high
T1GCONbits.T1GTM = 1; // Gate toggle mode is enabled
T1GCONbits.T1GSPM = 0; // Gate single-pulse mode is disabled
T1GCONbits.T1GSS = 0b01; // Gate source is Timer 0 overflow
T1CONbits.TMR1ON = 1; // Enables timer 1
 
/* Initialize CPS Module */
CPSCON0bits.CPSRM = 1; // DAC and FVR used for Vref- and Vref+
CPSCON0bits.CPSRNG = 0b11; // Osc in high range (100uA)
CPSCON0bits.T0XCS = 0; // Timer 0 clock runs at FOSC/4
CPSCON1bits.CPSCH = 0b00; // Channel 0 (CPS0)
cps_data_p->channel = 0;
CPSCON0bits.CPSON = 1; // CPS module is enabled
 
/* Initialize timer interrupts and clear timers */
INTCONbits.TMR0IE = 1; // Timer 0 interrupt enabled
PIE1bits.TMR1IE = 0; // Timer 1 interrupt disabled
CPS_Reset();
}
 
void CPS_Timer_0_Interrupt_Handler() {
unsigned int value = TMR1;
long percent;
 
if (value < 10) {
return;
}
 
// Calculate percentage change
percent = (long)cps_data_p->btn_avg_value[cps_data_p->channel]-(long)value;
if (percent < 0)
percent = 0;
else {
percent *= 100;
percent /= cps_data_p->btn_avg_value[cps_data_p->channel];
}
 
cps_data_p->btn_last_value[cps_data_p->channel] = value;
cps_data_p->btn_pct_value[cps_data_p->channel] = percent;
 
if (percent < CPS_PCT_OFF) {
// Calculate average
cps_data_p->btn_avg_value[cps_data_p->channel] =
cps_data_p->btn_avg_value[cps_data_p->channel] +
((long)value - (long)cps_data_p->btn_avg_value[cps_data_p->channel])
/CPS_AVG_COUNT;
// Set flag to indicate that button is not pressed
cps_data_p->btn_pressed[cps_data_p->channel] = 0;
} else if (percent > CPS_PCT_ON) {
// Set flag to indicate that button was pressed
cps_data_p->btn_pressed[cps_data_p->channel] = 1;
}
 
cps_data_p->channel = cps_data_p->channel + 1;
if (cps_data_p->channel == CPS_NUM_CHANNELS)
cps_data_p->channel = 0;
CPSCON1bits.CPSCH = cps_data_p->channel;
 
CPS_Reset();
}
 
void CPS_Reset() {
TMR1 = 0;
TMR0 = 0;
}
 
void CPS_Enable() {
INTCONbits.TMR0IE = 1; // Timer 0 interrupt enabled
T1CONbits.TMR1ON = 1;
CPSCON0bits.CPSON = 1;
CPS_Reset();
}
 
void CPS_Disable() {
INTCONbits.TMR0IE = 0;
CPSCON0bits.CPSON = 0;
T1CONbits.TMR1ON = 0;
}
/PIC Projects/PICX_12F1840_CPS/base_CPS.h
0,0 → 1,30
#ifndef CPS_H
#define CPS_H
 
// Size of rolling average buffer
#define CPS_AVG_COUNT 16
 
// Number of capacitance button inputs
#define CPS_NUM_CHANNELS 2
 
// Percentage of capacitance change to register button press
#define CPS_PCT_ON 10
#define CPS_PCT_OFF 8
 
typedef struct {
char channel;
char btn_pressed[4];
unsigned int btn_last_value[4];
unsigned int btn_avg_value[4];
char btn_pct_value[4];
} CPS_DATA;
 
void CPS_Init(CPS_DATA *data);
void CPS_Timer_0_Interrupt_Handler(void);
void CPS_Reset(void);
 
void CPS_Enable(void);
void CPS_Disable(void);
 
#endif
 
/PIC Projects/PICX_12F1840_CPS/funclist
0,0 → 1,15
___awdiv: CODE, 633 0 84
___aldiv: CODE, 397 0 130
_CPS_Reset: CODE, 942 0 5
_PWM_Set_Width: CODE, 871 0 46
_main: CODE, 717 0 54
_Interrupt_Enable: CODE, 956 0 3
_InterruptHandler: CODE, 4 0 30
___lmul: CODE, 824 0 47
__initialization: CODE, 952 0 1
_CPS_Timer_0_Interrupt_Handler: CODE, 36 0 361
i1_CPS_Reset: CODE, 947 0 5
_CPS_Init: CODE, 527 0 106
_PWM_Init: CODE, 917 0 25
_UART_Send_Interrupt_Handler: CODE, 771 0 53
Total: 950
/PIC Projects/PICX_12F1840_CPS/nbproject/Makefile-default.mk
0,0 → 1,204
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c base_INTERRUPTS.c base_UART.c base_CPS.c base_PWM.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_INTERRUPTS.p1 ${OBJECTDIR}/base_UART.p1 ${OBJECTDIR}/base_CPS.p1 ${OBJECTDIR}/base_PWM.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/base_INTERRUPTS.p1.d ${OBJECTDIR}/base_UART.p1.d ${OBJECTDIR}/base_CPS.p1.d ${OBJECTDIR}/base_PWM.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_INTERRUPTS.p1 ${OBJECTDIR}/base_UART.p1 ${OBJECTDIR}/base_CPS.p1 ${OBJECTDIR}/base_PWM.p1
 
# Source Files
SOURCEFILES=main.c base_INTERRUPTS.c base_UART.c base_CPS.c base_PWM.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=12F1840
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_UART.p1: base_UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_UART.p1.d
@${RM} ${OBJECTDIR}/base_UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_UART.p1 base_UART.c
@-${MV} ${OBJECTDIR}/base_UART.d ${OBJECTDIR}/base_UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_CPS.p1: base_CPS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_CPS.p1.d
@${RM} ${OBJECTDIR}/base_CPS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_CPS.p1 base_CPS.c
@-${MV} ${OBJECTDIR}/base_CPS.d ${OBJECTDIR}/base_CPS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_CPS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_PWM.p1: base_PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_PWM.p1.d
@${RM} ${OBJECTDIR}/base_PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_PWM.p1 base_PWM.c
@-${MV} ${OBJECTDIR}/base_PWM.d ${OBJECTDIR}/base_PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_UART.p1: base_UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_UART.p1.d
@${RM} ${OBJECTDIR}/base_UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_UART.p1 base_UART.c
@-${MV} ${OBJECTDIR}/base_UART.d ${OBJECTDIR}/base_UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_CPS.p1: base_CPS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_CPS.p1.d
@${RM} ${OBJECTDIR}/base_CPS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_CPS.p1 base_CPS.c
@-${MV} ${OBJECTDIR}/base_CPS.d ${OBJECTDIR}/base_CPS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_CPS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_PWM.p1: base_PWM.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_PWM.p1.d
@${RM} ${OBJECTDIR}/base_PWM.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -o${OBJECTDIR}/base_PWM.p1 base_PWM.c
@-${MV} ${OBJECTDIR}/base_PWM.d ${OBJECTDIR}/base_PWM.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_PWM.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" --ram=default,-160-16f -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_12F1840_CPS/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Mon Mar 10 16:56:28 EDT 2014
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=52258db7536b2d1fec300cefc7ed9230
/PIC Projects/PICX_12F1840_CPS/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_12F1840_CPS
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_12F1840_CPS/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_12F1840_CPS/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_12F1840_CPS.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_12F1840_CPS.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx12f1840cps.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx12f1840cps.tar
/PIC Projects/PICX_12F1840_CPS/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_12F1840_CPS.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx12f1840cps/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx12f1840cps/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx12f1840cps.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx12f1840cps.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_12F1840_CPS/nbproject/configurations.xml
0,0 → 1,167
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>base_INTERRUPTS.h</itemPath>
<itemPath>base_UART.h</itemPath>
<itemPath>defines.h</itemPath>
<itemPath>base_CPS.h</itemPath>
<itemPath>base_PWM.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>base_INTERRUPTS.c</itemPath>
<itemPath>base_UART.c</itemPath>
<itemPath>base_CPS.c</itemPath>
<itemPath>base_PWM.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC12F1840</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="false"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0xfff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0xfff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.5"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="advanced-elf" value="true"/>
<property key="output-file-format" value="-mcof,+elf"/>
<property key="stack-size-high" value="auto"/>
<property key="stack-size-low" value="auto"/>
<property key="stack-size-main" value="auto"/>
<property key="stack-type" value="compiled"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_12F1840_CPS/nbproject/project.xml
0,0 → 1,16
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>PICX_12F1840_CPS</name>
<creation-uuid>7fe93e92-3ae3-42d5-9338-2afa3dbfcf6b</creation-uuid>
<make-project-type>0</make-project-type>
<c-extensions>c</c-extensions>
<cpp-extensions/>
<header-extensions>h</header-extensions>
<sourceEncoding>ISO-8859-1</sourceEncoding>
<asminc-extensions/>
<make-dep-projects/>
</data>
</configuration>
</project>
/PIC Projects/PICX_12F1840_CPS/nbproject/project.properties
--- PICX_12F1840_CPS/Makefile (nonexistent)
+++ PICX_12F1840_CPS/Makefile (revision 342)
@@ -0,0 +1,108 @@
+#
+# There exist several targets which are by default empty and which can be
+# used for execution of your targets. These targets are usually executed
+# before and after some main targets. They are:
+#
+# .build-pre: called before 'build' target
+# .build-post: called after 'build' target
+# .clean-pre: called before 'clean' target
+# .clean-post: called after 'clean' target
+# .clobber-pre: called before 'clobber' target
+# .clobber-post: called after 'clobber' target
+# .all-pre: called before 'all' target
+# .all-post: called after 'all' target
+# .help-pre: called before 'help' target
+# .help-post: called after 'help' target
+#
+# Targets beginning with '.' are not intended to be called on their own.
+#
+# Main targets can be executed directly, and they are:
+#
+# build build a specific configuration
+# clean remove built files from a configuration
+# clobber remove all built files
+# all build all configurations
+# help print help mesage
+#
+# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+# .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+# Available make variables:
+#
+# CND_BASEDIR base directory for relative paths
+# CND_DISTDIR default top distribution directory (build artifacts)
+# CND_BUILDDIR default top build directory (object files, ...)
+# CONF name of current configuration
+# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
+# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
+# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
+# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
+# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
+# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
+#
+# NOCDDL
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk
+
+# include project make variables
+include nbproject/Makefile-variables.mk
/PIC Projects/PICX_12F1840_CPS/base_INTERRUPTS.c
0,0 → 1,55
#include <xc.h>
#include "defines.h"
#include "base_INTERRUPTS.h"
#include "base_UART.h"
#include "base_CPS.h"
 
void Interrupt_Enable() {
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
}
 
void interrupt InterruptHandler(void) {
char tmr0_rollover = 0;
// Check to see if we have an interrupt on Timer 0 (CPS)
if (INTCONbits.TMR0IF) {
CPS_Timer_0_Interrupt_Handler();
INTCONbits.TMR0IF = 0;
}
// // Check to see if we have an I2C interrupt
// if (PIR1bits.SSPIF) {
// I2C_Interrupt_Handler();
// PIR1bits.SSPIF = 0;
// }
 
#ifndef UART_TX_ONLY
// Check to see if we have an interrupt on USART1 RX
if (PIR1bits.RCIF) {
UART_Recv_Interrupt_Handler();
PIR1bits.RCIF = 0;
if (INTCONbits.TMR0IF)
tmr0_rollover = 1;
}
#endif
 
// Check to see if we have an interrupt on USART1 TX
if (PIR1bits.TXIF) {
UART_Send_Interrupt_Handler();
// PIR1bits.TXIF = 0;
if (INTCONbits.TMR0IF)
tmr0_rollover = 1;
}
 
// If Timer 0 rolls over while servicing another interrupt handler,
// reset the timers as the sample will be inaccurate.
if (tmr0_rollover) {
CPS_Reset();
}
}
/PIC Projects/PICX_12F1840_CPS/base_INTERRUPTS.h
0,0 → 1,12
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandlerHigh(void);
 
#endif
/PIC Projects/PICX_12F1840_CPS/base_PWM.c
0,0 → 1,33
#include <xc.h>
#include "defines.h"
#include "base_PWM.h"
 
void PWM_Init() {
// Output pin initially blocked
PWM_TRIS = 1;
 
/* Initialize PWM module */
PR2 = 0xF9; // 4ms @ 16MHz
CCP1CONbits.P1M = 0b00; // Single output, P1A modulated only
CCP1CONbits.CCP1M = 0b1100; // PWM mode, P1A active-high, P1B active-high
 
// Idle the output till width is specified
CCPR1L = 0x00;
CCP1CONbits.DC1B = 0b00;
 
/* Initialize Timer 2 */
PIR1bits.TMR2IF = 0; // Clear the interrupt flag for Timer 2
T2CONbits.T2CKPS = 0b11; // Set a prescaler of 64
T2CONbits.TMR2ON = 1; // Enable the timer
 
// Wait for the timer to overflow before enabling output
while (!PIR1bits.TMR2IF);
PWM_TRIS = 0;
}
 
void PWM_Set_Width(int width_us) {
// Set the pulse duration to the requested width
int value = width_us / 4;
CCPR1L = value >> 2;
CCP1CONbits.DC1B = value;
}
/PIC Projects/PICX_12F1840_CPS/base_PWM.h
0,0 → 1,12
#ifndef PWM_H
#define PWM_H
 
#define PWM_Width_Min 510
#define PWM_Width_Max 2300
#define PWM_Width_Mid 1350
 
void PWM_Init(void);
 
void PWM_Set_Width(int width_us);
 
#endif
/PIC Projects/PICX_12F1840_CPS/base_UART.c
0,0 → 1,137
#include <xc.h>
#include "defines.h"
#include "base_UART.h"
 
static UART_DATA *uart_data_p;
 
void UART_Init(UART_DATA *data) {
uart_data_p = data;
 
UART_TX_TRIS = 0; // Tx pin set to output
#ifndef UART_TX_ONLY
UART_RX_TRIS = 1; // Rx pin set to input
#endif
LATAbits.LATA0 = 1; // Keep the line high at start
 
BAUDCONbits.BRG16 = 0; // 8-bit baud rate generator
SPBRGL = 25; // Set UART speed to 38400 baud
TXSTAbits.BRGH = 1; // High speed mode
 
TXSTAbits.SYNC = 0; // Async mode
RCSTAbits.SPEN = 1; // Serial port enable
 
TXSTAbits.TX9 = 0; // 8 bit transmission
 
TXSTAbits.TXEN = 1; // Transmission enabled
 
PIE1bits.TXIE = 0; // Disable TX interrupt
#ifndef UART_TX_ONLY
RCSTAbits.RX9 = 0; // 8 bit reception
RCSTAbits.CREN = 1; // Enables receiver
PIE1bits.RCIE = 1; // Enable RX interrupt
 
// Initialize the buffer that holds UART messages
uart_data_p->buffer_in_read_ind = 0;
uart_data_p->buffer_in_write_ind = 0;
uart_data_p->buffer_in_len = 0;
uart_data_p->buffer_in_len_tmp = 0;
#else
RCSTAbits.CREN = 0;
#endif
uart_data_p->buffer_out_ind = 0;
uart_data_p->buffer_out_len = 0;
}
 
void UART_Send_Interrupt_Handler() {
// Put remaining data in TSR for transmit
if (uart_data_p->buffer_out_ind != uart_data_p->buffer_out_len) {
TXREG = uart_data_p->buffer_out[uart_data_p->buffer_out_ind];
uart_data_p->buffer_out_ind++;
} else {
while (!TXSTAbits.TRMT); // Wait for last byte to finish sending
PIE1bits.TXIE = 0;
uart_data_p->buffer_out_ind = 0;
uart_data_p->buffer_out_len = 0;
}
}
 
void UART_Write(const char *string, char length) {
while (PIE1bits.TXIE); // Wait for previous message to finish sending
uart_data_p->buffer_out_len = length;
uart_data_p->buffer_out_ind = 1;
for (char i = 0; i < length; i++) {
uart_data_p->buffer_out[i] = string[i];
}
TXREG = uart_data_p->buffer_out[0]; // Put first byte in TSR
PIE1bits.TXIE = 1;
}
 
void UART_WriteD(const char* string, char length) {
PIE1bits.TXIE = 1;
for (char i = 0; i < length; i++) {
TXREG = string[i];
NOP();
while (!PIR1bits.TXIF);
}
PIE1bits.TXIE = 0;
}
 
#ifndef UART_TX_ONLY
void UART_Recv_Interrupt_Handler() {
if (PIR1bits.RCIF) { // Check if data receive flag is set
char c = RCREG;
 
// Save received data into buffer
uart_data_p->buffer_in[uart_data_p->buffer_in_write_ind] = c;
if (uart_data_p->buffer_in_write_ind == MAXUARTBUF - 1) {
uart_data_p->buffer_in_write_ind = 0;
} else {
uart_data_p->buffer_in_write_ind++;
}
 
// Store the last MAXUARTBUF values entered
if (uart_data_p->buffer_in_len_tmp < MAXUARTBUF) {
uart_data_p->buffer_in_len_tmp++;
} else {
if (uart_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_data_p->buffer_in_read_ind = 0;
} else {
uart_data_p->buffer_in_read_ind++;
}
}
 
// Update buffer size upon receiving newline (0x0D)
if (c == UART_BREAK_CHAR) {
uart_data_p->buffer_in_len = uart_data_p->buffer_in_len_tmp;
uart_data_p->buffer_in_len_tmp = 0;
}
}
 
if (RCSTAbits.OERR == 1) {
// We've overrun the USART and must reset
TXSTAbits.TXEN = 0; // Kill anything currently sending
RCSTAbits.CREN = 0; // Reset UART1
RCSTAbits.CREN = 1;
}
}
 
char UART_Buffer_Len() {
return uart_data_p->buffer_in_len;
}
 
/* Reader interface to the UART buffer, returns the number of bytes read */
char UART_Read_Buffer(char *buffer) {
char i = 0;
while (uart_data_p->buffer_in_len != 0) {
buffer[i] = uart_data_p->buffer_in[uart_data_p->buffer_in_read_ind];
i++;
if (uart_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_data_p->buffer_in_read_ind = 0;
} else {
uart_data_p->buffer_in_read_ind++;
}
uart_data_p->buffer_in_len--;
}
return i;
}
#endif
/PIC Projects/PICX_12F1840_CPS/base_UART.h
0,0 → 1,33
#ifndef UART_H
#define UART_H
 
#define UART_TX_ONLY
 
#define UART_BUFFER_SIZE 32
#define UART_BREAK_CHAR 0x0D
 
typedef struct {
#ifndef UART_TX_ONLY
char buffer_in[UART_BUFFER_SIZE];
volatile char buffer_in_read_ind;
volatile char buffer_in_write_ind;
volatile char buffer_in_len;
volatile char buffer_in_len_tmp;
#endif
 
volatile char buffer_out[UART_BUFFER_SIZE];
volatile char buffer_out_ind;
volatile char buffer_out_len;
} UART_DATA;
 
void UART_Init(UART_DATA *data);
void UART_Send_Interrupt_Handler(void);
void UART_Write(const char *string, char length);
void UART_WriteD(const char *string, char length);
#ifndef UART_TX_ONLY
void UART_Recv_Interrupt_Handler(void);
char UART_Buffer_Len(void);
char UART_Read_Buffer(char *buffer);
#endif
 
#endif
/PIC Projects/PICX_12F1840_CPS/defines.h
0,0 → 1,18
#ifndef DEFINES_H
#define DEFINES_H
 
// Preprocessor define for __delay_ms() and __delay_us()
#define _XTAL_FREQ 32000000
 
#define CPS_0_TRIS TRISAbits.TRISA0
#define CPS_1_TRIS TRISAbits.TRISA1
 
#define LED_TRIS TRISAbits.TRISA2
#define LED_LAT LATAbits.LATA2
 
#define UART_TX_TRIS TRISAbits.TRISA4
 
#define PWM_TRIS TRISAbits.TRISA5
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_12F1840_CPS/main.c
0,0 → 1,87
#include <xc.h>
#include "defines.h"
#include "base_INTERRUPTS.h"
//#include "base_UART.h"
#include "base_CPS.h"
#include "base_PWM.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
/* Config Register CONFIGL @ 0x8007 */
#pragma config CPD = OFF // Data memory code protection is disabled
#pragma config BOREN = OFF // Brown-out Reset disabled
#pragma config IESO = OFF // Internal/External Switchover mode is disabled
#pragma config FOSC = INTOSC // INTOSC oscillator: I/O function on CLKIN pin
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor is disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config WDTE = OFF // WDT disabled
#pragma config CP = OFF // Program memory code protection is disabled
#pragma config PWRTE = OFF // PWRT disabled
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
 
/* Config Register CONFIG2 @ 0x8008 */
#pragma config PLLEN = OFF // 4x PLL disabled
#pragma config WRT = OFF // Write protection off
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
#pragma config BORV = HI // Brown-out Reset Voltage (Vbor), high trip point selected.
#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming
// </editor-fold>
 
int main() {
 
// Oscillator configuration (16Mhz HFINTOSC)
OSCCONbits.SCS = 0b00;
OSCCONbits.IRCF = 0b1111;
ANSELA = 0x00; // All pins set to digital I/O
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
APFCONbits.TXCKSEL = 1; // Switch TX/CK from RA0 to RA4
APFCONbits.RXDTSEL = 1; // Switch RX/DT from RA1 to RA5
 
/* Set pins as analog */
/* 0x01 = ANSA0 (RA0)
* 0x02 = ANSA1 (RA1)
* 0x04 = ANSA2 (RA2)
* 0x10 = ANSA4 (RA4) */
ANSELA = 0x03;
Interrupt_Enable();
 
// UART_DATA uart_data;
// UART_Init(&uart_data);
 
CPS_DATA cps_data;
CPS_Init(&cps_data);
 
PWM_Init();
// char msg[] = "Begin Program\n";
// UART_Write(msg, 14);
 
LED_TRIS = 0;
 
while(1) {
// __delay_ms(10);
 
// unsigned int value = cps_data.btn_last_value[cps_data.channel];
// unsigned int avg = cps_data.btn_avg_value[cps_data.channel];
// unsigned char output[9];
// output[0] = cps_data.channel;
// output[1] = 0;
// output[2] = value >> 8;
// output[3] = value;
// output[4] = 0;
// output[5] = avg >> 8;
// output[6] = avg;
// output[7] = 0;
// output[8] = cps_data.btn_pct_value[cps_data.channel];
// UART_WriteD(output, 9);
 
if (cps_data.btn_pressed[0] || cps_data.btn_pressed[1]) {
LED_LAT = 1;
PWM_Set_Width(1350);
} else {
LED_LAT = 0;
PWM_Set_Width(800);
}
}
}
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sat Jan 25 17:17:04 EST 2014
default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=83f4565fa27ad9b8015f63d69ef74f66
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc32\\v1.31\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
default.languagetoolchain.version=1.31
host.platform=windows
conf.ids=default
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Makefile-default.mk
0,0 → 1,160
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c ETHERNET.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/ETHERNET.o
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/ETHERNET.o.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/ETHERNET.o
 
# Source Files
SOURCEFILES=main.c ETHERNET.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=32MX795F512L
MP_LINKER_FILE_OPTION=
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assembleWithPreprocess
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/ETHERNET.o: ETHERNET.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ETHERNET.o.d
@${RM} ${OBJECTDIR}/ETHERNET.o
@${FIXDEPS} "${OBJECTDIR}/ETHERNET.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -MMD -MF "${OBJECTDIR}/ETHERNET.o.d" -o ${OBJECTDIR}/ETHERNET.o ETHERNET.c
else
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.c
${OBJECTDIR}/ETHERNET.o: ETHERNET.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/ETHERNET.o.d
@${RM} ${OBJECTDIR}/ETHERNET.o
@${FIXDEPS} "${OBJECTDIR}/ETHERNET.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -MMD -MF "${OBJECTDIR}/ETHERNET.o.d" -o ${OBJECTDIR}/ETHERNET.o ETHERNET.c
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: compileCPP
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) -mdebugger -D__MPLAB_DEBUGGER_PK3=1 -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -mreserve=data@0x0:0x1FC -mreserve=boot@0x1FC02000:0x1FC02FEF -mreserve=boot@0x1FC02000:0x1FC024FF -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),--defsym=__MPLAB_DEBUG=1,--defsym=__DEBUG=1,--defsym=__MPLAB_DEBUGGER_PK3=1,-Map="${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.map"
else
dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),-Map="${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.map"
${MP_CC_DIR}\\xc32-bin2hex dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=Cerebot_MX7CK_Ethernet
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_25-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-gcc.exe"
MP_CPPC="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-g++.exe"
# MP_BC is not defined
MP_AS="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-as.exe"
MP_LD="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-ld.exe"
MP_AR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin\xc32-ar.exe"
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_CPPC_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
# MP_BC_DIR is not defined
MP_AS_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_LD_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
MP_AR_DIR="C:\Program Files (x86)\Microchip\xc32\v1.31\bin"
# MP_BC_DIR is not defined
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=Cerebot_MX7CK_Ethernet.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/Cerebot_MX7CK_Ethernet.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=cerebotmx7ckethernet.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/cerebotmx7ckethernet.tar
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=Cerebot_MX7CK_Ethernet.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=cerebotmx7ckethernet/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/cerebotmx7ckethernet/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/cerebotmx7ckethernet.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/cerebotmx7ckethernet.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/configurations.xml
0,0 → 1,164
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>ETHERNET.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>ETHERNET.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC32MX795F512L</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PK3OBPlatformTool</platformTool>
<languageToolchain>XC32</languageToolchain>
<languageToolchainVersion>1.31</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<C32>
<property key="additional-warnings" value="false"/>
<property key="enable-app-io" value="false"/>
<property key="enable-omit-frame-pointer" value="false"/>
<property key="enable-symbols" value="true"/>
<property key="enable-unroll-loops" value="false"/>
<property key="exclude-floating-point" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="generate-micro-compressed-code" value="false"/>
<property key="isolate-each-function" value="false"/>
<property key="make-warnings-into-errors" value="false"/>
<property key="optimization-level" value=""/>
<property key="place-data-into-section" value="false"/>
<property key="post-instruction-scheduling" value="default"/>
<property key="pre-instruction-scheduling" value="default"/>
<property key="preprocessor-macros" value=""/>
<property key="strict-ansi" value="false"/>
<property key="support-ansi" value="false"/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="use-indirect-calls" value="false"/>
</C32>
<C32-AS>
</C32-AS>
<C32-LD>
<property key="additional-options-use-response-files" value="false"/>
<property key="enable-check-sections" value="false"/>
<property key="exclude-floating-point-library" value="false"/>
<property key="exclude-standard-libraries" value="false"/>
<property key="extra-lib-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="generate-cross-reference-file" value="false"/>
<property key="generate-micro-compressed-code" value="false"/>
<property key="heap-size" value=""/>
<property key="input-libraries" value=""/>
<property key="linker-symbols" value=""/>
<property key="map-file" value="${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.map"/>
<property key="no-startup-files" value="false"/>
<property key="oXC32ld-extra-opts" value=""/>
<property key="optimization-level" value=""/>
<property key="preprocessor-macros" value=""/>
<property key="remove-unused-sections" value="false"/>
<property key="report-memory-usage" value="false"/>
<property key="stack-size" value=""/>
<property key="symbol-stripping" value=""/>
<property key="trace-symbols" value=""/>
<property key="warn-section-align" value="false"/>
</C32-LD>
<C32CPP>
<property key="additional-warnings" value="false"/>
<property key="check-new" value="false"/>
<property key="eh-specs" value="true"/>
<property key="enable-app-io" value="false"/>
<property key="enable-omit-frame-pointer" value="false"/>
<property key="enable-symbols" value="true"/>
<property key="enable-unroll-loops" value="false"/>
<property key="exceptions" value="true"/>
<property key="exclude-floating-point" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="generate-micro-compressed-code" value="false"/>
<property key="isolate-each-function" value="false"/>
<property key="make-warnings-into-errors" value="false"/>
<property key="optimization-level" value=""/>
<property key="place-data-into-section" value="false"/>
<property key="post-instruction-scheduling" value="default"/>
<property key="pre-instruction-scheduling" value="default"/>
<property key="preprocessor-macros" value=""/>
<property key="rtti" value="true"/>
<property key="strict-ansi" value="false"/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="use-indirect-calls" value="false"/>
</C32CPP>
<C32Global>
<property key="legacy-libc" value="false"/>
<property key="save-temps" value="false"/>
<property key="wpo-lto" value="false"/>
</C32Global>
<PK3OBPlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="firmware.download.all" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1d07ffff"/>
<property key="memories.programmemory.start" value="0x1d000000"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1d0001ff"/>
<property key="programoptions.preserveprogramrange.start" value="0x1d000000"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PK3OBPlatformTool>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/Cerebot_32MX7_Ethernet/nbproject/project.properties
--- Cerebot_32MX7_Ethernet/nbproject/project.xml (nonexistent)
+++ Cerebot_32MX7_Ethernet/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>Cerebot_MX7CK_Ethernet</name>
+ <creation-uuid>f0462d5a-dd1f-4567-9500-a142dc818c0d</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>US-ASCII</sourceEncoding>
+ <asminc-extensions/>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/Cerebot_32MX7_Ethernet/ETHERNET.c
0,0 → 1,349
#include "defines.h"
#include "ETHERNET.h"
 
static ETH_DATA *eth_data;
 
/* Function to convert from virtual address to physical address
See 3.4.1 in reference manual for explanation */
uint32_t VA_TO_PA(uint32_t ptr) {
uint32_t ret = ptr & 0x1FFFFFFF;
return ret;
}
 
void ETH_Init(ETH_DATA *data, void(*tx_callback)(void), void(*rx_callback)(void)) {
// Save a pointer to the descriptor tables
eth_data = data;
eth_data->tx_callback = tx_callback;
eth_data->rx_callback = rx_callback;
 
// Bring the PHY reset line high to initialize the PHY
PHY_RESET_TRIS = 0;
PHY_RESET_LAT = 0;
Delay_US(100);
PHY_RESET_LAT = 1;
 
INTDisableInterrupts();
 
// Initialize the I/O lines (dont actually need this)
ETH_MDC_TRIS = 0;
ETH_MDIO_TRIS = 1;
ETH_TXEN_TRIS = 0;
ETH_TXD0_TRIS = 0;
ETH_TXD1_TRIS = 0;
ETH_RXCLK_TRIS = 1;
ETH_RXDV_TRIS = 1;
ETH_RXD0_TRIS = 1;
ETH_RXD1_TRIS = 1;
ETH_RXERR_TRIS = 1;
 
eth_data->TX_descriptor_index = 0;
eth_data->RX_descriptor_index = 0;
 
// Initialize values in the descriptor tables
uint8_t i;
for (i = 0; i < ETH_TX_DESCRIPTOR_COUNT; i++) {
// Set the NPV values for each descriptor (linear list)
eth_data->TX_ED_table.descriptor[i].NPV = 0;
// Set the EOWN values for each descriptor
eth_data->TX_ED_table.descriptor[i].EOWN = 0;
 
// Assign a data buffer to each descriptor
eth_data->TX_ED_table.descriptor[i].BUFFER_ADDR = VA_TO_PA((uint32_t)eth_data->TX_ED_buffer[i]);
}
for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
// Set the NPV values for each descriptor (linear list)
eth_data->RX_ED_table.descriptor[i].NPV = 0;
 
// Set the EOWN values for each descriptor
eth_data->RX_ED_table.descriptor[i].EOWN = 1;
 
// Assign a data buffer to each descriptor
eth_data->RX_ED_table.descriptor[i].BUFFER_ADDR = VA_TO_PA((uint32_t)eth_data->RX_ED_buffer[i]);
}
 
// On the last descriptor, save the address to the beginning of the list
eth_data->TX_ED_table.descriptor[ETH_TX_DESCRIPTOR_COUNT-1].NPV = 1;
eth_data->RX_ED_table.descriptor[ETH_RX_DESCRIPTOR_COUNT-1].NPV = 1;
 
// Set the last RX descriptor EOWN to software, thus using list configuration
// eth_data->TX_ED_table.descriptor[ETH_TX_DESCRIPTOR_COUNT-1].EOWN = 0;
// eth_data->RX_ED_table.descriptor[ETH_RX_DESCRIPTOR_COUNT-1].EOWN = 0;
 
// Loop the end of the descriptor table to the beginning (ring configuration)
eth_data->TX_ED_table.next_ED = VA_TO_PA((uint32_t)eth_data->TX_ED_table.descriptor);
eth_data->RX_ED_table.next_ED = VA_TO_PA((uint32_t)eth_data->RX_ED_table.descriptor);
 
// Save the head of the table to the corresponding ETH register
ETHTXST = VA_TO_PA((uint32_t)eth_data->TX_ED_table.descriptor);
ETHRXST = VA_TO_PA((uint32_t)eth_data->RX_ED_table.descriptor);
 
// Ethernet Initialization Sequence: see section 35.4.10 in the PIC32 Family Reference Manual
// Part 1. Ethernet Controller Initialization
IEC1bits.ETHIE = 0; // Disable ethernet interrupts
ETHCON1bits.ON = 0; // Disable the ethernet module
ETHCON1bits.TXRTS = 0; // Stop transmit logic
ETHCON1bits.RXEN = 0; // Stop receive logic
ETHCON1bits.AUTOFC = 0;
ETHCON1bits.MANFC = 0;
while (ETHSTATbits.ETHBUSY);
IFS1bits.ETHIF = 0; // Clear interrupt flags
ETHIENCLR = 0xFFFF; // Clear the ETHIEN register (interrupt enable)
 
// Part 2. MAC Init
EMAC1CFG1bits.SOFTRESET = 1; // Put the MACMII in reset
EMAC1CFG1bits.SOFTRESET = 0;
// Default I/O configuration, RMII operating mode
EMAC1SUPPbits.RESETRMII = 1; // Reset the MAC RMII module
EMAC1MCFGbits.RESETMGMT = 1; // Reset the MII management module
EMAC1MCFGbits.RESETMGMT = 0;
EMAC1MCFGbits.CLKSEL = 0x8; // Set the MIIM PHY clock to SYSCLK/40
while(EMAC1MINDbits.MIIMBUSY);
 
// Part 3. PHY Init
// Contrary to the ref manual, the ETH module needs to be enabled for the MIIM to work
 
ETHCON1bits.ON = 1; // Enable the ethernet module
uint16_t value;
// Reset the PHY chip
ETH_PHY_Write(PHY_ADDRESS, 0x0, 0x8000);
do {
value = ETH_PHY_Read(PHY_ADDRESS, 0x0);
} while (value & 0x8000 != 0);
 
// Delay to wait for the link to be established
Delay_MS(5000);
// Wait for auto-negotiation to finish
do {
value = ETH_PHY_Read(PHY_ADDRESS, 0x1F); // Acquire link status
} while (value & 0x1000 == 0);
 
ETHCON1bits.ON = 0; // Disable the ethernet module before changing other settings
// Part 4. MAC Configuration
EMAC1CFG1bits.RXENABLE = 1; // Enable the MAC receiving of frames
EMAC1CFG1bits.TXPAUSE = 1; // Enable PAUSE flow control frames
EMAC1CFG1bits.RXPAUSE = 1; // Enable processing of PAUSE control frames
EMAC1CFG2bits.AUTOPAD = 0; // No auto-detection for VLAN padding
EMAC1CFG2bits.VLANPAD = 0; // MAC does not perform padding of short frames
EMAC1CFG2bits.PADENABLE = 1; // Pad all short frames
EMAC1CFG2bits.CRCENABLE = 1; // Append a CRC to every frame
EMAC1CFG2bits.HUGEFRM = 1; // Allow frames of any length
EMAC1CFG2bits.LENGTHCK = 0; // Check the frame lengths to the length/type field
if ((value & 0x14) || (value & 0x18)) {
EMAC1CFG2bits.FULLDPLX = 1; // Operate in full-duplex mode
EMAC1IPGT = 0x15; // Back-to-back interpacket gap @ 0.96us/9.6us
// LED1_LAT = 1;
} else {
EMAC1CFG2bits.FULLDPLX = 0; // Operate in half-duplex mode
EMAC1IPGT = 0x12; // Back-to-back interpacket gap @ 0.96us/9.6us
// LED2_LAT = 1;
}
if ((value & 0x08) || (value & 0x18)) {
EMAC1SUPPbits.SPEEDRMII = 1; // 100Mbps mode
// LED3_LAT = 1;
} else {
EMAC1SUPPbits.SPEEDRMII = 0; // 10Mbps mode
// LED4_LAT = 1;
}
EMAC1IPGRbits.NB2BIPKTGP1 = 0xC; // Set some other delay gap values
EMAC1IPGRbits.NB2BIPKTGP2 = 0x12;
EMAC1CLRTbits.CWINDOW = 0x37; // Set collision window to count of frame bytes
EMAC1CLRTbits.RETX = 0xF; // Set number of retransmission attempts
EMAC1MAXF = 0x7F4; // Set the maximum frame length to 2046 bits
// Default MAC address is 00-04-A3-1A-4C-FC
// Set MAC address to 00-18-3E-00-D7-EB
EMAC1SA0 = 0xEBD7;
EMAC1SA1 = 0x003E;
EMAC1SA2 = 0x1800;
 
// Part 5. Ethernet Controller Initialization cont.
// Flow control is off by default!
ETHRXFCbits.HTEN = 0; // Disable hash table filtering
ETHRXFCbits.MPEN = 0; // Disable magic packet filtering
ETHRXFCbits.PMMODE = 0; // Disable pattern matching
ETHRXFCbits.CRCERREN = 0; // Disable CRC error collection filtering
ETHRXFCbits.CRCOKEN = 0; // Disable CRC filtering
ETHRXFCbits.RUNTERREN = 0; // Disable runt error collection filtering
ETHRXFCbits.RUNTEN = 0; // Disable runt filtering
ETHRXFCbits.UCEN = 1; // Enable unicast filtering
ETHRXFCbits.NOTMEEN = 0; // Disable acceptance of packets to other destinations
ETHRXFCbits.MCEN = 0; // Disable multicast filtering
ETHRXFCbits.BCEN = 0; // Disable broadcast filtering
 
ETHCON2bits.RXBUF_SZ = 0x7F; // Set RX data buffer size to 2032 bytes
 
EMAC1SUPPbits.RESETRMII = 0; // Bring the RMII module out of reset
ETHCON1bits.ON = 1; // Enable the ethernet module
 
ETHCON1bits.RXEN = 1; // Start receive logic
 
ETHIENbits.TXBUSEIE = 1; // Enable interrupt on transmit BVCI bus error
ETHIENbits.RXBUSEIE = 1; // Enable interrupt on receive BVCI bus error
// ETHIENbits.RXDONEIE = 1; // Enable interrupt on packet received
ETHIENbits.PKTPENDIE = 1; // Enable interrupt on packet pending
// ETHIENbits.RXACTIE = 1;
ETHIENbits.TXDONEIE = 1; // Enable interrupt on packet sent
ETHIENbits.TXABORTIE = 1; // Enable interrupt on packet send aborted
 
IPC12bits.ETHIP = 1; // Set interrupt priority to 1
IPC12bits.ETHIS = 1; // Set intererupt sub-priority to 1
IEC1bits.ETHIE = 1; // Enable ethernet interrupts
 
INTEnableInterrupts();
}
 
/* Reads from the specified register on the PHY chip */
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg) {
EMAC1MADR = reg | (address << 8);
EMAC1MCMDbits.READ = 1;
Nop();Nop();Nop();
while (EMAC1MINDbits.MIIMBUSY);
EMAC1MCMDbits.READ = 0;
return EMAC1MRDD;
}
 
/* Write to the specified register on the PHY chip */
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value) {
EMAC1MADR = reg | (address << 8);
EMAC1MWTD = value;
Nop();Nop();Nop();
while (EMAC1MINDbits.MIIMBUSY);
}
 
/* Queries the number of pending packets */
uint8_t ETH_Recv_Queue(void) {
return ETHSTATbits.BUFCNT;
}
 
/* Function to read a single packet (<2014 bytes) */
uint8_t ETH_Read_Packet(uint8_t *buffer, uint16_t *length) {
uint16_t i, j;
uint16_t size;
uint8_t descriptor_index = eth_data->RX_descriptor_index;
 
// Look for the first descriptor where EOWN is cleared and SOP/EOP is set
for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
if ((eth_data->RX_ED_table.descriptor[descriptor_index].EOWN == 0) &&
(eth_data->RX_ED_table.descriptor[descriptor_index].SOP == 1) &&
(eth_data->RX_ED_table.descriptor[descriptor_index].EOP == 1)) {
 
// Read the packet data values into the buffer
size = eth_data->RX_ED_table.descriptor[descriptor_index].BYTE_COUNT - 18;
*length = size;
for (j = 0; j < size - 18; j++) {
buffer[j] = eth_data->RX_ED_buffer[descriptor_index][j+14];
}
 
// Reset the descriptors
eth_data->RX_ED_table.descriptor[descriptor_index].SOP = 0;
eth_data->RX_ED_table.descriptor[descriptor_index].EOP = 0;
eth_data->RX_ED_table.descriptor[descriptor_index].EOWN = 1;
 
eth_data->RX_descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
 
ETHCON1bits.BUFCDEC = 1;
return 0;
 
} else {
descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
}
}
 
return 1;
}
 
/* Function to send a single packet (<2018 bytes) */
uint8_t ETH_Write_Packet(ETH_MAC_ADDRESS dest, ETH_MAC_ADDRESS src, uint16_t length, uint8_t *buffer) {
uint16_t i;
uint16_t write_index = 0;
uint16_t read_index = 0;
uint16_t descriptor_index = eth_data->TX_descriptor_index;
 
// Do a quick sanity check to ensure that we have enough memory to send the message
if (length > ETH_TX_ED_BUFFER_SIZE - 14)
return 1;
 
// Fill the descriptor
eth_data->TX_ED_table.descriptor[descriptor_index].TSV.registers[0] = 0;
eth_data->TX_ED_table.descriptor[descriptor_index].TSV.registers[1] = 0;
eth_data->TX_ED_table.descriptor[descriptor_index].EOWN = 1;
eth_data->TX_ED_table.descriptor[descriptor_index].SOP = 1;
eth_data->TX_ED_table.descriptor[descriptor_index].EOP = 1;
 
for (i = 0; i < 6; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = dest.bytes[i];
write_index++;
}
for (i = 0; i < 6; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = src.bytes[i];
write_index++;
}
eth_data->TX_ED_buffer[descriptor_index][write_index] = length >> 8;
eth_data->TX_ED_buffer[descriptor_index][write_index+1] = length;
write_index += 2;
 
 
eth_data->TX_ED_table.descriptor[descriptor_index].BYTE_COUNT = length + 14;
 
for (i = 0; i < length; i++) {
eth_data->TX_ED_buffer[descriptor_index][write_index] = buffer[read_index];
write_index++;
read_index++;
}
 
// Wait for any previous transmits to finish before sending
while (ETHSTATbits.TXBUSY);
ETHCON1bits.TXRTS = 1;
while (ETHSTATbits.TXBUSY);
 
eth_data->TX_descriptor_index = (descriptor_index == ETH_TX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
return 0;
}
 
void __ISR(_ETH_VECTOR, ipl1) __ETH_Interrupt_Handler(void) {
uint32_t value = ETHIRQ;
if (ETHIRQbits.TXBUSE) {
 
ETHIRQbits.TXBUSE = 0;
}
if (ETHIRQbits.RXBUSE) {
 
ETHIRQbits.RXBUSE = 0;
}
// if (ETHIRQbits.RXDONE) {
// ETHIRQbits.RXDONE = 0;
// }
if (ETHIRQbits.PKTPEND) {
if (eth_data->rx_callback != NULL)
(*eth_data->rx_callback)();
ETHIRQbits.PKTPEND = 0;
}
if (ETHIRQbits.TXDONE) {
if (eth_data->tx_callback != NULL)
(*eth_data->tx_callback)();
ETHIRQbits.TXDONE = 0;
}
if (ETHIRQbits.TXABORT) {
 
ETHIRQbits.TXABORT = 0;
}
if (ETHIRQbits.RXBUFNA) {
// This is a serious error!
 
ETHIRQbits.RXBUFNA = 0;
}
if (ETHIRQbits.RXOVFLW) {
// This is a serious error!
 
ETHIRQbits.RXOVFLW = 0;
}
 
IFS1bits.ETHIF = 0;
}
/PIC Projects/Cerebot_32MX7_Ethernet/ETHERNET.h
0,0 → 1,162
#ifndef ETHERNET_H
#define ETHERNET_H
 
#define ETH_TX_DESCRIPTOR_COUNT 2
#define ETH_RX_DESCRIPTOR_COUNT 2
#define ETH_TX_ED_BUFFER_SIZE 2032
#define ETH_RX_ED_BUFFER_SIZE 2032
 
#ifdef CEREBOT_MX7CK
#define PHY_RESET_TRIS TRISAbits.TRISA6
#define PHY_RESET_LAT LATAbits.LATA6
#endif
#ifdef CEREBOT_32MX7
#define PHY_RESET_TRIS TRISEbits.TRISE9
#define PHY_RESET_LAT LATEbits.LATE9
#endif
#define ETH_MDC_TRIS TRISDbits.TRISD11
#define ETH_MDIO_TRIS TRISDbits.TRISD8
#define ETH_TXEN_TRIS TRISDbits.TRISD6
#define ETH_TXD0_TRIS TRISFbits.TRISF1
#define ETH_TXD1_TRIS TRISFbits.TRISF0
#define ETH_RXCLK_TRIS TRISGbits.TRISG9
#define ETH_RXDV_TRIS TRISGbits.TRISG8
#define ETH_RXD0_TRIS TRISBbits.TRISB12
#define ETH_RXD1_TRIS TRISBbits.TRISB13
#define ETH_RXERR_TRIS TRISBbits.TRISB11
 
#define PHY_ADDRESS 0x0
 
typedef union {
struct {
uint8_t BYTE_0;
uint8_t BYTE_1;
uint8_t BYTE_2;
uint8_t BYTE_3;
uint8_t BYTE_4;
uint8_t BYTE_5;
};
uint8_t bytes[6];
} ETH_MAC_ADDRESS;
 
typedef union {
struct {
// Bits 31:0
unsigned BYTE_COUNT : 16; // Total bytes in frame not counting collided bytes
unsigned COLLISION_COUNT : 4; // Number of collisions current packet incurred durrent transmit attempts
unsigned CRC_ERROR : 1; // Attached CRC did not match the internal generated CRC
unsigned LENGTH_CHECK_ERROR : 1; // Frame length field value in packet does not match actual data byte length and is not a Type field
unsigned LENGTH_OUT_OF_RANGE : 1; // Frame type/length field was larger than 1500 bytes
unsigned DONE : 1; // Transmit of packet was completed
unsigned MULTICASE : 1; // Destination address was a multicast address
unsigned BROADCAST : 1; // Destination address was a broadcast address
unsigned PACKET_DEFER : 1; // Packet was deferred for at least one attempt
unsigned EXCESSIVE_DEFER : 1; // Packet was defered in excess of 6071/24287 nibble(100Mbps)/bit(10Mbps) times
unsigned MAXIMUM_COLLISION : 1; // Packet aborted, number of collisions exceeded RETX
unsigned LATE_COLLISION : 1; // Collision occurred beyond the collision window (512 bit times)
unsigned GIANT : 1; // Frame byte count greater than MACMAXF
unsigned UNDERRUN : 1; // Failed to transfer complete packet to the transmit MAC module
// Bits 63:32
unsigned BYTES_TRANSMITTED : 16; // Total bytes transmitted on wire (including collisions)
unsigned CONTROL_FRAME : 1; // Frame transmitted was a control frame
unsigned PAUSE_CONTROL_FRAME : 1; // Frame transmitted was a control frame with a valid PAUSE Op code
unsigned BACKPRESSURE : 1; // Carrier-sense method backpressure was previously applied
unsigned VLAN_TAGGED : 1; // Frame length/type field contained 0x8100 (VLAN protocol identifier)
unsigned : 12;
};
uint32_t registers[2];
} ETH_TRANSMIT_STATUS_VECTOR;
 
typedef union {
struct {
// Bits 31:0
unsigned BYTE_COUNT : 16; // Length of received frame
unsigned LONG_DROP_EVENT : 1; // Packet over 50000 bit times occured or packet since last RSV was dropped
unsigned RXDV_EVENT : 1; // Last receive event seen not long enough to be a valid packet
unsigned CARRIER_EVENT : 1; // Carrier event detected, noted, and reported
unsigned CODE_VIOLATION : 1; // MII data does not represent a valid data code when MRXER asserted
unsigned CRC_ERROR : 1; // Frame CRC does not match the CRC calculated by the receiver MAC
unsigned LENGTH_CHECK_ERROR : 1; // Frame length field value doe snot match the actual data byte length
unsigned LENGTH_OUT_OF_RANGE : 1; // Frame type/length field was larger than 1500 bytes
unsigned RECEIVE_OK : 1; // Packet has a valid CRC and no symbol errors
unsigned MULTICAST : 1; // Packet had a valid multicast address
unsigned BROADCAST : 1; // Packet had a valid broadcast address
unsigned DRIBBLE_NIBBLE : 1; // An additional 1-7 bits received after packet
unsigned CONTROL_FRAME : 1; // Frame recognized as a control frame
unsigned PAUSE_CONTROL_FRAME : 1; // Frame recognized as a control frame with a valid PAUSE Op code
unsigned UNKNOWN_OP_CODE : 1; // Frame recognized as a control frame but with an unknown Op code
unsigned VLAN_TAGGED : 1; // Frame recognized as a VLAN tagged frame
unsigned : 1;
// Bits 63:32;
unsigned PKT_CHECKSUM : 16; // RX packet payload checksum of this descriptor's packet
unsigned : 8;
unsigned RUNT_PACKET : 1; // Runt packet
unsigned BROADCAST_OR_NOT_DEST : 1; // NOT unicast match AND NOT multicast match
unsigned HASH_TABLE_MATCH : 1; // Hash table match
unsigned MAGIC_PACKET_MATCH : 1; // Magic packet match
unsigned PATTERN_MATCH : 1; // Pattern match
unsigned UNICAST_MATCH : 1; // Unicast match
unsigned BROADCAST_MATCH : 1; // Broadcast match
unsigned MULTICAST_MATCH : 1; // Multicast match
};
uint32_t registers[2];
} ETH_RECEIVE_STATUS_VECTOR;
 
typedef struct {
unsigned : 7;
unsigned EOWN : 1; // Ethernet controller own bit (1 = ED owned by controller, do not modify)
unsigned NPV : 1; // Next ED pointer valid enable bit (1 = NEXT_ED field exists)
unsigned : 7;
unsigned BYTE_COUNT : 11; // Number of bytes to be transmited for this descriptor (1-2047)
unsigned : 3;
unsigned EOP : 1; // End of packet enable bit (1 = transmit end of packet delimiter)
unsigned SOP : 1; // Start of packet enable bit (1 = transmit start of packet delimiter)
uint32_t BUFFER_ADDR; // Starting point address of the data buffer
ETH_TRANSMIT_STATUS_VECTOR TSV; // Transmit status vector bits
} ETH_TX_ETHERNET_DESCRIPTOR;
 
typedef struct {
unsigned : 7;
unsigned EOWN : 1; // Ethernet controller own bit (1 = ED owned by controller, do not modify)
unsigned NPV : 1; // Next ED pointer valid enable bit (1 = NEXT_ED field exists)
unsigned : 7;
unsigned BYTE_COUNT : 11; // Number of bytes to be transmited for this descriptor (1-2047)
unsigned : 3;
unsigned EOP : 1; // End of packet enable bit (1 = transmit end of packet delimiter)
unsigned SOP : 1; // Start of packet enable bit (1 = transmit start of packet delimiter)
uint32_t BUFFER_ADDR; // Starting point address of the data buffer
ETH_RECEIVE_STATUS_VECTOR RSV; // Transmit status vector bits
} ETH_RX_ETHERNET_DESCRIPTOR;
 
typedef struct {
ETH_TX_ETHERNET_DESCRIPTOR descriptor[ETH_TX_DESCRIPTOR_COUNT];
uint32_t next_ED;
} ETH_TX_DESCRIPTOR_TABLE;
 
typedef struct {
ETH_RX_ETHERNET_DESCRIPTOR descriptor[ETH_RX_DESCRIPTOR_COUNT];
uint32_t next_ED;
} ETH_RX_DESCRIPTOR_TABLE;
 
typedef struct {
ETH_TX_DESCRIPTOR_TABLE TX_ED_table;
ETH_RX_DESCRIPTOR_TABLE RX_ED_table;
uint8_t TX_ED_buffer[ETH_TX_DESCRIPTOR_COUNT][ETH_TX_ED_BUFFER_SIZE];
uint8_t RX_ED_buffer[ETH_RX_DESCRIPTOR_COUNT][ETH_RX_ED_BUFFER_SIZE];
uint8_t TX_descriptor_index;
uint8_t RX_descriptor_index;
void (*tx_callback)(void);
void (*rx_callback)(void);
} ETH_DATA;
 
void ETH_Init(ETH_DATA *data, void(*tx_callback)(void), void(*rx_callback)(void));
 
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg);
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value);
 
uint8_t ETH_Recv_Queue(void);
uint8_t ETH_Read_Packet(uint8_t *buffer, uint16_t *length);
uint8_t ETH_Write_Packet(ETH_MAC_ADDRESS dest, ETH_MAC_ADDRESS src, uint16_t length, uint8_t *buffer);
 
#endif /* ETHERNET_H */
 
/PIC Projects/Cerebot_32MX7_Ethernet/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/Cerebot_32MX7_Ethernet/defines.h
0,0 → 1,30
// PIC32MX795F512L
 
#include <xc.h>
#include <plib.h>
#include <stdint.h>
 
#ifndef DEFINES_H
#define DEFINES_H
 
// Uncomment ONE of the following:
#define CEREBOT_32MX7
// #define CEREBOT_MX7CK
 
#define LED1_TRIS TRISGbits.TRISG12
#define LED1_LAT LATGbits.LATG12
#define LED2_TRIS TRISGbits.TRISG13
#define LED2_LAT LATGbits.LATG13
#define LED3_TRIS TRISGbits.TRISG14
#define LED3_LAT LATGbits.LATG14
#define LED4_TRIS TRISGbits.TRISG15
#define LED4_LAT LATGbits.LATG15
 
#define CPU_CLOCK_HZ 80000000UL
#define PERIPHERAL_CLOCK_HZ 80000000UL
#define CPU_CT_HZ (CPU_CLOCK_HZ/2UL)
#define MS_TO_CT_TICKS (CPU_CLOCK_HZ/2000UL)
#define US_TO_CT_TICKS (CPU_CLOCK_HZ/2000000UL)
 
#endif /* DEFINES_H */
 
/PIC Projects/Cerebot_32MX7_Ethernet/main.c
0,0 → 1,112
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* ------------------------------------------------------------ */
/* PIC32 Configuration Settings */
/* ------------------------------------------------------------ */
/* Oscillator Settings */
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits
#pragma config POSCMOD = EC // Primary Oscillator Configuration
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable
/* Clock Control Settings */
#pragma config IESO = OFF // Internal/External Clock Switch Over
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin
/* USB Settings */
#pragma config UPLLEN = ON // USB PLL Enable
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection
#pragma config FUSBIDIO = OFF // USB USID Selection
/* Other Peripheral Device Settings */
#pragma config FWDTEN = OFF // Watchdog Timer Enable
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1048.576s)
#pragma config FSRSSEL = PRIORITY_7 // SRS Interrupt Priority
#pragma config FCANIO = OFF // CAN I/O Pin Select (default/alternate)
#pragma config FETHIO = ON // Ethernet I/O Pin Select (default/alternate)
#pragma config FMIIEN = OFF // Ethernet MII/RMII select (OFF=RMII)
/* Code Protection Settings */
#pragma config CP = OFF // Code Protect
#pragma config BWP = OFF // Boot Flash Write Protect
#pragma config PWP = OFF // Program Flash Write Protect
/* Debug Settings */
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (on-board debugger)
/* ------------------------------------------------------------ */
// </editor-fold>
 
#include "defines.h"
#include "ETHERNET.h"
 
void Delay_MS(uint32_t delay_ms) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow! (max delay_ms = 107374) ??
uint32_t delay = delay_ms * MS_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
void Delay_US(uint32_t delay_us) {
// Delays the CPU for the given amount of time.
// Note: Watch out for integer overflow!
uint32_t delay = delay_us * US_TO_CT_TICKS;
uint32_t startTime = ReadCoreTimer();
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
}
 
int main(void) {
/* -------------------- BEGIN INITIALIZATION --------------------- */
 
// Configure the target for maximum performance at 80 MHz.
// Note: This overrides the peripheral clock to 80Mhz regardless of config
SYSTEMConfigPerformance(CPU_CLOCK_HZ);
 
// Configure the interrupts for multiple vectors
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
 
// Set all analog I/O pins to digital
AD1PCFGSET = 0xFFFF;
 
// Enable the watchdog timer with windowed mode disabled
// WDT prescaler set to 1048576 (1048.576s) (see config bits)
// WDTCON = 0x00008000;
 
LED1_TRIS = 0;
LED2_TRIS = 0;
LED3_TRIS = 0;
LED4_TRIS = 0;
LED1_LAT = 0;
LED2_LAT = 0;
LED3_LAT = 0;
LED4_LAT = 0;
 
ETH_DATA eth_data;
ETH_Init(&eth_data, NULL, NULL);
 
uint8_t buffer[3000] = {0};
buffer[0] = 0xAA;
buffer[2017] = 0xBB;
buffer[2018] = 0xCC;
buffer[2999] = 0xDD;
 
ETH_MAC_ADDRESS dest = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
ETH_MAC_ADDRESS src = {0x00, 0x18, 0x3E, 0x00, 0xD7, 0xEB};
 
// ETH_Write_Packet(dest, src, 2018, buffer);
ETH_Write_Packet(dest, src, 2018, buffer);
ETH_Write_Packet(dest, src, 2018, buffer);
ETH_Write_Packet(dest, src, 2018, buffer);
ETH_Write_Packet(dest, src, 2018, buffer);
 
while (1) {
uint8_t queue = ETH_Recv_Queue();
if (queue != 0) {
LED1_LAT = 1;
}
}
}
 
/PIC Projects/PICX_16F1825_Controller/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Thu Dec 12 05:11:31 EST 2013
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=0d2b1469ad71adb787c711a416386331
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=1b3e17eea10b9e6765d1132465030f97
/PIC Projects/PICX_16F1825_Controller/nbproject/Makefile-default.mk
0,0 → 1,172
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c base_I2C.c base_INTERRUPTS.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_I2C.p1 ${OBJECTDIR}/base_INTERRUPTS.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/base_I2C.p1.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_I2C.p1 ${OBJECTDIR}/base_INTERRUPTS.p1
 
# Source Files
SOURCEFILES=main.c base_I2C.c base_INTERRUPTS.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1825
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_I2C.p1: base_I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_I2C.p1.d
@${RM} ${OBJECTDIR}/base_I2C.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_I2C.p1 base_I2C.c
@-${MV} ${OBJECTDIR}/base_I2C.d ${OBJECTDIR}/base_I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_I2C.p1: base_I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_I2C.p1.d
@${RM} ${OBJECTDIR}/base_I2C.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_I2C.p1 base_I2C.c
@-${MV} ${OBJECTDIR}/base_I2C.d ${OBJECTDIR}/base_I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1825_Controller/nbproject/configurations.xml
0,0 → 1,159
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>base_I2C.h</itemPath>
<itemPath>base_INTERRUPTS.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>base_I2C.c</itemPath>
<itemPath>base_INTERRUPTS.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1825</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="true"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="false"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="firmware.download.all" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="output-file-format" value="-mcof,+elf"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1825_Controller/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1825_Controller
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1825_Controller/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_17/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1825_Controller/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1825_Controller.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1825_Controller.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1825controller.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1825controller.tar
/PIC Projects/PICX_16F1825_Controller/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1825_Controller.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1825controller/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1825controller/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1825controller.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1825controller.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1825_Controller/nbproject/project.properties
--- PICX_16F1825_Controller/nbproject/project.xml (nonexistent)
+++ PICX_16F1825_Controller/nbproject/project.xml (revision 342)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_16F1825_Controller</name>
+ <creation-uuid>a37f9b7c-e474-41b7-9a5b-bc6808e97a44</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_16F1825_Controller/defines.h
0,0 → 1,80
#ifndef DEFINES_H
#define DEFINES_H
 
#include <xc.h>
#include <stdint.h>
 
// <editor-fold defaultstate="collapsed" desc="I/O Pins">
#define BTN_L_N_TRIS TRISAbits.TRISA1
#define BTN_L_N_PORT PORTAbits.RA1
#define BTN_L_N_WPU WPUAbits.WPUA1
 
#define BTN_L_S_TRIS TRISAbits.TRISA0
#define BTN_L_S_PORT PORTAbits.RA0
#define BTN_L_S_WPU WPUAbits.WPUA0
 
#define BTN_R_N_TRIS TRISCbits.TRISC2
#define BTN_R_N_PORT PORTCbits.RC2
#define BTN_R_N_WPU WPUCbits.WPUC2
 
#define BTN_R_E_TRIS TRISAbits.TRISA3
#define BTN_R_E_PORT PORTAbits.RA3
#define BTN_R_E_WPU WPUAbits.WPUA3
 
#define BTN_R_S_TRIS TRISAbits.TRISA5
#define BTN_R_S_PORT PORTAbits.RA5
#define BTN_R_S_WPU WPUAbits.WPUA5
 
#define BTN_R_W_TRIS TRISAbits.TRISA2
#define BTN_R_W_PORT PORTAbits.RA2
#define BTN_R_W_WPU WPUAbits.WPUA2
 
#define LED_4_TRIS TRISCbits.TRISC3
#define LED_4_LAT LATCbits.LATC3
 
#define LED_3_TRIS TRISCbits.TRISC4
#define LED_3_LAT LATCbits.LATC4
 
#define LED_2_TRIS TRISCbits.TRISC5
#define LED_2_LAT LATCbits.LATC5
 
#define LED_1_TRIS TRISAbits.TRISA4
#define LED_1_LAT LATAbits.LATA4
 
#define I2C_CLK_TRIS TRISCbits.TRISC0
#define I2C_DAT_TRIS TRISCbits.TRISC1
// </editor-fold>
 
#define _XTAL_FREQ 32000000
 
#define CMD_QUERY_BTN 0x0A
#define CMD_SET_LEDS 0x0B
 
typedef union {
struct {
unsigned BTN_L_N :1;
unsigned BTN_L_S :1;
unsigned BTN_R_N :1;
unsigned BTN_R_E :1;
unsigned BTN_R_S :1;
unsigned BTN_R_W :1;
unsigned :2;
};
uint8_t value;
} BTN_STATUS;
 
typedef union {
struct {
unsigned LED_1 :1;
unsigned LED_2 :1;
unsigned LED_3 :1;
unsigned LED_4 :1;
};
uint8_t value;
} LED_STATUS;
 
void Pins_Read(BTN_STATUS *btns);
void Leds_Write(LED_STATUS *leds);
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_16F1825_Controller/base_I2C.c
0,0 → 1,532
#include "defines.h"
#include "base_I2C.h"
 
static I2C_DATA *i2c_data_p;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C_Init(I2C_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0x8; // I2C Master Mode
if (!speed) {
SSPADD = 0x13; // Operate at 400KHz (32MHz)
} else {
SSPADD = 0x4F; // Operate at 100KHz (32MHz)
}
SSPSTATbits.SMP = 1; // Disable Slew Rate Control
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
uint8_t i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPADD = addr << 1; // Set the slave address
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0xE; // Enable Slave 7-bit w/ start/stop interrupts
SSPSTATbits.SMP = 1; // Slew Off
SSPCON2bits.SEN = 1; // Enable clock-stretching
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
void I2C_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSPBUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSPBUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSPCON2bits.ACKSTAT) {
SSPCON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C_Interrupt_Slave() {
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSPCON1bits.SSPOV == 1) {
SSPCON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSPSTATbits.BF == 1) {
received_data = SSPBUF;
// DBG_PRINT_I2C("I2C: data read from buffer: %x\r\n", SSPBUF);
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// Ignore anything except a start
if (SSPSTATbits.S == 1) {
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->operating_state = I2C_STARTED;
}
break;
}
case I2C_STARTED:
{
// In this case, we expect either an address or a stop bit
if (SSPSTATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_nA == 0) {
// Address received
if (SSPSTATbits.R_nW == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSPBUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSPBUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSPSTATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSPSTATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_nA == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSPSTATbits.R_nW == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSPCON1bits.CKP == 0) {
SSPCON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
uint8_t I2C_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
uint8_t I2C_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
uint8_t I2C_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
uint8_t I2C_Process_Receive(uint8_t c) {
uint8_t ret = 0;
BTN_STATUS btns;
CLRWDT();
btns.value = 0;
switch (c) {
case CMD_QUERY_BTN:
Pins_Read(&btns);
i2c_data_p->buffer_out[0] = btns.value;
i2c_data_p->buffer_out_len = 1;
ret = 1;
break;
}
return ret;
}
/PIC Projects/PICX_16F1825_Controller/funclist
0,0 → 1,17
_I2C_Get_Status: CODE, 1174 0 54
_I2C_Interrupt_Master: CODE, 19 0 591
_I2C_Read_Buffer: CODE, 1046 0 65
_I2C_Interrupt_Slave: CODE, 610 0 358
_main: CODE, 1111 0 63
_Interrupt_Enable: CODE, 1449 0 3
_I2C_Configure_Slave: CODE, 1396 0 28
_InterruptHandler: CODE, 4 0 13
_I2C_Process_Receive: CODE, 1363 0 33
_I2C_Interrupt_Handler: CODE, 1424 0 22
_Interrupt_Init: CODE, 1452 0 3
__initialization: CODE, 1446 0 0
_I2C_Init: CODE, 968 0 78
_Pins_Read: CODE, 1319 0 44
_Pins_Init: CODE, 1274 0 45
_Leds_Write: CODE, 1228 0 46
Total: 1446
/PIC Projects/PICX_16F1825_Controller/main.c
0,0 → 1,125
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// PIC16F1825 Configuration Bit Settings
 
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
#include "defines.h"
#include "base_INTERRUPTS.h"
#include "base_I2C.h"
 
void Pins_Init(void) {
 
 
// Set all pins to digital I/O
ANSELA = 0x0;
ANSELC = 0x0;
 
// Enable weak pull-up if WPU bit is set
OPTION_REGbits.nWPUEN = 0;
 
// Set buttons as inputs and enable weak pull-ups
BTN_L_N_TRIS = 1;
BTN_L_N_WPU = 1;
BTN_L_S_TRIS = 1;
BTN_L_S_WPU = 1;
 
BTN_R_N_TRIS = 1;
BTN_R_N_WPU = 1;
BTN_R_E_TRIS = 1;
BTN_R_E_WPU = 1;
BTN_R_S_TRIS = 1;
BTN_R_S_WPU = 1;
BTN_R_W_TRIS = 1;
BTN_R_W_WPU = 1;
 
// Set leds as outputs and initialize to off
LED_1_TRIS = 0;
LED_1_LAT = 0;
LED_2_TRIS = 0;
LED_2_LAT = 0;
LED_3_TRIS = 0;
LED_3_LAT = 0;
LED_4_TRIS = 0;
LED_4_LAT = 0;
}
 
// Function to read button status into a data structure
void Pins_Read(BTN_STATUS *btns) {
btns->BTN_L_N = BTN_L_N_PORT;
btns->BTN_L_S = BTN_L_S_PORT;
 
btns->BTN_R_N = BTN_R_N_PORT;
btns->BTN_R_E = BTN_R_E_PORT;
btns->BTN_R_S = BTN_R_S_PORT;
btns->BTN_R_W = BTN_R_W_PORT;
}
 
// Function to write led values from the data structure
void Leds_Write(LED_STATUS *leds) {
LED_1_LAT = leds->LED_1;
LED_2_LAT = leds->LED_2;
LED_3_LAT = leds->LED_3;
LED_4_LAT = leds->LED_4;
}
 
// TODO: Set watchdog timer to reset device if no I2C messages are received every x seconds
// TODO: Use a timer to manually PWM the LEDs
 
int main(void) {
uint8_t buffer[32];
uint8_t result, length;
 
// Set internal oscillator speed to 32MHz
OSCCONbits.SPLLEN = 1; // 4x PLL enable (overwritten by config bits)
OSCCONbits.IRCF = 0xE; // Base frequency @ 8MHz
OSCCONbits.SCS = 0b00; // System clock determined by config bits
 
// Set watchdog timer to reset device every 1s
// CLRWDT is issued upon receiving data over I2C
WDTCON = 0x0A;
 
// Initialize I/O
Pins_Init();
 
// Initialize I2C in slave mode
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
I2C_Configure_Slave(0x25);
 
// Initialize interrupts
Interrupt_Init();
Interrupt_Enable();
 
// Check for received data over I2C
while (1) {
do {
result = I2C_Get_Status();
} while (!result);
CLRWDT();
length = I2C_Read_Buffer(buffer);
if (length == 2 && buffer[0] == CMD_SET_LEDS) {
LED_STATUS leds;
leds.value = buffer[1];
Leds_Write(&leds);
}
}
}
 
/PIC Projects/PICX_16F1825_Controller/base_I2C.h
0,0 → 1,81
#ifndef I2C_H
#define I2C_H
 
#define MAXI2CBUF 32
 
// I2C Operating Speed
#define I2C_400KHZ 0x0
#define I2C_100KHZ 0x1
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
uint8_t buffer_in[MAXI2CBUF];
uint8_t buffer_in_len;
uint8_t buffer_in_len_tmp;
uint8_t buffer_in_read_ind;
uint8_t buffer_in_write_ind;
uint8_t buffer_out[MAXI2CBUF];
uint8_t buffer_out_len;
uint8_t buffer_out_ind;
 
uint8_t operating_mode;
uint8_t operating_state;
uint8_t return_status;
 
uint8_t master_dest_addr;
uint8_t master_status;
uint8_t slave_in_last_byte;
uint8_t slave_sending_data;
} I2C_DATA;
 
void I2C_Init(I2C_DATA *data);
void I2C_Interrupt_Handler(void);
void I2C_Interrupt_Slave(void);
void I2C_Interrupt_Master(void);
void I2C_Configure_Slave(uint8_t address);
void I2C_Configure_Master(uint8_t speed);
void I2C_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
void I2C_Master_Recv(uint8_t address, uint8_t length);
void I2C_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
uint8_t I2C_Get_Status(void);
uint8_t I2C_Buffer_Len(void);
uint8_t I2C_Read_Buffer(uint8_t *buffer);
uint8_t I2C_Process_Receive(uint8_t);
 
#endif
/PIC Projects/PICX_16F1825_Controller/base_INTERRUPTS.c
0,0 → 1,79
#include "defines.h"
#include "base_INTERRUPTS.h"
#include "base_I2C.h"
 
void Interrupt_Init() {
// Enable MSSP1 interrupt
PIE1bits.SSP1IE = 1;
}
 
void Interrupt_Enable() {
// Enable global and peripheral interrupts
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
 
void Interrupt_Disable() {
INTCONbits.PEIE = 0;
INTCONbits.GIE = 0;
}
 
void interrupt InterruptHandler(void) {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// // Check to see if we have an SPI2 interrupt
// if (PIR3bits.SSP2IF) {
// // Call the handler
// SPI2_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR3bits.SSP2IF = 0;
//
// return;
// }
 
// Check to see if we have an I2C interrupt
if (PIR1bits.SSP1IF) {
 
// Call the handler
I2C_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSP1IF = 0;
 
return;
}
 
// // Check to see if we have an interrupt on USART1 RX
// if (PIR1bits.RC1IF) {
// // Call the interrupt handler
// UART1_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.RC1IF = 0;
//
// return;
// }
 
// // Check to see if we have an interrupt on USART1 TX
// if (PIR1bits.TX1IF) {
// // Call the interrupt handler
// UART1_Send_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.TX1IF = 0;
//
// return;
// }
 
// // Check to see if we have an interrupt on USART2 RX
// if (PIR3bits.RC2IF) {
// DBG_PRINT_INT("INT: UART2 RX\r\n");
// // Call the interrupt handler
// uart_2_recv_interrupt_handler();
//
// // Clear the interrupt flag
// PIR3bits.RC2IF = 0;
// }
}
/PIC Projects/PICX_16F1825_Controller/Makefile
0,0 → 1,113
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
# WARNING: the IDE does not call this target since it takes a long time to
# simply run make. Instead, the IDE removes the configuration directories
# under build and dist directly without calling make.
# This target is left here so people can do a clean when running a clean
# outside the IDE.
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_16F1825_Controller/base_INTERRUPTS.h
0,0 → 1,15
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandler(void);
 
#endif
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Makefile-default.mk
0,0 → 1,268
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=elf
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=elf
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Source Files Quoted if spaced
SOURCEFILES_QUOTED_IF_SPACED=main.c TIMER.c INTERRUPT.c UART.c I2C.c L3G.c LSM303.c RN-42.c MAX17040.c
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/TIMER.p1 ${OBJECTDIR}/INTERRUPT.p1 ${OBJECTDIR}/UART.p1 ${OBJECTDIR}/I2C.p1 ${OBJECTDIR}/L3G.p1 ${OBJECTDIR}/LSM303.p1 ${OBJECTDIR}/RN-42.p1 ${OBJECTDIR}/MAX17040.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/TIMER.p1.d ${OBJECTDIR}/INTERRUPT.p1.d ${OBJECTDIR}/UART.p1.d ${OBJECTDIR}/I2C.p1.d ${OBJECTDIR}/L3G.p1.d ${OBJECTDIR}/LSM303.p1.d ${OBJECTDIR}/RN-42.p1.d ${OBJECTDIR}/MAX17040.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/TIMER.p1 ${OBJECTDIR}/INTERRUPT.p1 ${OBJECTDIR}/UART.p1 ${OBJECTDIR}/I2C.p1 ${OBJECTDIR}/L3G.p1 ${OBJECTDIR}/LSM303.p1 ${OBJECTDIR}/RN-42.p1 ${OBJECTDIR}/MAX17040.p1
 
# Source Files
SOURCEFILES=main.c TIMER.c INTERRUPT.c UART.c I2C.c L3G.c LSM303.c RN-42.c MAX17040.c
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=16F1829
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPT.p1: INTERRUPT.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPT.p1.d
@${RM} ${OBJECTDIR}/INTERRUPT.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/INTERRUPT.p1 INTERRUPT.c
@-${MV} ${OBJECTDIR}/INTERRUPT.d ${OBJECTDIR}/INTERRUPT.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPT.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C.p1: I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C.p1.d
@${RM} ${OBJECTDIR}/I2C.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/I2C.p1 I2C.c
@-${MV} ${OBJECTDIR}/I2C.d ${OBJECTDIR}/I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/L3G.p1: L3G.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/L3G.p1.d
@${RM} ${OBJECTDIR}/L3G.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/L3G.p1 L3G.c
@-${MV} ${OBJECTDIR}/L3G.d ${OBJECTDIR}/L3G.p1.d
@${FIXDEPS} ${OBJECTDIR}/L3G.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/LSM303.p1: LSM303.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/LSM303.p1.d
@${RM} ${OBJECTDIR}/LSM303.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/LSM303.p1 LSM303.c
@-${MV} ${OBJECTDIR}/LSM303.d ${OBJECTDIR}/LSM303.p1.d
@${FIXDEPS} ${OBJECTDIR}/LSM303.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/RN-42.p1: RN-42.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/RN-42.p1.d
@${RM} ${OBJECTDIR}/RN-42.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/RN-42.p1 RN-42.c
@-${MV} ${OBJECTDIR}/RN-42.d ${OBJECTDIR}/RN-42.p1.d
@${FIXDEPS} ${OBJECTDIR}/RN-42.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/MAX17040.p1: MAX17040.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/MAX17040.p1.d
@${RM} ${OBJECTDIR}/MAX17040.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/MAX17040.p1 MAX17040.c
@-${MV} ${OBJECTDIR}/MAX17040.d ${OBJECTDIR}/MAX17040.p1.d
@${FIXDEPS} ${OBJECTDIR}/MAX17040.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
@${RM} ${OBJECTDIR}/main.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/TIMER.p1: TIMER.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/TIMER.p1.d
@${RM} ${OBJECTDIR}/TIMER.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/TIMER.p1 TIMER.c
@-${MV} ${OBJECTDIR}/TIMER.d ${OBJECTDIR}/TIMER.p1.d
@${FIXDEPS} ${OBJECTDIR}/TIMER.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/INTERRUPT.p1: INTERRUPT.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/INTERRUPT.p1.d
@${RM} ${OBJECTDIR}/INTERRUPT.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/INTERRUPT.p1 INTERRUPT.c
@-${MV} ${OBJECTDIR}/INTERRUPT.d ${OBJECTDIR}/INTERRUPT.p1.d
@${FIXDEPS} ${OBJECTDIR}/INTERRUPT.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/UART.p1: UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/UART.p1.d
@${RM} ${OBJECTDIR}/UART.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/UART.p1 UART.c
@-${MV} ${OBJECTDIR}/UART.d ${OBJECTDIR}/UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/I2C.p1: I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/I2C.p1.d
@${RM} ${OBJECTDIR}/I2C.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/I2C.p1 I2C.c
@-${MV} ${OBJECTDIR}/I2C.d ${OBJECTDIR}/I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/L3G.p1: L3G.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/L3G.p1.d
@${RM} ${OBJECTDIR}/L3G.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/L3G.p1 L3G.c
@-${MV} ${OBJECTDIR}/L3G.d ${OBJECTDIR}/L3G.p1.d
@${FIXDEPS} ${OBJECTDIR}/L3G.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/LSM303.p1: LSM303.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/LSM303.p1.d
@${RM} ${OBJECTDIR}/LSM303.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/LSM303.p1 LSM303.c
@-${MV} ${OBJECTDIR}/LSM303.d ${OBJECTDIR}/LSM303.p1.d
@${FIXDEPS} ${OBJECTDIR}/LSM303.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/RN-42.p1: RN-42.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/RN-42.p1.d
@${RM} ${OBJECTDIR}/RN-42.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/RN-42.p1 RN-42.c
@-${MV} ${OBJECTDIR}/RN-42.d ${OBJECTDIR}/RN-42.p1.d
@${FIXDEPS} ${OBJECTDIR}/RN-42.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/MAX17040.p1: MAX17040.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/MAX17040.p1.d
@${RM} ${OBJECTDIR}/MAX17040.p1
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/MAX17040.p1 MAX17040.c
@-${MV} ${OBJECTDIR}/MAX17040.d ${OBJECTDIR}/MAX17040.p1.d
@${FIXDEPS} ${OBJECTDIR}/MAX17040.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.map --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Sat Sep 28 16:30:53 EDT 2013
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.20\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=0d2b1469ad71adb787c711a416386331
default.languagetoolchain.version=1.20
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=1b3e17eea10b9e6765d1132465030f97
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/configurations.xml
0,0 → 1,170
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>main.h</itemPath>
<itemPath>TIMER.h</itemPath>
<itemPath>INTERRUPT.h</itemPath>
<itemPath>UART.h</itemPath>
<itemPath>I2C.h</itemPath>
<itemPath>L3G.h</itemPath>
<itemPath>LSM303.h</itemPath>
<itemPath>RN-42.h</itemPath>
<itemPath>MAX17040.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>TIMER.c</itemPath>
<itemPath>INTERRUPT.c</itemPath>
<itemPath>UART.c</itemPath>
<itemPath>I2C.c</itemPath>
<itemPath>L3G.c</itemPath>
<itemPath>LSM303.c</itemPath>
<itemPath>RN-42.c</itemPath>
<itemPath>MAX17040.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC16F1829</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.20</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="asmlist" value="true"/>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="false"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-command-line" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="additional-options-use-response-files" value="false"/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VPPFirst"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
<property key="output-file-format" value="-mcof,+elf"/>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.7.0_17/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.20\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/project.xml
0,0 → 1,15
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://www.netbeans.org/ns/project/1">
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
<name>PICX_16F1829_BLE_IMU</name>
<creation-uuid>ff750289-f357-4403-b705-1a1fce70e6e7</creation-uuid>
<make-project-type>0</make-project-type>
<c-extensions>c</c-extensions>
<cpp-extensions/>
<header-extensions>h</header-extensions>
<sourceEncoding>ISO-8859-1</sourceEncoding>
<make-dep-projects/>
</data>
</configuration>
</project>
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_16F1829_BLE_IMU
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_16F1829_BLE_IMU.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_16F1829_BLE_IMU.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx16f1829bleimu.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx16f1829bleimu.tar
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_16F1829_BLE_IMU.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx16f1829bleimu/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx16f1829bleimu/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx16f1829bleimu.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx16f1829bleimu.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_16F1829_BLE_IMU/nbproject/project.properties
--- PICX_16F1829_BLE_IMU/Demo.py (nonexistent)
+++ PICX_16F1829_BLE_IMU/Demo.py (revision 342)
@@ -0,0 +1,59 @@
+import serial
+
+def twos_comp(val, bits):
+ '''Convert given value from two's complement to integer'''
+ if ((val & (1 << (bits-1))) != 0):
+ val = val - (1 << bits)
+ return val
+
+if __name__ == '__main__':
+ print("Attempting to connect to serial port...")
+ # Connect to specified serial port
+ ser = serial.Serial()
+ ser.baudrate = 115200
+ ser.port = "COM3"
+ ser.timeout = 3 # Three second timeout
+ try:
+ ser.open()
+ print("Connected to serial port.")
+ # Loop reading in data from the sensor
+ while(1):
+ s = ser.read(21)
+ # Ensure that the data properly ends in a newline
+ if s[20] == ord('\n'):
+ # Read in accelerometer data and convert from two's compliment
+ A_X = ((s[1] << 8) | s[0])
+ A_Y = ((s[3] << 8) | s[2])
+ A_Z = ((s[5] << 8) | s[4])
+ A_X_N = twos_comp(A_X, 16) >> 4
+ A_Y_N = twos_comp(A_Y, 16) >> 4
+ A_Z_N = twos_comp(A_Z, 16) >> 4
+
+ # Read in gyroscope data and convert from two's compliment
+ G_Y = (s[7] << 8) | s[6]
+ G_X = (s[9] << 8) | s[8]
+ G_Z = (s[11] << 8) | s[10]
+ G_X_N = twos_comp(G_X, 16)
+ G_Y_N = twos_comp(G_Y, 16)
+ G_Z_N = twos_comp(G_Z, 16)
+
+ # Read in magnetometer data and convert from two's compliment
+ M_X = ((s[13] << 8) | s[12])
+ M_Y = ((s[15] << 8) | s[14])
+ M_Z = ((s[17] << 8) | s[16])
+ M_X_N = twos_comp(M_X, 16)
+ M_Y_N = twos_comp(M_Y, 16)
+ M_Z_N = twos_comp(M_Z, 16)
+
+ # Read in battery status
+ B_H = s[18]
+ B_L = s[19]
+
+ # Print out the processed data
+ print("A: %-6i %-6i %-6i G: %-6i %-6i %-6i M: %-6i %-6i %-6i B: %u.%u" % \
+ (A_X_N, A_Y_N, A_Z_N, G_X_N, G_Y_N, G_Z_N, M_X_N, M_Y_N, M_Z_N, B_H, B_L))
+ else:
+ break
+ except:
+ pass
+ ser.close()
\ No newline at end of file
/PIC Projects/PICX_16F1829_BLE_IMU/MAX17040.c
0,0 → 1,29
#include <xc.h>
#include "main.h"
#include "MAX17040.h"
#include "I2C.h"
 
void MAX17040_Init(void) {
char c[] = {MAX17040_MODE_H, 0x40, 0x00};
I2C_Master_Send(ADDRESS_LIPO, &c, 3);
while (!I2C_Get_Status());
 
}
 
void MAX17040_Read_Batt(char *h, char *l) {
char result, length, buffer[10] = {0};
 
char c = MAX17040_SOC_H;
 
I2C_Master_Restart(ADDRESS_LIPO, c, 2);
do {
result = I2C_Get_Status();
} while (!result);
 
// Read received data
length = I2C_Read_Buffer(buffer);
 
// Data is received in low-high byte order
*h = buffer[0];
*l = buffer[1];
}
/PIC Projects/PICX_16F1829_BLE_IMU/MAX17040.h
0,0 → 1,20
#ifndef MAX17040_H
#define MAX17040_H
 
#define MAX17040_VCELL_H 0x02
#define MAX17040_VCELL_L 0x03
#define MAX17040_SOC_H 0x04
#define MAX17040_SOC_L 0x05
#define MAX17040_MODE_H 0x06
#define MAX17040_MODE_L 0x07
#define MAX17040_VERSION_H 0x08
#define MAX17040_VERSION_L 0x09
#define MAX17040_RCOMP_H 0x0C
#define MAX17040_RCOMP_L 0x0D
#define MAX17040_COMMAND 0xFE
 
void MAX17040_Init(void);
void MAX17040_Read_Batt(char *h, char *l);
 
#endif /* MAX17040_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/RN-42.c
0,0 → 1,80
#include <xc.h>
#include "main.h"
#include "RN-42.h"
#include "UART.h"
#include <string.h>
 
extern char LED_G_ON;
extern char LED_R_ON;
 
void RN42_Init(void) {
if (RN42_Enter_CMD_Mode()) {
// Set authentication to open mode
char sa[] = "SA,0\r";
RN42_Send_CMD(sa, 5);
// Optimize for low latency rather than throughput
char sq[] = "SQ,16\r";
RN42_Send_CMD(sq, 6);
// // Allow continuous configuration
// char st[] = "ST,255\r";
// RN42_Send_CMD(st, 7);
// // Set page scan window to maximum
// char sj[] = "SJ,800\r";
// RN42_Send_CMD(sj, 7);
// // Enable connection status strings
// char so[] = "SO,!\r";
// RN42_Send_CMD(so, 5);
// Reboot with the new settings
char r[] = "R,1\r";
RN42_Send_CMD(r, 4);
}
}
 
char RN42_Enter_CMD_Mode(void) {
char ret, buffer[10];
char cmd_mode[] = "$$$";
UART_Write(cmd_mode, 3);
__delay_ms(30);
ret = UART_Read(buffer);
if (ret == 5 && !strncmp(buffer, "CMD\r\n", 5))
return 1;
else
return 0;
}
 
void RN42_Exit_CMD_Mode(void) {
char ret, buffer[10];
char cmd_ret[] = "---\r";
UART_Write(cmd_ret, 4);
__delay_ms(30);
ret = UART_Read(buffer); // Exiting should return "END"
}
 
char RN42_Send_CMD(char *cmd, char length) {
char ret, buffer[10];
UART_Write(cmd, length);
__delay_ms(30);
ret = UART_Read(buffer);
if (ret == 5 && !strncmp(buffer, "AOK\r\n", 5))
return 1;
else
return 0;
}
 
char RN42_Connected_Status(void) {
if (RN42_Enter_CMD_Mode()) {
char ret, buffer[10], cmd[] = "GK\r";
UART_Write(cmd, 3);
__delay_ms(30);
ret = UART_Read(buffer);
if (ret == 7 && !strncmp(buffer, "1,0,0\r\n", 7)) {
RN42_Exit_CMD_Mode();
return 1;
} else {
RN42_Exit_CMD_Mode();
return 0;
}
} else {
return 0;
}
}
/PIC Projects/PICX_16F1829_BLE_IMU/RN-42.h
0,0 → 1,12
#ifndef RN_42_H
#define RN_42_H
 
void RN42_Init(void);
char RN42_Enter_CMD_Mode(void);
void RN42_Exit_CMD_Mode(void);
char RN42_Send_CMD(char *cmd, char length);
char RN42_Connected_Status(void);
 
 
#endif /* RN_42_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/UART.h
0,0 → 1,25
#ifndef UART_H
#define UART_H
 
#define UART_BUFFER_SIZE 30
 
typedef struct {
char buffer_in[UART_BUFFER_SIZE];
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_in_len;
 
char buffer_out[UART_BUFFER_SIZE];
char buffer_out_ind;
char buffer_out_len;
} UART_DATA;
 
void UART_Init(UART_DATA *data);
void UART_Write(char *data, char length);
char UART_Read(char *buffer);
 
void UART_TX_Interrupt_Handler(void);
void UART_RX_Interrupt_Handler(void);
 
#endif /* UART_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/funclist
0,0 → 1,44
_TIMER_2_Init: CODE, 2661 0 16
_I2C_Get_Status: CODE, 3217 0 62
_I2C_Interrupt_Master: CODE, 264 0 706
_TIMER_2_Start: CODE, 2623 0 3
__stringtab: STRING, 235 0 1
_I2C_Read_Buffer: CODE, 3546 0 72
__i1fptable: CODE, 257 0 7
__stringdata: STRING, 236 0 20
_INTERRUPT_Init: CODE, 2620 0 3
_UART_Read: CODE, 4013 0 83
_MAX17040_Init: CODE, 2728 0 31
_I2C_Interrupt_Slave: CODE, 970 0 424
_INTERRUPT_Handler: CODE, 4 0 46
_I2C_Configure_Master: CODE, 2759 0 34
_I2C_Master_Send: CODE, 3930 0 83
_UART_Init: CODE, 3040 0 57
_RN42_Init: CODE, 3618 0 75
_main: CODE, 1611 0 210
_Error: CODE, 2983 0 57
_TIMER_1_Init: CODE, 2677 0 25
_Timer_2_Callback: CODE, 3343 0 66
_I2C_Process_Send: CODE, 3155 0 62
_I2C_Interrupt_Handler: CODE, 2702 0 26
_RN42_Enter_CMD_Mode: CODE, 3476 0 70
_UART_TX_Interrupt_Handler: CODE, 3097 0 58
__initialization: CODE, 2928 0 52
_TIMER_2_Interrupt_Handler: CODE, 2626 0 5
_I2C_Master_Restart: CODE, 3693 0 79
_LSM303_Init: CODE, 1821 0 104
_LSM303_Read_Accl: CODE, 52 0 93
_I2C_Init: CODE, 1925 0 95
_RN42_Send_CMD: CODE, 2829 0 47
_LSM303_Read_Magn: CODE, 3851 0 79
_Timer_1_Callback: CODE, 3 0 1
_MAX17040_Read_Batt: CODE, 3279 0 64
_strncmp: CODE, 3409 0 67
_UART_RX_Interrupt_Handler: CODE, 145 0 90
_Startup_Check: CODE, 1394 0 217
_L3G_Init: CODE, 2020 0 26
_UART_Write: CODE, 2876 0 52
_TIMER_1_Interrupt_Handler: CODE, 2651 0 10
_L3G_Read_Gyro: CODE, 3772 0 79
_INTERRUPT_Enable: CODE, 2046 0 2
Total: 3459
/PIC Projects/PICX_16F1829_BLE_IMU/main.c
0,0 → 1,248
#include <xc.h>
#include <string.h>
#include "main.h"
#include "TIMER.h"
#include "INTERRUPT.h"
#include "UART.h"
#include "I2C.h"
#include "L3G.h"
#include "LSM303.h"
#include "RN-42.h"
#include "MAX17040.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
 
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// </editor-fold>
 
UART_DATA uart_data;
I2C_DATA i2c_data;
 
char LED_R_ON = 0;
char LED_G_ON = 0;
char LED_B_ON = 0;
char timer_2_pwm = 0;
char connected = 0;
 
void Error(char ID) {
while(1) {
for (char i = 0; i < ID; i++) {
LED_R_ON = 1;
__delay_ms(120);
LED_R_ON = 0;
__delay_ms(150);
}
__delay_ms(1000);
}
}
 
void Startup_Check(void) {
char buffer[20];
char result, length;
 
// BLE_RESET_LAT = 0;
// __delay_ms(3000);
// BLE_RESET_LAT = 1;
// __delay_ms(200);
 
// // Check BLE Module
// length = UART_Read(buffer);
// if (memcmp(buffer, "\r\nBR-LE4.0-S2\r\n", 15)) {
// Error(1);
// }
// UART_Write("AT\r", 3);
// __delay_ms(10);
// length = UART_Read(buffer);
// if (memcmp(buffer, "\r\nOK\r\n", 6)) {
// Error(1);
// }
 
// Check Battery Gauge
I2C_Master_Restart(ADDRESS_LIPO, 0x0C, 2);
do {
result = I2C_Get_Status();
} while (!result);
if ((result != I2C_SEND_OK) && (result != I2C_RECV_OK)) {
Error(2);
}
length = I2C_Read_Buffer(buffer);
if ((buffer[0] != 0x97) || (buffer[1] != 0x00) || (length != 2)) {
Error(2);
}
 
// Check Gyroscope
I2C_Master_Restart(ADDRESS_GYRO, 0x0F, 1);
do {
result = I2C_Get_Status();
} while (!result);
if ((result != I2C_SEND_OK) && (result != I2C_RECV_OK)) {
Error(3);
}
length = I2C_Read_Buffer(buffer);
if ((buffer[0] != 0xD4) || (length != 1)) {
Error(3);
}
 
// Check Accelerometer
I2C_Master_Restart(ADDRESS_ACCL, 0x20, 1);
do {
result = I2C_Get_Status();
} while (!result);
if ((result != I2C_SEND_OK) && (result != I2C_RECV_OK)) {
Error(4);
}
length = I2C_Read_Buffer(buffer);
if ((buffer[0] != 0x07) || (length != 1)) {
Error(4);
}
 
// Check Magnometer
I2C_Master_Restart(ADDRESS_MAGN, 0x0A, 1);
do {
result = I2C_Get_Status();
} while (!result);
if ((result != I2C_SEND_OK) && (result != I2C_RECV_OK)) {
Error(4);
}
length = I2C_Read_Buffer(buffer);
if ((buffer[0] != 0x48) || (length != 1)) {
Error(4);
}
}
 
void Timer_2_Callback(void) {
// Here we manually 'PWM' the LEDs
// Note: this is terribly inefficient but we need to do this
// otherwise we will blow out the blue LED (max 10mA)
if (timer_2_pwm == 0) {
LED_R_LAT = (LED_R_ON) ? 0 : 1;
LED_G_LAT = (LED_G_ON) ? 0 : 1;
LED_B_LAT = (LED_B_ON) ? 0 : 1;
}
if (timer_2_pwm == LED_R_MAX_BRIGHTNESS) {
LED_R_LAT = 1;
}
if (timer_2_pwm == LED_G_MAX_BRIGHTNESS) {
LED_G_LAT = 1;
}
if (timer_2_pwm == LED_B_MAX_BRIGHTNESS) {
LED_B_LAT = 1;
}
timer_2_pwm++;
}
 
void Timer_1_Callback(void) {
// int A_X,A_Y,A_Z;
// int G_X,G_Y,G_Z;
// int M_X,M_Y,M_Z;
 
// LSM303_Read_Accl(&A_X, &A_Y, &A_Z);
// L3G_Read_Gyro(&G_X, &G_Y, &G_Z);
// LSM303_Read_Magn(&output[6], &output[7], &output[8]);
 
// UART_Write("Hello", 5);
}
 
int main() {
 
OSCCON = 0xF0; // Software PLL enabled, 32MHz
ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
 
LED_R_TRIS = 0;
LED_R_LAT = 1;
LED_G_TRIS = 0;
LED_G_LAT = 1;
LED_B_TRIS = 0;
LED_B_LAT = 1;
 
BLE_RESET_TRIS = 0;
BLE_RESET_LAT = 1;
 
UART_CTS_TRIS = 1;
UART_RTS_TRIS = 0;
UART_RTS_LAT = 0;
 
// Initialize all peripherals
TIMER_1_Init(&Timer_1_Callback);
TIMER_2_Init(&Timer_2_Callback);
UART_Init(&uart_data);
I2C_Init(&i2c_data);
INTERRUPT_Init();
 
I2C_Configure_Master(I2C_400KHZ);
INTERRUPT_Enable();
// TIMER_1_Start();
TIMER_2_Start();
 
// A small delay is needed for the sensors to start up
__delay_ms(1000);
 
// Run a check to ensure that all sensors are properly connected
Startup_Check();
 
// Initialze the sensors
L3G_Init();
LSM303_Init();
RN42_Init();
MAX17040_Init();
 
char output[21] = {0};
output[20] = '\n';
// char len, buffer[30];
 
LED_B_ON = 1;
while(1) {
__delay_ms(10);
 
// len = UART_Read(buffer);
// if (len != 0) {
// if (!strncmp(buffer, "!CONNECT", 8)) {
// connected = 1;
// LED_G_ON = 1;
// }
// if (!strncmp(buffer, "!DISCONNECT", 11)) {
// connected = 0;
// LED_G_ON = 0;
// }
// }
 
// if (connected) {
LSM303_Read_Accl(&output[0], &output[1], &output[2], &output[3], &output[4], &output[5]);
L3G_Read_Gyro(&output[6], &output[7], &output[8], &output[9], &output[10], &output[11]);
LSM303_Read_Magn(&output[12], &output[13], &output[14], &output[15], &output[16], &output[17]);
MAX17040_Read_Batt(&output[18], &output[19]);
 
UART_Write((char *)&output[0], 21);
// }
 
// LED_B_ON = 0;
// LED_R_ON = 1;
// __delay_ms(250);
// LED_R_ON = 0;
// LED_G_ON = 1;
// __delay_ms(250);
// LED_G_ON = 0;
// LED_B_ON = 1;
// __delay_ms(250);
}
}
/PIC Projects/PICX_16F1829_BLE_IMU/I2C.c
0,0 → 1,555
#include <xc.h>
#include "main.h"
#include "I2C.h"
 
static I2C_DATA *data_ptr;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C_Init(I2C_DATA *data) {
data_ptr = data;
 
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
data_ptr->buffer_in_len = 0;
data_ptr->buffer_in_len_tmp = 0;
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
 
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
 
data_ptr->operating_mode = 0;
data_ptr->operating_state = I2C_IDLE;
data_ptr->return_status = 0;
 
data_ptr->slave_in_last_byte = 0;
data_ptr->slave_sending_data = 0;
 
data_ptr->master_dest_addr = 0;
data_ptr->master_status = I2C_MASTER_IDLE;
 
// Enable I2C interrupt
PIE1bits.SSP1IE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C_Configure_Master(char speed) {
data_ptr->operating_mode = I2C_MODE_MASTER;
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
if (speed) {
SSP1ADD = 0x4F; // Operate at 100KHz (32MHz)
} else {
SSP1ADD = 0x13; // Operate at 400KHz (32MHz)
}
SSP1STATbits.SMP = 1; // Disable Slew Rate Control
SSP1CON3bits.PCIE = 1; // Stop condition interrupt enable
SSP1CON3bits.SCIE = 1; // Start condition interrupt enable
SSP1CON1bits.SSPEN = 1; // Enable MSSP Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C_Master_Send(char address, char *msg, char length) {
char i;
if (length == 0)
return;
 
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
data_ptr->buffer_in[i] = msg[i];
}
data_ptr->buffer_in_len = length;
data_ptr->master_dest_addr = address;
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
data_ptr->operating_state = I2C_SEND_ADDR;
data_ptr->master_status = I2C_MASTER_SEND;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C_Master_Recv(char address, char length) {
if (length == 0)
return;
 
// Save length and address to get data from
data_ptr->buffer_in_len = length;
data_ptr->master_dest_addr = address;
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
data_ptr->operating_state = I2C_SEND_ADDR;
data_ptr->master_status = I2C_MASTER_RECV;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C_Master_Restart(char address, char msg, char length) {
char c;
if (length == 0) {
c = msg;
I2C_Master_Send(address, &c, 1);
return;
}
 
// Save length and address to get data from
data_ptr->buffer_in[0] = msg;
data_ptr->buffer_in_len = length;
data_ptr->master_dest_addr = address;
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
data_ptr->operating_state = I2C_SEND_ADDR;
data_ptr->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSP1CON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C_Configure_Slave(char addr) {
data_ptr->operating_mode = I2C_MODE_SLAVE;
 
SSP1ADD = addr << 1; // Set the slave address
 
SSP1STAT = 0x0;
SSP1CON1 = 0x0;
SSP1CON2 = 0x0;
SSP1CON3 = 0x0;
SSP1CON1bits.SSPM = 0xE; // Enable Slave 7-bit w/ start/stop interrupts
SSP1STATbits.SMP = 1; // Slew Off
SSP1CON2bits.SEN = 1; // Enable clock-stretching
SSP1CON1bits.SSPEN = 1; // Enable MSSP Module
}
 
void I2C_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (data_ptr->operating_mode == I2C_MODE_MASTER) {
I2C_Interrupt_Master();
} else if (data_ptr->operating_mode == I2C_MODE_SLAVE) {
I2C_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C_Interrupt_Master() {
// If we are in the middle of sending data
if (data_ptr->master_status == I2C_MASTER_SEND) {
switch (data_ptr->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
data_ptr->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (data_ptr->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (data_ptr->buffer_in_read_ind < data_ptr->buffer_in_len) {
SSP1BUF = data_ptr->buffer_in[data_ptr->buffer_in_read_ind];
data_ptr->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (data_ptr->master_status == I2C_MASTER_RECV) {
switch (data_ptr->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
data_ptr->operating_state = I2C_CHECK_ACK_RECV;
char tmp = (data_ptr->master_dest_addr << 1);
tmp |= 0x1;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
data_ptr->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = SSP1BUF;
data_ptr->buffer_in_write_ind++;
if (data_ptr->buffer_in_write_ind < data_ptr->buffer_in_len) {
// If we still need to read, send an ACK to the slave
data_ptr->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
data_ptr->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
data_ptr->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_RECV_OK;
break;
}
} else if (data_ptr->master_status == I2C_MASTER_RESTART) {
switch (data_ptr->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with write bit set
data_ptr->operating_state = I2C_CHECK_ACK_SEND;
SSP1BUF = (data_ptr->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSP1BUF = data_ptr->buffer_in[0];
data_ptr->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSP1CON2bits.ACKSTAT) {
SSP1CON2bits.RSEN = 1;
data_ptr->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
data_ptr->operating_state = I2C_CHECK_ACK_RECV;
char tmp = (data_ptr->master_dest_addr << 1);
tmp |= 0x1;
SSP1BUF = tmp;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSP1CON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
data_ptr->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = SSP1BUF;
data_ptr->buffer_in_write_ind++;
if (data_ptr->buffer_in_write_ind < data_ptr->buffer_in_len) {
// If we still need to read, send an ACK to the slave
data_ptr->operating_state = I2C_REQ_DATA;
SSP1CON2bits.ACKDT = 0; // ACK
SSP1CON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
data_ptr->operating_state = I2C_SEND_STOP;
SSP1CON2bits.ACKDT = 1; // NACK
SSP1CON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
data_ptr->operating_state = I2C_RCV_DATA;
SSP1CON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
data_ptr->operating_state = I2C_IDLE;
SSP1CON2bits.PEN = 1;
data_ptr->master_status = I2C_MASTER_IDLE;
data_ptr->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C_Interrupt_Slave() {
char received_data;
char data_read_from_buffer = 0;
char data_written_to_buffer = 0;
char overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSP1CON1bits.SSPOV == 1) {
SSP1CON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
data_ptr->operating_state = I2C_IDLE;
overrun_error = 1;
data_ptr->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSP1STATbits.BF == 1) {
received_data = SSP1BUF;
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (data_ptr->operating_state) {
case I2C_IDLE:
{
// Ignore anything except a start
if (SSP1STATbits.S == 1) {
data_ptr->buffer_in_len_tmp = 0;
data_ptr->operating_state = I2C_STARTED;
// if (data_read_from_buffer) {
// if (SSPSTATbits.D_A == 1) {
// DBG_PRINT_I2C("I2C Start: (ERROR) no address recieved\r\n");
// // This is bad because we got data and we wanted an address
// data_ptr->operating_state = I2C_IDLE;
// data_ptr->return_status = I2C_ERR_NOADDR;
// } else {
// // Determine if we are sending or receiving data
// if (SSPSTATbits.R_W == 1) {
// data_ptr->operating_state = I2C_SEND_DATA;
// } else {
// data_ptr->operating_state = I2C_RCV_DATA;
// }
// }
// } else {
// data_ptr->operating_state = I2C_STARTED;
// }
}
break;
}
case I2C_STARTED:
{
// In this case, we expect either an address or a stop bit
if (SSP1STATbits.P == 1) {
// Return to idle mode
data_ptr->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 0) {
// Address received
if (SSP1STATbits.R_nW == 0) {
// Slave write mode
data_ptr->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
data_ptr->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
data_ptr->operating_state = I2C_IDLE;
data_ptr->return_status = I2C_ERR_NODATA;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!data_ptr->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C_Process_Send(data_ptr->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSP1BUF = data_ptr->buffer_out[0];
data_ptr->buffer_out_ind = 1;
data_ptr->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
data_ptr->slave_sending_data = 0;
data_ptr->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (data_ptr->buffer_out_ind < data_ptr->buffer_out_len) {
SSP1BUF = data_ptr->buffer_out[data_ptr->buffer_out_ind];
data_ptr->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
data_ptr->slave_sending_data = 0;
data_ptr->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSP1STATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = received_data;
if (data_ptr->buffer_in_write_ind == I2C_BUFFER_SIZE-1) {
data_ptr->buffer_in_write_ind = 0;
} else {
data_ptr->buffer_in_write_ind++;
}
data_ptr->buffer_in_len_tmp++;
// Save the last byte received
data_ptr->slave_in_last_byte = received_data;
data_ptr->return_status = I2C_DATA_AVAL;
} else {
data_ptr->operating_state = I2C_IDLE;
data_ptr->return_status = I2C_ERR_NODATA;
}
}
data_ptr->buffer_in_len += data_ptr->buffer_in_len_tmp;
data_ptr->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSP1STATbits.D_nA == 1) {
// Data received
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = received_data;
if (data_ptr->buffer_in_write_ind == I2C_BUFFER_SIZE-1) {
data_ptr->buffer_in_write_ind = 0;
} else {
data_ptr->buffer_in_write_ind++;
}
data_ptr->buffer_in_len_tmp++;
// Save the last byte received
data_ptr->slave_in_last_byte = received_data;
data_ptr->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSP1STATbits.R_nW == 1) {
data_ptr->buffer_in_len += data_ptr->buffer_in_len_tmp;
data_ptr->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
data_ptr->operating_state = I2C_IDLE;
data_ptr->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSP1CON1bits.CKP == 0) {
SSP1CON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
char I2C_Get_Status() {
if (data_ptr->operating_mode == I2C_MODE_MASTER) {
if (data_ptr->master_status != I2C_MASTER_IDLE || data_ptr->buffer_in_len == 0) {
return 0;
} else {
return data_ptr->return_status;
}
} else {
if (data_ptr->operating_state != I2C_IDLE || data_ptr->buffer_in_len == 0) {
return 0;
} else {
return data_ptr->return_status;
}
}
}
 
char I2C_Buffer_Len() {
return data_ptr->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
char I2C_Read_Buffer(char *buffer) {
char i = 0;
while (data_ptr->buffer_in_len != 0) {
buffer[i] = data_ptr->buffer_in[data_ptr->buffer_in_read_ind];
i++;
if (data_ptr->buffer_in_read_ind == I2C_BUFFER_SIZE-1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
data_ptr->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
char I2C_Process_Send(char c) {
char ret = 0;
switch (c) {
case 0xAA:
data_ptr->buffer_out[0] = 'A';
data_ptr->buffer_out_len = 1;
ret = 1;
break;
case 0xBB:
data_ptr->buffer_out[0] = '1';
data_ptr->buffer_out[1] = '2';
data_ptr->buffer_out_len = 2;
ret = 1;
break;
}
return ret;
}
/PIC Projects/PICX_16F1829_BLE_IMU/I2C.h
0,0 → 1,83
#ifndef I2C_H
#define I2C_H
 
#define I2C_BUFFER_SIZE 20
 
// I2C Operating Speed
#define I2C_400KHZ 0x0
#define I2C_100KHZ 0x1
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status (Master)
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
 
// Return Status (Slave)
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
 
typedef struct {
char buffer_in[I2C_BUFFER_SIZE];
char buffer_in_len;
char buffer_in_len_tmp;
char buffer_in_read_ind;
char buffer_in_write_ind;
 
char buffer_out[I2C_BUFFER_SIZE];
char buffer_out_len;
char buffer_out_ind;
 
char operating_mode;
char operating_state;
char return_status;
 
char master_dest_addr;
char master_status;
 
char slave_in_last_byte;
char slave_sending_data;
} I2C_DATA;
 
void I2C_Init(I2C_DATA *data);
void I2C_Interrupt_Handler(void);
void I2C_Interrupt_Slave(void);
void I2C_Interrupt_Master(void);
void I2C_Configure_Slave(char);
void I2C_Configure_Master(char speed);
void I2C_Master_Send(char address, char *msg, char length);
void I2C_Master_Recv(char address, char length);
void I2C_Master_Restart(char address, char msg, char length);
char I2C_Get_Status(void);
char I2C_Buffer_Len(void);
char I2C_Read_Buffer(char *buffer);
char I2C_Process_Send(char);
 
#endif /* I2C_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/L3G.c
0,0 → 1,35
#include <xc.h>
#include "main.h"
#include "L3G.h"
#include "I2C.h"
 
void L3G_Init(void) {
char c[2] = {L3G_CTRL_REG1, 0x0F};
I2C_Master_Send(ADDRESS_GYRO, &c, 2);
while (!I2C_Get_Status());
}
 
void L3G_Read_Gyro(char *x_L, char *x_H,
char *y_L, char *y_H,
char *z_L, char *z_H) {
char result, length, buffer[10];
 
// Assert the MSB to autoincrement address
char c = L3G_OUT_X_L | (1 << 7);
 
I2C_Master_Restart(ADDRESS_GYRO, c, 6);
do {
result = I2C_Get_Status();
} while (!result);
 
// Read received data
length = I2C_Read_Buffer(buffer);
 
// Data is received in low-high byte order
*x_L = buffer[0];
*x_H = buffer[1];
*y_L = buffer[2];
*y_H = buffer[3];
*z_L = buffer[4];
*z_H = buffer[5];
}
/PIC Projects/PICX_16F1829_BLE_IMU/L3G.h
0,0 → 1,42
#ifndef L3G_H
#define L3G_H
 
// Register Addresses
#define L3G_WHO_AM_I 0x0F
 
#define L3G_CTRL_REG1 0x20
#define L3G_CTRL_REG2 0x21
#define L3G_CTRL_REG3 0x22
#define L3G_CTRL_REG4 0x23
#define L3G_CTRL_REG5 0x24
#define L3G_REFERENCE 0x25
#define L3G_OUT_TEMP 0x26
#define L3G_STATUS_REG 0x27
 
#define L3G_OUT_X_L 0x28
#define L3G_OUT_X_H 0x29
#define L3G_OUT_Y_L 0x2A
#define L3G_OUT_Y_H 0x2B
#define L3G_OUT_Z_L 0x2C
#define L3G_OUT_Z_H 0x2D
 
#define L3G_FIFO_CTRL_REG 0x2E
#define L3G_FIFO_SRC_REG 0x2F
 
#define L3G_INT1_CFG 0x30
#define L3G_INT1_SRC 0x31
#define L3G_INT1_THS_XH 0x32
#define L3G_INT1_THS_XL 0x33
#define L3G_INT1_THS_YH 0x34
#define L3G_INT1_THS_YL 0x35
#define L3G_INT1_THS_ZH 0x36
#define L3G_INT1_THS_ZL 0x37
#define L3G_INT1_DURATION 0x38
 
void L3G_Init(void);
void L3G_Read_Gyro(char *x_L, char *x_H,
char *y_L, char *y_H,
char *z_L, char *z_H);
 
#endif /* L3G_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/LSM303.c
0,0 → 1,81
#include <xc.h>
#include "main.h"
#include "LSM303.h"
#include "I2C.h"
 
void LSM303_Init(void) {
// Enable accelerometer, normal power mode, all axes enabled (100Hz)
char c[2] = {LSM303_CTRL_REG1_A, 0x57};
I2C_Master_Send(ADDRESS_ACCL, &c, 2);
while (!I2C_Get_Status());
 
// Enable high resolution mode, +- 2G
char d[2] = {LSM303_CTRL_REG4_A, 0x08};
I2C_Master_Send(ADDRESS_ACCL, &d, 2);
while (!I2C_Get_Status());
 
// Enable magnetometer, continuous conversion mode
char e[2] = {LSM303_MR_REG_M, 0x00};
I2C_Master_Send(ADDRESS_MAGN, &e, 2);
while (!I2C_Get_Status());
 
char f[2] = {LSM303_CRA_REG_M, 0x18}; // (75Hz)
I2C_Master_Send(ADDRESS_MAGN, &f, 2);
while (!I2C_Get_Status());
 
// LSM303_Set_Mag_Gain(magGain_40);
}
 
void LSM303_Set_Mag_Gain(magGain value) {
char c[2];
c[0] = LSM303_CRB_REG_M;
c[1] = (char)value;
I2C_Master_Send(ADDRESS_MAGN, &c, 2);
while (!I2C_Get_Status());
}
 
void LSM303_Read_Accl(char *x_L, char *x_H, char *y_L, char *y_H, char *z_L, char *z_H) {
char result, length, buffer[10] = {0};
 
// Assert the MSB to autoincrement address
char c = LSM303_OUT_X_L_A | 0x80;
 
I2C_Master_Restart(ADDRESS_ACCL, c, 6);
do {
result = I2C_Get_Status();
} while (!result);
 
// Read received data
length = I2C_Read_Buffer(buffer);
 
// Data is received in low-high byte order
*x_L = buffer[0];
*x_H = buffer[1];
*y_L = buffer[2];
*y_H = buffer[3];
*z_L = buffer[4];
*z_H = buffer[5];
}
 
void LSM303_Read_Magn(char *x_L, char *x_H, char *y_L, char *y_H, char *z_L, char *z_H) {
char result, length, buffer[10];
 
// Assert the MSB to autoincrement address
char c = LSM303_OUT_X_H_M;
 
I2C_Master_Restart(ADDRESS_MAGN, c, 6);
do {
result = I2C_Get_Status();
} while (!result);
 
// Read received data
length = I2C_Read_Buffer(buffer);
 
// Data is received in high-low byte order
*x_H = buffer[0];
*x_L = buffer[1];
*z_H = buffer[2];
*z_L = buffer[3];
*y_H = buffer[4];
*y_L = buffer[5];
}
/PIC Projects/PICX_16F1829_BLE_IMU/LSM303.h
0,0 → 1,100
#ifndef LSM303_H
#define LSM303_H
 
#define LSM303_CTRL_REG1_A 0x20
#define LSM303_CTRL_REG2_A 0x21
#define LSM303_CTRL_REG3_A 0x22
#define LSM303_CTRL_REG4_A 0x23
#define LSM303_CTRL_REG5_A 0x24
#define LSM303_CTRL_REG6_A 0x25
#define LSM303_REFERENCE_A 0x26
#define LSM303_STATUS_REG_A 0x27
 
#define LSM303_OUT_X_L_A 0x28
#define LSM303_OUT_X_H_A 0x29
#define LSM303_OUT_Y_L_A 0x2A
#define LSM303_OUT_Y_H_A 0x2B
#define LSM303_OUT_Z_L_A 0x2C
#define LSM303_OUT_Z_H_A 0x2D
 
#define LSM303_FIFO_CTRL_REG_A 0x2E
#define LSM303_FIFO_SRC_REG_A 0x2F
 
#define LSM303_INT1_CFG_A 0x30
#define LSM303_INT1_SRC_A 0x31
#define LSM303_INT1_THS_A 0x32
#define LSM303_INT1_DURATION_A 0x33
#define LSM303_INT2_CFG_A 0x34
#define LSM303_INT2_SRC_A 0x35
#define LSM303_INT2_THS_A 0x36
#define LSM303_INT2_DURATION_A 0x37
 
#define LSM303_CLICK_CFG_A 0x38
#define LSM303_CLICK_SRC_A 0x39
#define LSM303_CLICK_THS_A 0x3A
#define LSM303_TIME_LIMIT_A 0x3B
#define LSM303_TIME_LATENCY_A 0x3C
#define LSM303_TIME_WINDOW_A 0x3D
 
#define LSM303_CRA_REG_M 0x00
#define LSM303_CRB_REG_M 0x01
#define LSM303_MR_REG_M 0x02
 
#define LSM303_OUT_X_H_M 0x03
#define LSM303_OUT_X_L_M 0x04
#define LSM303_OUT_Y_H_M 0x05
#define LSM303_OUT_Y_L_M 0x06
#define LSM303_OUT_Z_H_M 0x07
#define LSM303_OUT_Z_L_M 0x08
 
#define LSM303_SR_REG_M 0x09
#define LSM303_IRA_REG_M 0x0A
#define LSM303_IRB_REG_M 0x0B
#define LSM303_IRC_REG_M 0x0C
 
#define LSM303_TEMP_OUT_H_M 0x31
#define LSM303_TEMP_OUT_L_M 0x32
 
#define LSM303DLH_OUT_Y_H_M 0x05
#define LSM303DLH_OUT_Y_L_M 0x06
#define LSM303DLH_OUT_Z_H_M 0x07
#define LSM303DLH_OUT_Z_L_M 0x08
 
#define LSM303DLM_OUT_Z_H_M 0x05
#define LSM303DLM_OUT_Z_L_M 0x06
#define LSM303DLM_OUT_Y_H_M 0x07
#define LSM303DLM_OUT_Y_L_M 0x08
 
#define LSM303DLHC_OUT_Z_H_M 0x05
#define LSM303DLHC_OUT_Z_L_M 0x06
#define LSM303DLHC_OUT_Y_H_M 0x07
#define LSM303DLHC_OUT_Y_L_M 0x08
 
typedef enum {
accGain_2 = 0x00,
accGain_4 = 0x10,
accGain_8 = 0x20,
accGain_16 = 0x30
} accGain;
 
typedef enum {
magGain_13 = 0x20,
magGain_19 = 0x40,
magGain_25 = 0x60,
magGain_40 = 0x80,
magGain_47 = 0xA0,
magGain_56 = 0xC0,
magGain_81 = 0xE0
} magGain;
 
void LSM303_Init(void);
void LSM303_Set_Mag_Gain(magGain value);
void LSM303_Read_Accl(char *x_L, char *x_H,
char *y_L, char *y_H,
char *z_L, char *z_H);
void LSM303_Read_Magn(char *x_L, char *x_H,
char *y_L, char *y_H,
char *z_L, char *z_H);
 
#endif /* LSM303_H */
 
/PIC Projects/PICX_16F1829_BLE_IMU/TIMER.c
0,0 → 1,53
#include <xc.h>
#include "main.h"
#include "TIMER.h"
 
void (*timer_1_callback)(void);
void (*timer_2_callback)(void);
 
void TIMER_1_Init(void (*callback)(void)) {
timer_1_callback = callback;
T1CONbits.TMR1CS = 2; // Clock source is ext oscillator
T1CONbits.T1CKPS = 0; // Prescale of 1:1
T1CONbits.T1OSCEN = 1; // Dedicated oscillator circuit enabled
T1CONbits.nT1SYNC = 1; // Async external clock input
T1CONbits.TMR1ON = 0; // Timer stopped
T1GCONbits.TMR1GE = 0; // Gate disabled
TMR1 = 0x8000;
 
PIE1bits.TMR1IE = 1; // Timer 1 overflow interrupt
}
 
void TIMER_1_Start(void) {
T1CONbits.TMR1ON = 1; // Start timer
}
 
void TIMER_1_Stop(void) {
T1CONbits.TMR1ON = 0; // Stop timer
}
 
void TIMER_1_Interrupt_Handler(void) {
timer_1_callback();
TMR1 = 0x8000;
}
 
void TIMER_2_Init(void (*callback)(void)) {
timer_2_callback = callback;
T2CONbits.T2OUTPS = 0; // 1:1 Postscaler
T2CONbits.TMR2ON = 0; // Timer stopped
T2CONbits.T2CKPS = 0; // 1:1 Perscaler
 
PIE1bits.TMR2IE = 1; // Timer 2 overflow interrupt
}
 
void TIMER_2_Start(void) {
T2CONbits.TMR2ON = 1; // Start timer
}
 
void TIMER_2_Stop(void) {
T2CONbits.TMR2ON = 0; // Stop timer
}
 
void TIMER_2_Interrupt_Handler(void) {
timer_2_callback();
}
/PIC Projects/PICX_16F1829_BLE_IMU/TIMER.h
0,0 → 1,15
#ifndef TIMER_H
#define TIMER_H
 
void TIMER_1_Init(void (*callback)(void));
void TIMER_1_Start(void);
void TIMER_1_Stop(void);
void TIMER_1_Interrupt_Handler(void);
 
// Timer 2 is used to manually PWM the LED
void TIMER_2_Init(void (*callback)(void));
void TIMER_2_Start(void);
void TIMER_2_Stop(void);
void TIMER_2_Interrupt_Handler(void);
 
#endif /* TIMER_H */
/PIC Projects/PICX_16F1829_BLE_IMU/INTERRUPT.c
0,0 → 1,55
#include <xc.h>
#include "main.h"
#include "INTERRUPT.h"
#include "TIMER.h"
#include "UART.h"
#include "I2C.h"
 
void INTERRUPT_Init(void) {
INTCONbits.GIE = 0;
INTCONbits.PEIE = 1;
}
 
void INTERRUPT_Enable(void) {
INTCONbits.GIE = 1;
}
 
void INTERRUPT_Disable(void) {
INTCONbits.GIE = 0;
}
 
void interrupt INTERRUPT_Handler(void) {
// check Timer 1 interrupt flag
if (PIR1bits.TMR1IF) {
TIMER_1_Interrupt_Handler();
PIR1bits.TMR1IF = 0;
}
 
// Check Timer 2 interrupt flag
if (PIR1bits.TMR2IF) {
TIMER_2_Interrupt_Handler();
PIR1bits.TMR2IF = 0;
}
 
// Check UART RX interrupt flag
if (PIE1bits.RCIE) {
if (PIR1bits.RCIF) {
UART_RX_Interrupt_Handler();
// PIR1bits.RCIF = 0; // RXIF is read-only!
}
}
 
// Check UART TX interrupt flag
if (PIE1bits.TXIE) {
if (PIR1bits.TXIF) {
UART_TX_Interrupt_Handler();
// PIR1bits.TXIF = 0; // TXIF is read-only!
}
}
 
// Check I2C interrupt flag
if (PIR1bits.SSP1IF) {
I2C_Interrupt_Handler();
PIR1bits.SSP1IF = 0;
}
}
/PIC Projects/PICX_16F1829_BLE_IMU/main.h
0,0 → 1,63
#ifndef MAIN_H
#define MAIN_H
 
#define UART_RX_TRIS TRISCbits.TRISC5
#define UART_TX_TRIS TRISCbits.TRISC4
#define UART_CTS_TRIS TRISCbits.TRISC3
#define UART_CTS_LAT LATCbits.LATC3
#define UART_RTS_TRIS TRISCbits.TRISC6
#define UART_RTS_LAT LATCbits.LATC6
 
#define I2C_CLK_TRIS TRISBbits.TRISB6
#define I2C_DAT_TRIS TRISBbits.TRISB4
 
#define LED_R_TRIS TRISCbits.TRISC0
#define LED_R_LAT LATCbits.LATC0
 
#define LED_G_TRIS TRISCbits.TRISC1
#define LED_G_LAT LATCbits.LATC1
 
#define LED_B_TRIS TRISCbits.TRISC2
#define LED_B_LAT LATCbits.LATC2
 
// Active low reset
#define BLE_RESET_TRIS TRISCbits.TRISC7
#define BLE_RESET_LAT LATCbits.LATC7
 
#define ADDRESS_GYRO 0x6B
#define ADDRESS_ACCL 0x19
#define ADDRESS_MAGN 0x1E
#define ADDRESS_LIPO 0x36
 
#define _XTAL_FREQ 32000000
 
#define LED_R_MAX_BRIGHTNESS 5
#define LED_G_MAX_BRIGHTNESS 20
#define LED_B_MAX_BRIGHTNESS 30 // Dont set this past 100!
 
#endif /* MAIN_H */
 
// <editor-fold defaultstate="collapsed" desc="Pinouts">
/*
1/RA3 - MCLR
2/RC5 - UART RX
3/RC4 - UART TX
4/RC3 - UART CTS
5/RC6 - UART RTS
6/RC7 - BLE RESET
7/RB7 - Acc Interrupt 1
8/RB6 - I2C SCL
9/RB5 - Mag Interrupt
10/RB4 - I2C SDA
11/RC2 - BLE SLEEP
12/RC1 - LED
13/RC0 - BLE Mode Toggle
14/RA2 - Gyro Interrupt 2
15/RA1 - ICSPCLK
16/RA0 - ISCLDAT
17/VSS - GND
18/VDD - VDD
19/RA5 - T1 OSO
20/RA4 - T1 OSO
*/
// </editor-fold>
/PIC Projects/PICX_16F1829_BLE_IMU/INTERRUPT.h
0,0 → 1,8
#ifndef INTERRUPT_H
#define INTERRUPT_H
 
void INTERRUPT_Init(void);
void INTERRUPT_Enable(void);
void INTERRUPT_Disable(void);
 
#endif /* INTERRUPT_H */
/PIC Projects/PICX_16F1829_BLE_IMU/UART.c
0,0 → 1,106
#include <xc.h>
#include "main.h"
#include "UART.h"
 
static UART_DATA *data_ptr;
 
void UART_Init(UART_DATA *data) {
data_ptr = data;
 
APFCON0bits.RXDTSEL = 1; // Change RX from RB5 to RC5
APFCON0bits.TXCKSEL = 1; // Change TX from RB7 to RC4
UART_RX_TRIS = 1;
UART_TX_TRIS = 0;
 
SPBRG = 16; // Set baud rate to 115200 @ 32MHz
BAUDCONbits.BRG16 = 0; // 8-bit baud rate generator
TXSTAbits.BRGH = 1; // High baud rate select
 
TXSTAbits.SYNC = 0; // Async operation
RCSTAbits.CREN = 1; // Enable reception module
TXSTAbits.TXEN = 1; // Enable transmission module
RCSTAbits.SPEN = 1; // Enable EUSART module
 
PIE1bits.RCIE = 1; // UART RX interrupt starts enabled
PIE1bits.TXIE = 0; // UART TX interrupt starts disabled
 
// Initialize local variables
data_ptr->buffer_in_read_ind = 0;
data_ptr->buffer_in_write_ind = 0;
data_ptr->buffer_in_len = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
 
void UART_TX_Interrupt_Handler(void) {
// Send more data when transmit buffer is empty
if (data_ptr->buffer_out_ind != data_ptr->buffer_out_len) {
TXREG = data_ptr->buffer_out[data_ptr->buffer_out_ind];
data_ptr->buffer_out_ind++;
} else {
// Stop processing TX interrupts if there is no more data to send
while (!TXSTAbits.TRMT);
PIE1bits.TXIE = 0;
data_ptr->buffer_out_ind = 0;
data_ptr->buffer_out_len = 0;
}
}
 
void UART_RX_Interrupt_Handler(void) {
char c = RCREG;
 
// Read received data into buffer
data_ptr->buffer_in[data_ptr->buffer_in_write_ind] = c;
if (data_ptr->buffer_in_write_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_write_ind = 0;
} else {
data_ptr->buffer_in_write_ind++;
}
 
// Increment read counter to keep only the latest data
if (data_ptr->buffer_in_len < UART_BUFFER_SIZE) {
data_ptr->buffer_in_len++;
} else {
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
 
// Reset receiver module on overrun error
if (RCSTAbits.OERR == 1) {
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
}
 
void UART_Write(char *data, char length) {
// Ensure that no transmission is currently running
while (PIE1bits.TXIE);
 
data_ptr->buffer_out_len = length;
data_ptr->buffer_out_ind = 0;
for (char i = 0; i < length; i++) {
data_ptr->buffer_out[i] = data[i];
}
 
// Start transmission
PIE1bits.TXIE = 1;
}
 
char UART_Read(char *buffer) {
PIE1bits.RCIE = 0; // Disable receiver interrupt
char length = data_ptr->buffer_in_len;
for (char i = 0; i < length; i++) {
buffer[i] = data_ptr->buffer_in[data_ptr->buffer_in_read_ind];
if (data_ptr->buffer_in_read_ind == UART_BUFFER_SIZE - 1) {
data_ptr->buffer_in_read_ind = 0;
} else {
data_ptr->buffer_in_read_ind++;
}
}
data_ptr->buffer_in_len -= length;
PIE1bits.RCIE = 1; // Re-enable receiver interrupt
return length;
}
/PIC Projects/PICX_16F1829_BLE_IMU/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_27J13/nbproject/Makefile-default.mk
0,0 → 1,384
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=cof
DEBUGGABLE_SUFFIX=cof
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=cof
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_UART.p1 ${OBJECTDIR}/base_I2C.p1 ${OBJECTDIR}/base_SPI.p1 ${OBJECTDIR}/display_led_HT16K33.p1 ${OBJECTDIR}/sensor_nfc_PN532.p1 ${OBJECTDIR}/base_TIMERS.p1 ${OBJECTDIR}/comm_xbee.p1 ${OBJECTDIR}/base_ADC.p1 ${OBJECTDIR}/base_INTERRUPTS.p1 ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1 ${OBJECTDIR}/display_oled_ssd1306.p1 ${OBJECTDIR}/display_oled_ssd1331.p1 ${OBJECTDIR}/glcdfont.p1 ${OBJECTDIR}/sensor_lux_TSL2561.p1 ${OBJECTDIR}/sensor_temp_BMP085.p1 ${OBJECTDIR}/sensor_gyro_L3G.p1 ${OBJECTDIR}/sensor_accel_LSM303.p1 ${OBJECTDIR}/sensor_rtc_DS3231.p1
POSSIBLE_DEPFILES=${OBJECTDIR}/main.p1.d ${OBJECTDIR}/base_UART.p1.d ${OBJECTDIR}/base_I2C.p1.d ${OBJECTDIR}/base_SPI.p1.d ${OBJECTDIR}/display_led_HT16K33.p1.d ${OBJECTDIR}/sensor_nfc_PN532.p1.d ${OBJECTDIR}/base_TIMERS.p1.d ${OBJECTDIR}/comm_xbee.p1.d ${OBJECTDIR}/base_ADC.p1.d ${OBJECTDIR}/base_INTERRUPTS.p1.d ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d ${OBJECTDIR}/display_oled_ssd1306.p1.d ${OBJECTDIR}/display_oled_ssd1331.p1.d ${OBJECTDIR}/glcdfont.p1.d ${OBJECTDIR}/sensor_lux_TSL2561.p1.d ${OBJECTDIR}/sensor_temp_BMP085.p1.d ${OBJECTDIR}/sensor_gyro_L3G.p1.d ${OBJECTDIR}/sensor_accel_LSM303.p1.d ${OBJECTDIR}/sensor_rtc_DS3231.p1.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.p1 ${OBJECTDIR}/base_UART.p1 ${OBJECTDIR}/base_I2C.p1 ${OBJECTDIR}/base_SPI.p1 ${OBJECTDIR}/display_led_HT16K33.p1 ${OBJECTDIR}/sensor_nfc_PN532.p1 ${OBJECTDIR}/base_TIMERS.p1 ${OBJECTDIR}/comm_xbee.p1 ${OBJECTDIR}/base_ADC.p1 ${OBJECTDIR}/base_INTERRUPTS.p1 ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1 ${OBJECTDIR}/display_oled_ssd1306.p1 ${OBJECTDIR}/display_oled_ssd1331.p1 ${OBJECTDIR}/glcdfont.p1 ${OBJECTDIR}/sensor_lux_TSL2561.p1 ${OBJECTDIR}/sensor_temp_BMP085.p1 ${OBJECTDIR}/sensor_gyro_L3G.p1 ${OBJECTDIR}/sensor_accel_LSM303.p1 ${OBJECTDIR}/sensor_rtc_DS3231.p1
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=18F27J13
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_UART.p1: base_UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_UART.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_UART.p1 base_UART.c
@-${MV} ${OBJECTDIR}/base_UART.d ${OBJECTDIR}/base_UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_I2C.p1: base_I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_I2C.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_I2C.p1 base_I2C.c
@-${MV} ${OBJECTDIR}/base_I2C.d ${OBJECTDIR}/base_I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_SPI.p1: base_SPI.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_SPI.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_SPI.p1 base_SPI.c
@-${MV} ${OBJECTDIR}/base_SPI.d ${OBJECTDIR}/base_SPI.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_SPI.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_led_HT16K33.p1: display_led_HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_led_HT16K33.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_led_HT16K33.p1 display_led_HT16K33.c
@-${MV} ${OBJECTDIR}/display_led_HT16K33.d ${OBJECTDIR}/display_led_HT16K33.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_led_HT16K33.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_nfc_PN532.p1: sensor_nfc_PN532.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_nfc_PN532.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_nfc_PN532.p1 sensor_nfc_PN532.c
@-${MV} ${OBJECTDIR}/sensor_nfc_PN532.d ${OBJECTDIR}/sensor_nfc_PN532.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_nfc_PN532.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_TIMERS.p1: base_TIMERS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_TIMERS.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_TIMERS.p1 base_TIMERS.c
@-${MV} ${OBJECTDIR}/base_TIMERS.d ${OBJECTDIR}/base_TIMERS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_TIMERS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/comm_xbee.p1: comm_xbee.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/comm_xbee.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/comm_xbee.p1 comm_xbee.c
@-${MV} ${OBJECTDIR}/comm_xbee.d ${OBJECTDIR}/comm_xbee.p1.d
@${FIXDEPS} ${OBJECTDIR}/comm_xbee.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_ADC.p1: base_ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_ADC.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_ADC.p1 base_ADC.c
@-${MV} ${OBJECTDIR}/base_ADC.d ${OBJECTDIR}/base_ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1: display_oled_NHD-0216KZW-AB5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1 display_oled_NHD-0216KZW-AB5.c
@-${MV} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.d ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_ssd1306.p1: display_oled_ssd1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_ssd1306.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_ssd1306.p1 display_oled_ssd1306.c
@-${MV} ${OBJECTDIR}/display_oled_ssd1306.d ${OBJECTDIR}/display_oled_ssd1306.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_ssd1306.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_ssd1331.p1: display_oled_ssd1331.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_ssd1331.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_ssd1331.p1 display_oled_ssd1331.c
@-${MV} ${OBJECTDIR}/display_oled_ssd1331.d ${OBJECTDIR}/display_oled_ssd1331.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_ssd1331.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/glcdfont.p1: glcdfont.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/glcdfont.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/glcdfont.p1 glcdfont.c
@-${MV} ${OBJECTDIR}/glcdfont.d ${OBJECTDIR}/glcdfont.p1.d
@${FIXDEPS} ${OBJECTDIR}/glcdfont.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_lux_TSL2561.p1: sensor_lux_TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_lux_TSL2561.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_lux_TSL2561.p1 sensor_lux_TSL2561.c
@-${MV} ${OBJECTDIR}/sensor_lux_TSL2561.d ${OBJECTDIR}/sensor_lux_TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_lux_TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_temp_BMP085.p1: sensor_temp_BMP085.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_temp_BMP085.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_temp_BMP085.p1 sensor_temp_BMP085.c
@-${MV} ${OBJECTDIR}/sensor_temp_BMP085.d ${OBJECTDIR}/sensor_temp_BMP085.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_temp_BMP085.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_gyro_L3G.p1: sensor_gyro_L3G.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_gyro_L3G.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_gyro_L3G.p1 sensor_gyro_L3G.c
@-${MV} ${OBJECTDIR}/sensor_gyro_L3G.d ${OBJECTDIR}/sensor_gyro_L3G.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_gyro_L3G.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_accel_LSM303.p1: sensor_accel_LSM303.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_accel_LSM303.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_accel_LSM303.p1 sensor_accel_LSM303.c
@-${MV} ${OBJECTDIR}/sensor_accel_LSM303.d ${OBJECTDIR}/sensor_accel_LSM303.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_accel_LSM303.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_rtc_DS3231.p1: sensor_rtc_DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_rtc_DS3231.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_rtc_DS3231.p1 sensor_rtc_DS3231.c
@-${MV} ${OBJECTDIR}/sensor_rtc_DS3231.d ${OBJECTDIR}/sensor_rtc_DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_rtc_DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
else
${OBJECTDIR}/main.p1: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/main.p1 main.c
@-${MV} ${OBJECTDIR}/main.d ${OBJECTDIR}/main.p1.d
@${FIXDEPS} ${OBJECTDIR}/main.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_UART.p1: base_UART.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_UART.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_UART.p1 base_UART.c
@-${MV} ${OBJECTDIR}/base_UART.d ${OBJECTDIR}/base_UART.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_UART.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_I2C.p1: base_I2C.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_I2C.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_I2C.p1 base_I2C.c
@-${MV} ${OBJECTDIR}/base_I2C.d ${OBJECTDIR}/base_I2C.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_I2C.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_SPI.p1: base_SPI.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_SPI.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_SPI.p1 base_SPI.c
@-${MV} ${OBJECTDIR}/base_SPI.d ${OBJECTDIR}/base_SPI.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_SPI.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_led_HT16K33.p1: display_led_HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_led_HT16K33.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_led_HT16K33.p1 display_led_HT16K33.c
@-${MV} ${OBJECTDIR}/display_led_HT16K33.d ${OBJECTDIR}/display_led_HT16K33.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_led_HT16K33.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_nfc_PN532.p1: sensor_nfc_PN532.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_nfc_PN532.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_nfc_PN532.p1 sensor_nfc_PN532.c
@-${MV} ${OBJECTDIR}/sensor_nfc_PN532.d ${OBJECTDIR}/sensor_nfc_PN532.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_nfc_PN532.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_TIMERS.p1: base_TIMERS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_TIMERS.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_TIMERS.p1 base_TIMERS.c
@-${MV} ${OBJECTDIR}/base_TIMERS.d ${OBJECTDIR}/base_TIMERS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_TIMERS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/comm_xbee.p1: comm_xbee.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/comm_xbee.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/comm_xbee.p1 comm_xbee.c
@-${MV} ${OBJECTDIR}/comm_xbee.d ${OBJECTDIR}/comm_xbee.p1.d
@${FIXDEPS} ${OBJECTDIR}/comm_xbee.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_ADC.p1: base_ADC.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_ADC.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_ADC.p1 base_ADC.c
@-${MV} ${OBJECTDIR}/base_ADC.d ${OBJECTDIR}/base_ADC.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_ADC.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/base_INTERRUPTS.p1: base_INTERRUPTS.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/base_INTERRUPTS.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/base_INTERRUPTS.p1 base_INTERRUPTS.c
@-${MV} ${OBJECTDIR}/base_INTERRUPTS.d ${OBJECTDIR}/base_INTERRUPTS.p1.d
@${FIXDEPS} ${OBJECTDIR}/base_INTERRUPTS.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1: display_oled_NHD-0216KZW-AB5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1 display_oled_NHD-0216KZW-AB5.c
@-${MV} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.d ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_NHD-0216KZW-AB5.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_ssd1306.p1: display_oled_ssd1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_ssd1306.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_ssd1306.p1 display_oled_ssd1306.c
@-${MV} ${OBJECTDIR}/display_oled_ssd1306.d ${OBJECTDIR}/display_oled_ssd1306.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_ssd1306.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/display_oled_ssd1331.p1: display_oled_ssd1331.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/display_oled_ssd1331.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/display_oled_ssd1331.p1 display_oled_ssd1331.c
@-${MV} ${OBJECTDIR}/display_oled_ssd1331.d ${OBJECTDIR}/display_oled_ssd1331.p1.d
@${FIXDEPS} ${OBJECTDIR}/display_oled_ssd1331.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/glcdfont.p1: glcdfont.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/glcdfont.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/glcdfont.p1 glcdfont.c
@-${MV} ${OBJECTDIR}/glcdfont.d ${OBJECTDIR}/glcdfont.p1.d
@${FIXDEPS} ${OBJECTDIR}/glcdfont.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_lux_TSL2561.p1: sensor_lux_TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_lux_TSL2561.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_lux_TSL2561.p1 sensor_lux_TSL2561.c
@-${MV} ${OBJECTDIR}/sensor_lux_TSL2561.d ${OBJECTDIR}/sensor_lux_TSL2561.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_lux_TSL2561.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_temp_BMP085.p1: sensor_temp_BMP085.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_temp_BMP085.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_temp_BMP085.p1 sensor_temp_BMP085.c
@-${MV} ${OBJECTDIR}/sensor_temp_BMP085.d ${OBJECTDIR}/sensor_temp_BMP085.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_temp_BMP085.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_gyro_L3G.p1: sensor_gyro_L3G.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_gyro_L3G.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_gyro_L3G.p1 sensor_gyro_L3G.c
@-${MV} ${OBJECTDIR}/sensor_gyro_L3G.d ${OBJECTDIR}/sensor_gyro_L3G.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_gyro_L3G.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_accel_LSM303.p1: sensor_accel_LSM303.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_accel_LSM303.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_accel_LSM303.p1 sensor_accel_LSM303.c
@-${MV} ${OBJECTDIR}/sensor_accel_LSM303.d ${OBJECTDIR}/sensor_accel_LSM303.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_accel_LSM303.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
${OBJECTDIR}/sensor_rtc_DS3231.p1: sensor_rtc_DS3231.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/sensor_rtc_DS3231.p1.d
${MP_CC} --pass1 $(MP_EXTRA_CC_PRE) --chip=$(MP_PROCESSOR_OPTION) -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -o${OBJECTDIR}/sensor_rtc_DS3231.p1 sensor_rtc_DS3231.c
@-${MV} ${OBJECTDIR}/sensor_rtc_DS3231.d ${OBJECTDIR}/sensor_rtc_DS3231.p1.d
@${FIXDEPS} ${OBJECTDIR}/sensor_rtc_DS3231.p1.d $(SILENT) -rsi ${MP_CC_DIR}../
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G --asmlist -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.map -D__DEBUG=1 --debugger=pickit3 --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
@${RM} dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.hex
else
dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_CC} $(MP_EXTRA_LD_PRE) --chip=$(MP_PROCESSOR_OPTION) -G --asmlist -mdist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.map --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PICX_27J13/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Tue Apr 23 02:19:35 EDT 2013
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc8\\v1.12\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=415494acd195d89b2f6d7a36797a5ab4
default.languagetoolchain.version=1.12
host.platform=windows
conf.ids=default
default.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=10ef1ca121a2d422272c53829f548789
/PIC Projects/PICX_27J13/nbproject/configurations.xml
0,0 → 1,183
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>defines.h</itemPath>
<itemPath>base_UART.h</itemPath>
<itemPath>base_SPI.h</itemPath>
<itemPath>base_I2C.h</itemPath>
<itemPath>base_INTERRUPTS.h</itemPath>
<itemPath>display_oled_ssd1306.h</itemPath>
<itemPath>sensor_nfc_PN532.h</itemPath>
<itemPath>display_led_HT16K33.h</itemPath>
<itemPath>display_oled_ssd1331.h</itemPath>
<itemPath>base_TIMERS.h</itemPath>
<itemPath>sensor_lux_TSL2561.h</itemPath>
<itemPath>display_oled_NHD-0216KZW-AB5.h</itemPath>
<itemPath>sensor_temp_BMP085.h</itemPath>
<itemPath>comm_xbee.h</itemPath>
<itemPath>base_ADC.h</itemPath>
<itemPath>sensor_gyro_L3G.h</itemPath>
<itemPath>sensor_accel_LSM303.h</itemPath>
<itemPath>sensor_rtc_DS3231.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>base_UART.c</itemPath>
<itemPath>base_I2C.c</itemPath>
<itemPath>base_SPI.c</itemPath>
<itemPath>display_led_HT16K33.c</itemPath>
<itemPath>sensor_nfc_PN532.c</itemPath>
<itemPath>base_TIMERS.c</itemPath>
<itemPath>comm_xbee.c</itemPath>
<itemPath>base_ADC.c</itemPath>
<itemPath>base_INTERRUPTS.c</itemPath>
<itemPath>display_oled_NHD-0216KZW-AB5.c</itemPath>
<itemPath>display_oled_ssd1306.c</itemPath>
<itemPath>display_oled_ssd1331.c</itemPath>
<itemPath>glcdfont.c</itemPath>
<itemPath>sensor_lux_TSL2561.c</itemPath>
<itemPath>sensor_temp_BMP085.c</itemPath>
<itemPath>sensor_gyro_L3G.c</itemPath>
<itemPath>sensor_accel_LSM303.c</itemPath>
<itemPath>sensor_rtc_DS3231.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC18F27J13</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>XC8</languageToolchain>
<languageToolchainVersion>1.12</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<HI-TECH-COMP>
<property key="define-macros" value=""/>
<property key="extra-include-directories" value=""/>
<property key="identifier-length" value="255"/>
<property key="operation-mode" value="free"/>
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
<property key="optimization-assembler" value="true"/>
<property key="optimization-assembler-files" value="false"/>
<property key="optimization-debug" value="false"/>
<property key="optimization-global" value="true"/>
<property key="optimization-level" value="9"/>
<property key="optimization-set" value="default"/>
<property key="optimization-speed" value="true"/>
<property key="preprocess-assembler" value="true"/>
<property key="undefine-macros" value=""/>
<property key="use-cci" value="false"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="0"/>
<property key="what-to-do" value="ignore"/>
</HI-TECH-COMP>
<HI-TECH-LINK>
<property key="additional-options-checksum" value=""/>
<property key="additional-options-code-offset" value=""/>
<property key="additional-options-errata" value=""/>
<property key="additional-options-extend-address" value="false"/>
<property key="additional-options-trace-type" value=""/>
<property key="backup-reset-condition-flags" value="false"/>
<property key="calibrate-oscillator" value="true"/>
<property key="calibrate-oscillator-value" value=""/>
<property key="clear-bss" value="true"/>
<property key="code-model-external" value="wordwrite"/>
<property key="code-model-rom" value=""/>
<property key="create-html-files" value="false"/>
<property key="data-model-ram" value=""/>
<property key="data-model-size-of-double" value="24"/>
<property key="data-model-size-of-float" value="24"/>
<property key="display-class-usage" value="false"/>
<property key="display-hex-usage" value="false"/>
<property key="display-overall-usage" value="true"/>
<property key="display-psect-usage" value="false"/>
<property key="fill-flash-options-addr" value=""/>
<property key="fill-flash-options-const" value=""/>
<property key="fill-flash-options-how" value="0"/>
<property key="fill-flash-options-inc-const" value="1"/>
<property key="fill-flash-options-increment" value=""/>
<property key="fill-flash-options-seq" value=""/>
<property key="fill-flash-options-what" value="0"/>
<property key="format-hex-file-for-download" value="false"/>
<property key="initialize-data" value="true"/>
<property key="keep-generated-startup.as" value="false"/>
<property key="link-in-c-library" value="true"/>
<property key="link-in-peripheral-library" value="true"/>
<property key="managed-stack" value="false"/>
<property key="opt-xc8-linker-file" value="false"/>
<property key="opt-xc8-linker-link_startup" value="false"/>
<property key="opt-xc8-linker-serial" value=""/>
<property key="program-the-device-with-default-config-words" value="true"/>
</HI-TECH-LINK>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff7"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="true"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x1fff7"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
<XC8-config-global>
</XC8-config-global>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PICX_27J13/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PICX_27J13
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PICX_27J13/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PICX_27J13.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PICX_27J13.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=picx27j13.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/picx27j13.tar
/PIC Projects/PICX_27J13/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PICX_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=picx27j13/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/picx27j13/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/picx27j13.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/picx27j13.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PICX_27J13/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.6.0_32-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\xc8\v1.12\bin\xc8.exe"
# MP_CPPC is not defined
# MP_BC is not defined
# MP_AS is not defined
# MP_LD is not defined
# MP_AR is not defined
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\xc8\v1.12\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
# MP_AS_DIR is not defined
# MP_LD_DIR is not defined
# MP_AR_DIR is not defined
# MP_BC_DIR is not defined
/PIC Projects/PICX_27J13/nbproject/project.properties
--- PICX_27J13/nbproject/project.xml (nonexistent)
+++ PICX_27J13/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PICX_27J13</name>
+ <creation-uuid>18902124-e972-4028-9598-101aba5c4b06</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PICX_27J13/base_SPI.c
0,0 → 1,231
#include <xc.h>
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "base_SPI.h"
#include "base_UART.h"
 
static SPI_DATA *spi_data_p;
 
void SPI2_Init(SPI_DATA *data, char speed) {
spi_data_p = data;
 
// Set up SPI2 with specified pins
RPINR22 = PPS_SPI2_CLK_IN; // SPI2 CLK Input
PPS_SPI2_CLK_OUT = 11; // SPI2 CLK Output
 
#ifndef SPI2_WRITE_ONLY
RPINR21 = PPS_SPI2_MISO; // SPI2 Data Input
SPI_MISO_TRIS = 1; // SPI2 data in pin (MISO)
#endif
SPI_CLK_TRIS = 0; // SPI2 clock pin
PPS_SPI2_MOSI = 10; // SPI2 Data Output (MOSI)
SPI_MOSI_TRIS = 0; // SPI2 data out pin (MOSI)
 
SPI_SLAVE_SELECT_TRIS = 0; // SPI2 slave select
SPI_SLAVE_SELECT_LAT = 1; // SPI2 SS high (Idle)
 
SPI_RESET_TRIS = 0; // SPI2 reset
SPI_RESET_LAT = 1; // SPI2 reset active low
 
SPI_DC_SELECT_TRIS = 0; // SPI2 D/C select
SPI_DC_SELECT_LAT = 0;
 
SSP2STATbits.SMP = 0; // Input is sampled in the middle of data output time
SSP2STATbits.CKE = 0; // Transmit occurs on transition from Idle to active clock state
 
SSP2CON1bits.SSPM = speed;
 
SSP2CON1bits.CKP = 1; // Idle state for clock is a high level
SSP2CON1bits.SSPEN = 1; // Enable MSSP module
 
#ifdef SPI2_USE_INTERRUPT
PIE3bits.SSP2IE = 1; // Enable MSSP2 interrupt
#else
PIE3bits.SSP2IE = 0;
#endif
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in_len = 0;
spi_data_p->buffer_in_read_ind = 0;
spi_data_p->buffer_in_write_ind = 0;
#endif
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
 
void SPI2_Write(char *msg, unsigned int length) {
unsigned int i = 0;
#ifdef SPI2_USE_INTERRUPT
spi_data_p->buffer_out_len = length;
spi_data_p->buffer_out_ind = 1;
for (i = 0; i < length; i++) {
spi_data_p->buffer_out[i] = msg[i];
}
SPI_SLAVE_SELECT_LAT = 0; // Bring SS line low
SSP2BUF = spi_data_p->buffer_out[0]; // Transmit first byte
#else
SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP2BUF = msg[i];
i++;
while (!SSP2STATbits.BF);
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
char tmp = SSP2BUF;
#endif
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
void SPI2_Write_Repeat(char c, unsigned int length) {
#ifdef SPI2_USE_INTERRUPT
// TODO Implement interrupts for SPI2
#else
unsigned int i = 0;
SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP2BUF = c;
i++;
while (!SSP2STATbits.BF);
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
char tmp = SSP2BUF;
#endif
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
void SPI2_DMA_Init(void) {
DMACON1bits.SSCON0 = 0;
DMACON1bits.SSCON1 = 0; // DYLINTEN is software programmable
 
DMACON1bits.TXINC = 1; // TXADDR is automatically incremented
DMACON1bits.RXINC = 0; // RXADDR is not automatically incremented
 
DMACON1bits.DUPLEX0 = 1;
DMACON1bits.DUPLEX1 = 0; // Half-duplex mode, transmission only
 
DMACON1bits.DLYINTEN = 0; // Interrupt is disabled
 
DMACON2bits.DLYCYC = 0b0000; // Delay time of 1 cycle between bytes
DMACON2bits.INTLVL = 0b0000; // Interrupt on transfer complete
}
 
void SPI2_DMA_Start(unsigned int length, void* TXADDR, void* RXADDR) {
// Set length of message to transmit
DMABCH = (char)(length-1 >> 8);
DMABCL = (char)(length-1);
 
// Set sourcing address
TXADDRH = (char)((int)TXADDR >> 8);
TXADDRL = (char)((int)TXADDR);
 
// Set receiving address
RXADDRH = (char)((int)RXADDR >> 8);
RXADDRL = (char)((int)RXADDR);
 
DMACON1bits.DMAEN = 1; // Start transmission
}
 
#ifndef SPI2_WRITE_ONLY
void SPI2_Recv_Interrupt_Handler() {
char c;
 
if (SSP2STATbits.BF) { // Check if data receive flag is set
if (spi_data_p->buffer_in_len == MAXSPIBUF - 1) {
char output[64];
sprintf(output, "SPI2: (ERROR) buffer overflow\r\n");
DBG_PRINT_SPI(output, strlen(output));
c = SSP2BUF; // Read SSP2BUF to clear it
} else {
// Save received data into buffer
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
 
// Put next byte in SSP2BUF for transmit
if (spi_data_p->buffer_out_ind != spi_data_p->buffer_out_len) {
SSP2BUF = spi_data_p->buffer_out[spi_data_p->buffer_out_ind];
spi_data_p->buffer_out_ind++;
} else {
SPI_SLAVE_SELECT_LAT = 1; // Bring SS line high
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
}
}
}
 
void SPI2_Read(char length) {
#ifdef SPI2_USE_INTERRUPT
spi_data_p->buffer_out_len = length;
spi_data_p->buffer_out_ind = 1;
for (char i = 0; i < length; i++) {
spi_data_p->buffer_out[i] = 0x0;
}
SPI_SLAVE_SELECT_LAT = 0; // Bring SS line low
SSP2BUF = spi_data_p->buffer_out[0]; // Transmit first byte
#else
SPI_SLAVE_SELECT_LAT = 0;
 
for (char i = 0; i < length; i++) {
SSP2BUF = 0x0;
while (!SSP2STATbits.BF);
 
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
char SPI2_Buffer_Len() {
return spi_data_p->buffer_in_len;
}
 
char SPI2_Read_Buffer(char* buffer) {
char i = 0;
while (spi_data_p->buffer_in_len != 0) {
buffer[i] = spi_data_p->buffer_in[spi_data_p->buffer_in_read_ind];
i++;
if (spi_data_p->buffer_in_read_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_read_ind = 0;
} else {
spi_data_p->buffer_in_read_ind++;
}
spi_data_p->buffer_in_len--;
}
return i;
}
#endif
/PIC Projects/PICX_27J13/base_SPI.h
0,0 → 1,46
#ifndef SPI_H
#define SPI_H
 
#define MAXSPIBUF 64
 
#define SPI2_WRITE_ONLY
 
// Option to use interrupt. If interrupt are used, SPI write does not block but
// there is a longer delay between reading/writing data
//#define SPI2_USE_INTERRUPT
 
// SPI speed selection
#define SPI2_FOSC_TMR2 0b0011
#define SPI2_FOSC_64 0b0010
#define SPI2_FOSC_16 0b0001
#define SPI2_FOSC_8 0b1010
#define SPI2_FOSC_4 0b0000
 
typedef struct {
#ifndef SPI2_WRITE_ONLY
char buffer_in[MAXSPIBUF];
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_in_len;
#endif
 
char buffer_out[MAXSPIBUF];
char buffer_out_ind;
char buffer_out_len;
} SPI_DATA;
 
void SPI2_Init(SPI_DATA *data, char speed);
void SPI2_Write(char *msg, unsigned int length);
void SPI2_Write_Repeat(char c, unsigned int length);
#ifndef SPI2_WRITE_ONLY
void SPI2_Recv_Interrupt_Handler(void);
void SPI2_Read(char length);
char SPI2_Buffer_Len(void);
char SPI2_Read_Buffer(char *buffer);
#endif
 
void SPI2_DMA_Init(void);
void SPI2_DMA_Start(unsigned int length, void *TXADDR, void *RXADDR);
 
#endif /* SPI_H */
 
/PIC Projects/PICX_27J13/defines.h
0,0 → 1,140
#ifndef DEFINES_H
#define DEFINES_H
 
#define _XTAL_FREQ 48000000
 
#define UART1_RX_TO_BUFFER
//#define UART1_RX_TO_XBEE
 
#define _DEBUG
 
// <editor-fold defaultstate="collapsed" desc="I2C Addresses">
// HT16K33_ADDRESS 0x70
// L3GD20_ADDRESS 0x6B
// BMP085_I2CADDR 0x77
// TSL2561_ADDR_FLOAT 0x39
// PN532_I2C_ADDRESS 0x24
// LSM303_MAG_ADDRESS 0x1E
// LSM303_ACC_ADDRESS 0x18
// </editor-fold>
 
// <editor-fold defaultstate="expanded" desc="Test Cases">
//#define _TEST_UART
//#define _TEST_I2C_MASTER
//#define _TEST_I2C_SLAVE
//#define _TEST_SPI
#define _TEST_SPI_DMA
//#define _TEST_ADC
//#define _TEST_TIMER1_RTC
//#define _TEST_NFC
//#define _TEST_LUX
//#define _TEST_BMP
//#define _TEST_GYRO
//#define _TEST_ACCEL
//#define _TEST_RTC
//#define _TEST_LED_BACKPACK
//#define _TEST_SSD1306_OLED
//#define _TEST_SSD1331_OLED
//#define _TEST_XBEE
 
//#define _TEST_OLED_CHAR
//#define _TEST_NFC_TO_SSD1306_OLED
//#define _TEST_LUX_TO_CHAR_OLED
//#define _TEST_RTC_TO_LED_BACKPACK_CHAR_OLED
//#define _TEST_AHRS
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Debug Redirection">
#ifdef _DEBUG
#define DBG_PRINT_MAIN UART1_WriteS
#define DBG_PRINT_UART UART1_WriteS
#define DBG_PRINT_I2C UART1_WriteS
#define DBG_PRINT_SPI UART1_WriteS
#define DBG_PRINT_XBEE UART1_WriteS
#define DBG_PRINT_PORTB_INT
#define DBG_PRINT_INT
#define DBG_PRINT_LUX
#define DBG_PRINT_BMP
#else
#define DBG_PRINT_MAIN
#define DBG_PRINT_UART
#define DBG_PRINT_I2C
#define DBG_PRINT_SPI
#define DBG_PRINT_XBEE
#define DBG_PRINT_PORTB_INT
#define DBG_PRINT_INT
#define DBG_PRINT_LUX
#define DBG_PRINT_BMP
#endif
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Pin Allocations">
#define UART1_RX_TRIS TRISCbits.TRISC7
#define UART1_TX_TRIS TRISCbits.TRISC6
 
#define I2C_CLK_TRIS TRISCbits.TRISC3
#define I2C_DAT_TRIS TRISCbits.TRISC4
 
#define LED_BLUE_TRIS TRISCbits.TRISC5
#define LED_BLUE_LAT LATCbits.LATC5
#define LED_RED_TRIS TRISCbits.TRISC2
#define LED_RED_LAT LATCbits.LATC2
 
#define ADC_AN0_TRIS TRISAbits.TRISA0
#define ADC_AN1_TRIS TRISAbits.TRISA1
#define ADC_AN2_TRIS TRISAbits.TRISA2
 
#define XBEE_CTS_TRIS TRISBbits.TRISB0
#define XBEE_CTS_LAT LATBbits.LATB0
#define XBEE_CTS_PORT PORTBbits.RB0
#define XBEE_RTS_TRIS TRISBbits.TRISB1
#define XBEE_RTS_LAT LATBbits.LATB1
 
#define SPI_MOSI_TRIS TRISBbits.TRISB0
#ifndef SPI2_WRITE_ONLY
#define SPI_MISO_TRIS TRISBbits.TRISB0
#endif
#define SPI_CLK_TRIS TRISAbits.TRISA0
#define SPI_DC_SELECT_TRIS TRISAbits.TRISA1
#define SPI_DC_SELECT_LAT LATAbits.LATA1
#define SPI_RESET_TRIS TRISAbits.TRISA2
#define SPI_RESET_LAT LATAbits.LATA2
#define SPI_SLAVE_SELECT_TRIS TRISAbits.TRISA3
#define SPI_SLAVE_SELECT_LAT LATAbits.LATA3
 
#define PARALLEL_RS_TRIS TRISBbits.TRISB7
#define PARALLEL_RS_LAT LATBbits.LATB7
#define PARALLEL_RW_TRIS TRISBbits.TRISB6
#define PARALLEL_RW_LAT LATBbits.LATB6
#define PARALLEL_EN_TRIS TRISBbits.TRISB5
#define PARALLEL_EN_LAT LATBbits.LATB5
#define PARALLEL_D4_TRIS TRISBbits.TRISB4
#define PARALLEL_D4_LAT LATBbits.LATB4
#define PARALLEL_D5_TRIS TRISBbits.TRISB3
#define PARALLEL_D5_LAT LATBbits.LATB3
#define PARALLEL_D6_TRIS TRISBbits.TRISB2
#define PARALLEL_D6_LAT LATBbits.LATB2
#define PARALLEL_D7_TRIS TRISBbits.TRISB1
#define PARALLEL_D7_LAT LATBbits.LATB1
#define PARALLEL_BUSY_TRIS TRISBbits.TRISB1
#define PARALLEL_BUSY_PORT PORTBbits.RB1
 
#define NFC_IRQ_TRIS TRISAbits.TRISA5
#define NFC_IRQ_PORT PORTAbits.RA5
//#define NFC_RESET_TRIS TRISCbits.TRISC2
//#define NFC_RESET_LAT LATCbits.LATC2
 
// PPS bindings (RP Pins)
#define PPS_SPI2_CLK_IN 0 // A0
#define PPS_SPI2_CLK_OUT RPOR0 // A0
#define PPS_SPI2_MOSI RPOR3 // B0
#ifndef SPI2_WRITE_ONLY
#define PPS_SPI2_MISO 3 // NA
#endif
 
//#define PPS_UART2_RX 5
//#define PPS_UART2_TX RPOR6
// </editor-fold>
 
#endif /* DEFINES_H */
 
/PIC Projects/PICX_27J13/funclist
0,0 → 1,25
_I2C_Interrupt_Master: CODE, 67304 0 1764
exp@coeff: MEDIUMCONST, 0 0 64687
_SPI2_DMA_Start: CODE, 71264 0 74
__stringdata: MEDIUMCONST, 64729 0 805
_UART1_WriteS: CODE, 71478 0 64
_I2C_Interrupt_Slave: CODE, 65536 0 1768
_strlen: CODE, 71410 0 68
_SPI2_Init: CODE, 70964 0 120
_font: MEDIUMCONST, 63366 0 1275
_UART1_Recv_Interrupt_Handler: CODE, 70092 0 428
_pn532response_firmwarevers: MEDIUMCONST, 64714 0 8
_main: CODE, 70684 0 142
_numbertable: MEDIUMCONST, 64641 0 10
_pn532ack: MEDIUMCONST, 64722 0 7
_I2C_Process_Send: CODE, 70520 0 164
_I2C_Interrupt_Handler: CODE, 71338 0 72
__initialization: CODE, 71084 0 90
_alphatable: MEDIUMCONST, 64651 0 6
_sprintf: CODE, 71180 0 84
_InterruptHandlerLow: CODE, 24 0 154
_Timer1_Interrupt_Handler: CODE, 71578 0 2
_InterruptHandlerHigh: CODE, 8 0 70956
log@coeff: MEDIUMCONST, 0 0 64714
_SPI2_DMA_Init: CODE, 71542 0 32
Total: 207494
/PIC Projects/PICX_27J13/main.c
0,0 → 1,1701
#include <xc.h>
#include <delays.h>
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "base_INTERRUPTS.h"
#include "base_TIMERS.h"
#include "base_UART.h"
#include "base_I2C.h"
#include "base_SPI.h"
#include "base_ADC.h"
#include "sensor_nfc_PN532.h"
#include "sensor_lux_TSL2561.h"
#include "sensor_temp_BMP085.h"
#include "sensor_gyro_L3G.h"
#include "sensor_accel_LSM303.h"
#include "sensor_rtc_DS3231.h"
#include "display_led_HT16K33.h"
#include "display_oled_ssd1306.h"
#include "display_oled_ssd1331.h"
#include "display_oled_NHD-0216KZW-AB5.h"
#include "comm_xbee.h"
 
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* --------------------------- Configuration Bits --------------------------- */
/* CONFIG1L @ 0x1FFF8 */
#pragma config CFGPLLEN = ON // Enable PLL on startup
#pragma config PLLDIV = 3 // Set PPL prescaler to 3 (to get 4MHz)
#pragma config WDTEN = OFF // Turn off watchdog timer
#pragma config STVREN = OFF // Stack overflow/underflow reset disabled
#pragma config XINST = OFF // Turn off extended instruction set
 
/* CONFIG1H @ 0x1FFF9 */
#pragma config CP0 = OFF // Program memory is not code-protected
 
/* CONFIG2L @ 0x1FFFA */
#pragma config CLKOEC = OFF // CLKO output disabled on RA6 pin
#pragma config SOSCSEL = LOW // Low Power T1OSC/SOSC circuit selected
#pragma config IESO = ON // Internal external oscillator switch over disabled
#pragma config OSC = HSPLL // Use external oscillator (101)
#pragma config FCMEN = OFF // Fail-safe clock monitor disabled
 
/* CONFIG2H @ 0x1FFFB */
#pragma config WDTPS = 1 // Watchdog postscaler of 1:1
 
/* CONFIG3L @ 0x1FFFC */
#pragma config RTCOSC = T1OSCREF // RTCC uses T1OSC/T1CKI
#pragma config DSBOREN = ON // Deep sleep BOR enabled
#pragma config DSWDTPS = M2 // Deep sleep watchdog postscaler of 1:2 (36m)
#pragma config DSWDTEN = OFF // Deep sleep watchdog timer disabled
#pragma config DSWDTOSC = INTOSCREF // DSWDT clock select uses INTRC
 
/* CONFIG3H @ 0x1FFFD */
#pragma config PLLSEL = PLL96 // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
#pragma config ADCSEL = BIT12 // 12-bit ADC
#pragma config MSSP7B_EN = MSK7 // 7-bit address masking mode
#pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed
 
/* CONFIG4L @ 0x1FFFE */
#pragma config WPCFG = ON // Configuration words page protected
 
/* CONFIG4H @ 0x1FFFF */
#pragma config WPEND = PAGE_WPFP // Pages WPFP<6:0> through Configuration Words erase/write protected
#pragma config WPDIS = OFF // WPFP<6:0>/WPEND region ignored
/* -------------------------------------------------------------------------- */
// </editor-fold>
 
#if defined(_TEST_UART)
// <editor-fold defaultstate="collapsed" desc="_TEST_UART">
int main() {
char buffer[100];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
char output[] = "\r\nBegin Program\r\n";
DBG_PRINT_MAIN(output, strlen(output));
 
while (1) {
char length = UART1_Read_Buffer((char *) buffer);
if (length != 0) {
UART1_WriteS(buffer, length);
}
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_I2C_MASTER)
// <editor-fold defaultstate="collapsed" desc="_TEST_I2C_MASTER">
void main(void) {
char length = 0;
char result = 0;
char buffer[100];
char output[64];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
I2C_DATA i2c_data;
I2C_Init(&i2c_data); // Initialize the I2C handler code
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
while (1) {
buffer[0] = 0x8;
 
I2C_Master_Send(0x24, 1, buffer);
do {
result = I2C_Get_Status();
} while (!result);
sprintf(output, "S: %X ", result);
DBG_PRINT_MAIN(output, strlen(output));
 
I2C_Master_Recv(0x24, 2);
do {
result = I2C_Get_Status();
} while (!result);
sprintf(output, "S: %X ", result);
DBG_PRINT_MAIN(output, strlen(output));
length = I2C_Read_Buffer(buffer);
sprintf(output, "L: %d D: ", length);
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < length; i++) {
sprintf(output, "%c ", buffer[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
I2C_Master_Restart(0x30, 0xBB, 2);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
sprintf(output, "S: %X ", result);
DBG_PRINT_MAIN(output, strlen(output));
length = I2C_Read_Buffer(buffer);
sprintf(output, "L: %d D: ", length);
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < length; i++) {
sprintf(output, "%c ", buffer[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_I2C_SLAVE)
// <editor-fold defaultstate="collapsed" desc="_TEST_I2C_SLAVE">
void main(void) {
char length = 0;
char result = 0;
char buffer[100];
char output[64];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
I2C_DATA i2c_data;
I2C_Init(&i2c_data); // Initialize the I2C handler code
 
I2C_Configure_Slave(0x24);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
while (1) {
 
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
sprintf(output, "S: %X ", result);
DBG_PRINT_MAIN(output, strlen(output));
length = I2C_Read_Buffer(buffer);
sprintf(output, "L: %d D: ", length);
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < length; i++) {
sprintf(output, "%X ", buffer[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_SPI)
// <editor-fold defaultstate="collapsed" desc="_TEST_SPI">
void main(void) {
char length = 0;
char result = 0;
char buffer[100];
char output[64];
char test[8] = "ASDF123";
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_8); // Initialize the SPI module
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
while (1) {
 
SPI2_Write(test, 7);
while (result != 7) {
length = SPI2_Read_Buffer(buffer);
if (length) {
result += length;
}
}
result = 0;
 
for (char i = 0; i < result; i++) {
sprintf(output, "%X ", buffer[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_SPI_DMA)
// <editor-fold defaultstate="collapsed" desc="_TEST_SPI_DMA">
void main(void) {
char buffer[42];
char buffer2;
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_4); // Initialize the SPI module
SPI2_DMA_Init();
 
// Interrupt_Init(); // Initialize the interrupt priorities
// Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
// for (char i = 0; i < 42; i++) {
// buffer[i] = i;
// }
while (1) {
SPI2_DMA_Start(42, &buffer, &buffer2);
 
__delay_ms(1);
}
}
// </editor-fold>
#elif defined(_TEST_ADC)
// <editor-fold defaultstate="collapsed" desc="_TEST_ADC">
void main(void) {
unsigned int x, y, z;
char buffer[60];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_8); // Initialize the SPI module
SSD1306_DATA ssd1306_data;
SSD1306_Init(&ssd1306_data); // Initialize the SSD1331 OLED display (uses SPI2)
ADC_DATA adc_data;
ADC_Init(&adc_data, ADC_TAD_20, ADC_FOSC_64_);
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(buffer, "\r\nBegin Program\r\n");
SSD1306_Write_String(buffer, strlen(buffer));
 
memset(buffer, 0, 60);
SSD1306_Clear_Display();
SSD1306_Display();
 
while (1) {
// ADC read from AN0-AN2 and prints to display
ADC_Start(ADC_CHANNEL_AN2);
// SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 0);
while (!ADC_Get_Result(&x));
sprintf(buffer, "X: %u", x);
SSD1306_Write_String(buffer, strlen(buffer));
SSD1306_Display();
 
ADC_Start(ADC_CHANNEL_AN1);
// SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 8);
while (!ADC_Get_Result(&y));
sprintf(buffer, "Y: %u", y);
SSD1306_Write_String(buffer, strlen(buffer));
SSD1306_Display();
 
ADC_Start(ADC_CHANNEL_AN0);
// SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 16);
while (!ADC_Get_Result(&z));
sprintf(buffer, "Z: %u", z);
SSD1306_Write_String(buffer, strlen(buffer));
SSD1306_Display();
}
}
// </editor-fold>
#elif defined(_TEST_TIMER1_RTC)
// <editor-fold defaultstate="collapsed" desc="_TEST_TIMER1_RTC">
void main(void) {
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
Timer1_Init();
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
LED_BLUE_TRIS = 0;
LED_RED_TRIS = 0;
 
Timer1_Enable();
 
while (1) {
 
}
}
// </editor-fold>
#elif defined(_TEST_NFC)
// <editor-fold defaultstate="collapsed" desc="_TEST_NFC">
void main(void) {
char length = 0;
char output[64];
 
// NFC stuff
NFC_FIRMWARE_VERSION version;
NFC_TargetDataMiFare cardData[2];
NFC_TargetDataMiFare cardData_prev[2];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
I2C_DATA i2c_data;
I2C_Init(&i2c_data); // Initialize the I2C handler code
NFC_DATA nfc_data;
NFC_Init(&nfc_data); // Initialize the NFC chip (uses I2C)
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
version = NFC_Get_Firmware_Version();
while (!version.IC) {
sprintf(output, "Waiting for NFC board..\r\n");
DBG_PRINT_MAIN(output, strlen(output));
Delay10KTCYx(3);
version = NFC_Get_Firmware_Version();
}
sprintf(output, "Found chip PN5%X\r\n", version.IC);
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Firmware ver. %d.%d\r\n", version.Ver, version.Rev);
DBG_PRINT_MAIN(output, strlen(output));
NFC_SAMConfig();
 
memset(cardData, 0, 24);
 
while (1) {
 
// // This query will hang until the NFC chip replies (card detected)
// length = NFC_readPassiveTargetID(cardData);
// if (length) {
// DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[0].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// if (length == 2) {
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[1].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// }
// }
 
// // This query will hang until the NFC chip replies (card detected)
// length = NFC_readPassiveTargetID(cardData);
// if (length) {
// DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[0].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// if (length == 2) {
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[1].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// }
// }
 
// This query will not wait for a detection before responding
length = NFC_Poll_Targets(1, 1, cardData);
if (!length) {
memset(cardData_prev, 0, 24);
} else if (length == 1) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
sprintf(output, "UID: ");
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < cardData[0].NFCID_LEN; i++) {
sprintf(output, "%02X ", cardData[0].NFCID[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
}
memset(&cardData_prev[1], 0, 12);
} else if (length == 2) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// First card matched
sprintf(output, "UID2: ");
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < cardData[1].NFCID_LEN; i++) {
sprintf(output, "%02X ", cardData[1].NFCID[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Second card matched
sprintf(output, "UID1: ");
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < cardData[0].NFCID_LEN; i++) {
sprintf(output, "%02X ", cardData[0].NFCID[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
// No match
sprintf(output, "UID1: ");
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < cardData[0].NFCID_LEN; i++) {
sprintf(output, "%02X ", cardData[0].NFCID[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
sprintf(output, "UID2: ");
DBG_PRINT_MAIN(output, strlen(output));
for (char i = 0; i < cardData[1].NFCID_LEN; i++) {
sprintf(output, "%02X ", cardData[1].NFCID[i]);
DBG_PRINT_MAIN(output, strlen(output));
}
sprintf(output, "\r\n");
DBG_PRINT_MAIN(output, strlen(output));
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
}
}
}
}
// </editor-fold>
#elif defined(_TEST_LUX)
// <editor-fold defaultstate="collapsed" desc="_TEST_LUX">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
TSL2561_DATA lux_data;
LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
LUX_Begin();
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
// LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
LUX_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
while (1) {
unsigned long lum = LUX_Get_Full_Luminosity();
unsigned int ir = lum >> 16;
unsigned int full = lum & 0xFFFF;
sprintf(output, "IR: %d\r\n", ir);
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Visible: %d\r\n", full - ir);
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Full: %d\r\n", full);
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Lux: %ld\r\n\r\n", LUX_Calculate_Lux(full, ir));
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_BMP)
// <editor-fold defaultstate="collapsed" desc="_TEST_BMP">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
BMP085_DATA bmp_data;
BMP_Init(&bmp_data);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
BMP_Begin(BMP085_ULTRAHIGHRES);
 
BMP_Read_Temperature();
BMP_Read_Pressure();
BMP_Read_Altitude(101592);
 
while (1) {
sprintf(output, "Temp: %f *C\r\n", BMP_Read_Temperature());
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Pressure: %ld Pa\r\n", BMP_Read_Pressure());
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "Altitude: %f meters\r\n", BMP_Read_Altitude(101592));
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_GYRO)
// <editor-fold defaultstate="collapsed" desc="_TEST_GYRO">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
L3G_DATA gyro_data;
L3G_Init(&gyro_data, L3GD20_DEVICE, L3G_SA0_HIGH);
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
L3G_Begin();
int x,y,z;
while (1) {
L3G_Read(&x, &y, &z);
sprintf(output, "X: %d Y: %d Z: %d\r\n", x, y, z);
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(100);
}
}
// </editor-fold>
#elif defined(_TEST_ACCEL)
// <editor-fold defaultstate="collapsed" desc="_TEST_ACCEL">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
LSM303_DATA acc_data;
LSM303_Init(&acc_data, LSM303DLHC_DEVICE, ACC_ADDRESS_SA0_A_LOW);
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
LSM303_Begin();
int a_x, a_y, a_z, m_x, m_y, m_z;
while (1) {
LSM303_Read_Acc(&a_x, &a_y, &a_z);
LSM303_Read_Mag(&m_x, &m_y, &m_z);
sprintf(output, "A - X: %d Y: %d Z: %d\r\n", a_x, a_y, a_z);
DBG_PRINT_MAIN(output, strlen(output));
sprintf(output, "M - X: %d Y: %d Z: %d\r\n", m_x, m_y, m_z);
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(100);
}
}
// </editor-fold>
#elif defined(_TEST_RTC)
// <editor-fold defaultstate="collapsed" desc="_TEST_RTC">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
DS3231_Begin();
// Sec, Min, Hour, DOW, Day, Month, Year, Mil Time, AM/PM
DS3231_Set_Time(00, 59, 7, 5, 18, 1, 13, 0, 0);
 
char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
while (1) {
DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
sprintf(output, "%02d:%02d:%02d %s %s - %d/%d/%d (%d)\r\n", hour, min, sec, (h_am_pm) ? "PM" : "AM",
(h_mil) ? "24H" : "12H", month, date, year, day);
DBG_PRINT_MAIN(output, strlen(output));
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_LED_BACKPACK)
// <editor-fold defaultstate="collapsed" desc="_TEST_LED_BACKPACK">
void main(void) {
unsigned int counter = 0;
char output[64];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
I2C_DATA i2c_data;
I2C_Init(&i2c_data); // Initialize the I2C handler code
LED_DATA led_data;
LED_Init(&led_data); // Initialize the LED backpack (uses I2C);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
LED_Start();
LED_Write_Digit_Num(0, 1, 1);
LED_Write_Digit_Num(1, 2, 0);
LED_Write_Digit_Num(2, 3, 0);
LED_Write_Digit_Num(3, 4, 0);
LED_Write_Display();
for (char i = 0; i < 15; i++) {
LED_Set_Brightness(15 - i);
Delay10KTCYx(100);
}
for (char i = 0; i < 15; i++) {
LED_Set_Brightness(i);
Delay10KTCYx(100);
}
LED_Blink_Rate(HT16K33_BLINK_OFF);
 
while (1) {
LED_Write_Num(counter);
counter++;
if (counter > 9999)
counter = 0;
 
// Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_SSD1306_OLED)
// <editor-fold defaultstate="collapsed" desc="_TEST_SDS1306_OLED">
void main(void) {
char output[64];
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_4); // Initialize the SPI module
SSD1306_DATA ssd1306_data;
SSD1306_Init(&ssd1306_data); // Initialize the OLED code
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
 
SSD1306_Display(); // Show splashscreen
 
while (1) {
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawLine();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawCircle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Fill_Circle(SSD1306_LCDWIDTH / 2, SSD1306_LCDHEIGHT / 2, 10, SSD1306_WHITE);
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawRoundRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillRoundRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawTriangle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillTriangle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawChar();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Set_Text_Size(1);
SSD1306_Set_Text_Color(SSD1306_WHITE);
SSD1306_Set_Cursor(0, 0);
sprintf(output, "Hello World!\n");
SSD1306_Write_String(output, strlen(output));
// SSD1306_Set_Text_Color_BG(BLACK, WHITE);
unsigned int i = 65535;
sprintf(output, "%u %d\n", i, i);
SSD1306_Write_String(output, strlen(output));
// SSD1306_Set_Text_Size(2);
// SSD1306_Set_Text_Color(WHITE);
unsigned long l = 0xDEADBEEF;
sprintf(output, "0x%lX", (long) l);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
 
// SSD1306_Clear_Display();
// SSD1306_Set_Rotation(0);
// SSD1306_Set_Text_Size(1);
// SSD1306_Set_Text_Color(SSD1306_WHITE);
// SSD1306_Set_Cursor(0, 0);
// SSD1306_Write_String("%u", i);
// i++;
// SSD1306_Display();
 
}
}
// </editor-fold>
#elif defined(_TEST_SSD1331_OLED)
// <editor-fold defaultstate="collapsed" desc="_TEST_SSD1331_OLED">
void main(void) {
char output[128];
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_64); // Initialize the SPI module
SSD1331_DATA ssd1331_data;
SSD1331_Init(&ssd1331_data); // Initialize the OLED code
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
SSD1331_Begin();
 
while (1) {
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_Pattern();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Clear_Display();
SSD1331_Set_Rotation(0);
SSD1331_Set_Cursor(0, 0);
sprintf(output, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabit adipiscing ante sed nibh tincidunt feugiat.");
SSD1331_Write_String(output, strlen(output));
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Clear_Display();
// SSD1331_Set_Rotation(3);
// SSD1331_Set_Cursor(0, 0);
// SSD1331_Write_String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_DrawLines(SSD1331_YELLOW);
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Test_DrawLines(SSD1331_BLUE);
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_DrawRect(SSD1331_GREEN);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(1);
SSD1331_Test_DrawRect(SSD1331_RED);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(2);
SSD1331_Test_DrawRect(SSD1331_BLUE);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Test_DrawRect(SSD1331_YELLOW);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN);
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Clear_Display();
SSD1331_Test_FillCircle(10, SSD1331_BLUE);
SSD1331_Test_DrawCircle(10, SSD1331_WHITE);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Clear_Display();
SSD1331_Test_FillCircle(10, SSD1331_MAGENTA);
SSD1331_Test_DrawCircle(10, SSD1331_YELLOW);
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_DrawTria();
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Test_DrawTria();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_DrawRoundRect();
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(3);
SSD1331_Test_DrawRoundRect();
 
// SSD1331_Clear_Display();
// SSD1331_Set_Rotation(3);
// SSD1331_Set_Cursor(0,0);
// SSD1331_Set_Text_Color_BG(SSD1331_WHITE, SSD1331_BLACK);
// SSD1331_Write_String("%u", i);
// i++;
}
}
// </editor-fold>
#elif defined(_TEST_OLED_CHAR)
// <editor-fold defaultstate="collapsed" desc="_TEST_OLED_CHAR">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
// UART1_Init();
OLED_CHAR_DATA oled_data;
NHD_Init(&oled_data);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
NHD_Begin(16, 2);
 
sprintf(output, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do");
NHD_Write_String(output, strlen(output));
NHD_Set_Cursor(0,1);
sprintf(output, "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e");
NHD_Write_String(output, strlen(output));
 
while (1) {
Delay10KTCYx(150);
NHD_Scroll_Display_Left();
}
}
// </editor-fold>
#elif defined(_TEST_NFC_TO_SSD1306_OLED)
// <editor-fold defaultstate="collapsed" desc="_TEST_NFC_TO_SSD1306_OLED">
void main(void) {
char output[64];
 
// NFC stuff
NFC_FIRMWARE_VERSION version;
NFC_TargetDataMiFare cardData[2];
NFC_TargetDataMiFare cardData_prev[2];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
NFC_DATA nfc_data;
NFC_Init(&nfc_data);
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_4);
SSD1306_DATA ssd1306_data;
SSD1306_Init(&ssd1306_data);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
memset(cardData, 0, 24);
memset(cardData_prev, 0, 24);
SSD1306_Clear_Display();
SSD1306_Set_Rotation(0);
SSD1306_Set_Cursor(0, 0);
 
version = NFC_Get_Firmware_Version();
while (!version.IC) {
sprintf(output, "Waiting for NFC board..\n");
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
Delay10KTCYx(255);
version = NFC_Get_Firmware_Version();
}
sprintf(output, "PN5%X Ver. %d.%d\n", version.IC, version.Ver, version.Rev);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
NFC_SAMConfig();
 
while (1) {
 
// This query will not wait for a detection before responding
char length = NFC_Poll_Targets(1, 1, cardData);
if (!length) {
memset(cardData_prev, 0, 24);
} else if (length == 1) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
}
memset(&cardData_prev[1], 0, 12);
} else if (length == 2) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// First card matched
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Second card matched
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
// No match
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
}
}
}
}
// </editor-fold>
#elif defined(_TEST_LUX_TO_CHAR_OLED)
// <editor-fold defaultstate="collapsed" desc="_TEST_LUX_TO_CHAR_OLED">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
OLED_CHAR_DATA oled_data;
NHD_Init(&oled_data);
TSL2561_DATA lux_data;
LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
NHD_Begin(16, 2);
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
// LUX_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
while (1) {
unsigned long lum = LUX_Get_Full_Luminosity();
unsigned int ir = lum >> 16;
unsigned int full = lum & 0xFFFF;
NHD_Set_Cursor(0, 0);
sprintf(output, "I: %d ", ir);
NHD_Write_String(output, strlen(output));
sprintf(output, "V: %d ", full - ir);
NHD_Write_String(output, strlen(output));
NHD_Set_Cursor(0, 1);
sprintf(output, "Lux: %ld ", LUX_Calculate_Lux(full, ir));
NHD_Write_String(output, strlen(output));
 
// Delay10KTCYx(100);
}
}
// </editor-fold>
#elif defined(_TEST_RTC_TO_LED_BACKPACK_CHAR_OLED)
// <editor-fold defaultstate="collapsed" desc="_TEST_RTC_TO_LED_BACKPACK_CHAR_OLED">
void main(void) {
char output[64];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
LED_DATA led_data;
LED_Init(&led_data);
OLED_CHAR_DATA oled_data;
NHD_Init(&oled_data);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
LED_Start();
LED_Draw_Colon(1);
NHD_Begin(16, 2);
DS3231_Begin();
 
char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
int time;
while (1) {
DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
time = hour * 100 + min;
LED_Write_Num(time);
 
NHD_Set_Cursor(0, 0);
sprintf(output, "%02d:%02d:%02d %s", hour, min, sec, h_am_pm ? "PM" : "AM");
NHD_Write_String(output, strlen(output));
NHD_Set_Cursor(12, 0);
switch (day) {
case 1:
sprintf(output, "*MON");
break;
case 2:
sprintf(output, "*TUE");
break;
case 3:
sprintf(output, "*WED");
break;
case 4:
sprintf(output, "*THU");
break;
case 5:
sprintf(output, "*FRI");
break;
case 6:
sprintf(output, "*SAT");
break;
case 7:
sprintf(output, "*SUN");
break;
}
NHD_Write_String(output, strlen(output));
 
NHD_Set_Cursor(0, 1);
switch (month) {
case 1:
sprintf(output, "January");
break;
case 2:
sprintf(output, "February");
break;
case 3:
sprintf(output, "March");
break;
case 4:
sprintf(output, "April");
break;
case 5:
sprintf(output, "May");
break;
case 6:
sprintf(output, "June");
break;
case 7:
sprintf(output, "July");
break;
case 8:
sprintf(output, "August");
break;
case 9:
sprintf(output, "September");
break;
case 10:
sprintf(output, "October");
break;
case 11:
sprintf(output, "November");
break;
case 12:
sprintf(output, "December");
break;
}
NHD_Write_String(output, strlen(output));
 
sprintf(output, " %d 20%d", date, year);
NHD_Write_String(output, strlen(output));
 
Delay10KTCYx(100);
}
}
// </editor-fold>
#elif defined(_TEST_AHRS)
// <editor-fold defaultstate="collapsed" desc="_TEST_AHRS">
void main(void) {
char output[64];
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data);
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
L3G_DATA gyro_data;
L3G_Init(&gyro_data, L3GD20_DEVICE, L3G_SA0_HIGH);
LSM303_DATA acc_data;
LSM303_Init(&acc_data, LSM303DLHC_DEVICE, ACC_ADDRESS_SA0_A_LOW);
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
sprintf(output, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(output, strlen(output));
 
L3G_Begin();
LSM303_Begin();
int a_x, a_y, a_z, m_x, m_y, m_z, g_x, g_y, g_z;
while (1) {
L3G_Read(&g_x, &g_y, &g_z);
LSM303_Read_Acc(&a_x, &a_y, &a_z);
LSM303_Read_Mag(&m_x, &m_y, &m_z);
sprintf(output, "GAM:%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",
g_x,g_y,g_z,a_x,a_y,a_z,m_x,m_y,m_z);
DBG_PRINT_MAIN(output, strlen(output));
 
Delay10KTCYx(255);
}
}
// </editor-fold>
#elif defined(_TEST_XBEE)
// <editor-fold defaultstate="collapsed" desc="_TEST_XBEE">
void main(void) {
char buffer[100];
 
XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
XBEE_RX_DATA_TX_STATUS_FRAME *rx_tx_status_frame;
XBEE_RX_REMOTE_AT_COMMAND_FRAME *rx_remote_at_cmd_frame;
XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME *rx_node_ident_frame;
XBEE_RX_MODEM_STATUS_FRAME *rx_modem_status_frame;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART_DATA uart_data;
UART1_Init(&uart_data); // Initialize the UART handler code
XBEE_DATA xbee_data;
XBee_Init(&xbee_data);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
 
sprintf(buffer, "\r\nBegin Program\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
 
while (1) {
 
//#define _ROUTER
#define _COORDINATOR
 
#ifdef _ROUTER
XBEE_TX_DATA_PACKET_FRAME *tx_data_frame;
tx_data_frame = (void *) buffer;
tx_data_frame->frame_type = XBEE_TX_DATA_PACKET;
tx_data_frame->frame_id = 1;
tx_data_frame->destination_64.UPPER_32.long_value = 0x00000000;
tx_data_frame->destination_64.LOWER_32.long_value = 0x00000000;
tx_data_frame->destination_16.INT_16.int_value = 0xFEFF;
tx_data_frame->broadcast_radius = 0;
tx_data_frame->options = 0;
tx_data_frame->data[0] = 0x54;
tx_data_frame->data[1] = 0x78;
tx_data_frame->data[2] = 0x32;
tx_data_frame->data[3] = 0x43;
tx_data_frame->data[4] = 0x6F;
tx_data_frame->data[5] = 0x6F;
tx_data_frame->data[6] = 0x72;
tx_data_frame->data[7] = 0x11;
XBee_Process_Transmit_Frame(buffer, XBEE_TX_DATA_PACKET_FRAME_SIZE + 8);
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
#endif
 
#ifdef _COORDINATOR
int length = XBee_Get_Received_Frame(buffer);
if (length != 0) {
switch (*(char *) buffer) {
case XBEE_RX_AT_COMMAND_RESPONSE:
sprintf(buffer, "XBEE: parsing recieved AT command response frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_at_cmd_response_frame = (void *) buffer;
// DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
// DBG_PRINT_MAIN("AT Command: %c%c Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
// rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
// DBG_PRINT_MAIN("Command Data: ");
for (int i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
// DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
}
// DBG_PRINT_MAIN("\r\n");
}
break;
case XBEE_RX_DATA_PACKET:
sprintf(buffer, "XBEE: parsing recieved data recieved frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_data_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_data_frame->source_64));
XBee_Convert_Endian_16(&(rx_data_frame->source_16));
// DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
// rx_data_frame->source_64.UPPER_32.long_value, \\
// rx_data_frame->source_64.LOWER_32.long_value, \\
// rx_data_frame->source_16.INT_16.int_value, \\
// rx_data_frame->recieve_options);
// DBG_PRINT_MAIN("Data: ");
for (int i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
// DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
}
// DBG_PRINT_MAIN("\r\n");
break;
case XBEE_RX_DATA_TX_STATUS:
sprintf(buffer, "XBEE: parsing recieved TX status frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_tx_status_frame = (void *) buffer;
XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
// DBG_PRINT_MAIN("Frame ID: %u Destination 16: %04X\r\n", \\
// rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
// DBG_PRINT_MAIN("Transmit Retry Count: %02X Delivery Status: %02X Discovery Status: %02X\r\n", \\
// rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
// rx_tx_status_frame->discovery_status);
break;
case XBEE_RX_IO_DATA_SAMPLE:
sprintf(buffer, "XBEE: parsing recieved IO data sample frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_EXPLICIT_COMMAND:
sprintf(buffer, "XBEE: parsing recieved explicit command frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
sprintf(buffer, "XBEE: parsing recieved remote AT command frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_remote_at_cmd_frame = (void *) buffer;
break;
case XBEE_RX_ROUTE_RECORD:
sprintf(buffer, "XBEE: parsing recieved route record frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
case XBEE_RX_NODE_IDENTIFICATION:
sprintf(buffer, "XBEE: parsing recieved node identification frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_node_ident_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
// DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
// rx_node_ident_frame->source_64.UPPER_32.long_value, \\
// rx_node_ident_frame->source_64.LOWER_32.long_value, \\
// rx_node_ident_frame->source_16.INT_16.int_value, \\
// rx_node_ident_frame->recieve_options);
// DBG_PRINT_MAIN("Remote 64: %08lX %08lX Remote 16: %04X Parent 16: %04X\r\n", \\
// rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
// rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
// rx_node_ident_frame->remote_16.INT_16.int_value, \\
// rx_node_ident_frame->parent_16.INT_16.int_value);
// DBG_PRINT_MAIN("Device Type: %02X Source Event: %02X\r\n", \\
// rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
break;
case XBEE_RX_FRAME_MODEM_STATUS:
sprintf(buffer, "XBEE: parsing recieved modem status frame\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
rx_modem_status_frame = (void *) buffer;
// DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
break;
default:
sprintf(buffer, "??\r\n");
DBG_PRINT_MAIN(buffer, strlen(buffer));
break;
}
}
#endif
 
}
}
// </editor-fold>
#else
int main() {
char output[64];
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
// NFC stuff
NFC_FIRMWARE_VERSION version;
NFC_TargetDataMiFare cardData[2];
NFC_TargetDataMiFare cardData_prev[2];
 
I2C_DATA i2c_data;
I2C_Init(&i2c_data);
LED_DATA led_data;
LED_Init(&led_data);
OLED_CHAR_DATA oled_data;
NHD_Init(&oled_data);
TSL2561_DATA lux_data;
LUX_Init(&lux_data, TSL2561_ADDR_FLOAT);
NFC_DATA nfc_data;
NFC_Init(&nfc_data);
SPI_DATA spi_data;
SPI2_Init(&spi_data, SPI2_FOSC_4);
SSD1306_DATA ssd1306_data;
SSD1306_Init(&ssd1306_data);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Init(); // Initialize the interrupt priorities
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
 
LED_Start();
LED_Draw_Colon(1);
NHD_Begin(16, 2);
DS3231_Begin();
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
// LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
LUX_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
memset(cardData, 0, 24);
memset(cardData_prev, 0, 24);
SSD1306_Clear_Display();
SSD1306_Set_Rotation(0);
SSD1306_Set_Cursor(0, 0);
char sec, min, hour, day, date, month, year, h_mil, h_am_pm;
int time;
 
version = NFC_Get_Firmware_Version();
while (!version.IC) {
sprintf(output, "Waiting for NFC board..\n");
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
Delay10KTCYx(255);
version = NFC_Get_Firmware_Version();
}
sprintf(output, "PN5%X Ver. %d.%d\n", version.IC, version.Ver, version.Rev);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
NFC_SAMConfig();
 
while (1) {
// Time to LED backpack
DS3231_Get_Time(&sec, &min, &hour, &day, &date, &month, &year, &h_mil, &h_am_pm);
time = hour * 100 + min;
LED_Write_Num(time);
 
// Lux to Character OLED
unsigned long lum = LUX_Get_Full_Luminosity();
unsigned int ir = lum >> 16;
unsigned int full = lum & 0xFFFF;
NHD_Set_Cursor(0, 0);
sprintf(output, "I: %d ", ir);
NHD_Write_String(output, strlen(output));
sprintf(output, "V: %d ", full - ir);
NHD_Write_String(output, strlen(output));
NHD_Set_Cursor(0, 1);
sprintf(output, "Lux: %ld ", LUX_Calculate_Lux(full, ir));
NHD_Write_String(output, strlen(output));
 
// NFC Query
char length = NFC_Poll_Targets(1, 1, cardData);
if (!length) {
memset(cardData_prev, 0, 24);
} else if (length == 1) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
}
memset(&cardData_prev[1], 0, 12);
} else if (length == 2) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// First card matched
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Second card matched
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
// No match
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
sprintf(output, "UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Write_String(output, strlen(output));
SSD1306_Display();
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
}
}
 
 
Delay10KTCYx(100);
}
}
#endif
/PIC Projects/PICX_27J13/sensor_rtc_DS3231.c
0,0 → 1,114
#include "defines.h"
#include "sensor_rtc_DS3231.h"
#include "base_I2C.h"
 
void DS3231_Begin() {
char reg[3];
reg[0] = DS3231_CONTROL;
/* Control Register (0x0E)
* Bit 7 - !EOSC
* Bit 6 - BBSQW
* Bit 5 - CONV
* Bit 4 - RS2
* Bit 3 - RS1
* Bit 2 - INTCN
* Bit 1 - A2IE
* Bit 0 - A1IE
*/
reg[1] = 0x04;
 
/* Control Register 2 (0x0F)
* Bit 3 = EN32kHZ
*/
reg[2] = 0x00;
 
// Set the configuration registers
I2C_Master_Send(DS3231_ADDRESS, 3, reg);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
char DS3231_Get_Status(void) {
/* Status Register (0x0F)
* Bit 7 - OSF
* Bit 3 - EN32kHz
* Bit 2 - BSY
* Bit 1 - A2F
* Bit 0 - A1F
*/
char value;
I2C_Master_Restart(DS3231_ADDRESS, 0x0F, 1);
char result;
do {
result = I2C_Get_Status();
} while (!result);
I2C_Read_Buffer(&value);
return value;
}
 
void DS3231_Set_Time(char sec, char min, char hour, char day, char date,
char month, char year, char h_mil, char h_am_pm) {
 
// Format the data in a way that the chip expects
char output[8];
output[0] = DS3231_SECONDS;
output[1] = ((sec / 10) << 4) | (sec % 10);
output[2] = ((min / 10) << 4) | (min % 10);
output[3] = ((hour / 10) << 4) | (hour % 10);
if (!h_mil) {
output[3] |= (h_am_pm) ? 0x60 : 0x40;
}
output[4] = day;
output[5] = ((date / 10) << 4) | (date % 10);
output[6] = ((month / 10) << 4) | (month % 10);
output[7] = ((year / 10) << 4) | (year % 10);
 
// Check the status to make sure that it isnt currently busy
char status = DS3231_Get_Status();
while (status & 0x04)
status = DS3231_Get_Status();
 
// Write the data to the chip
I2C_Master_Send(DS3231_ADDRESS, 8, output);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
void DS3231_Get_Time(char *sec, char *min, char *hour, char *day, char *date,
char *month, char *year, char *h_mil, char *h_am_pm) {
 
// Check the status to make sure that it isnt currently busy
char status = DS3231_Get_Status();
while (status & 0x04)
status = DS3231_Get_Status();
 
// Request time data from the chip
char input[7];
I2C_Master_Restart(DS3231_ADDRESS, 0x00, 7);
char result;
do {
result = I2C_Get_Status();
} while (!result);
I2C_Read_Buffer(input);
 
// Parse BCD format into decimal and return
*sec = ((input[0] >> 4) * 10) + (input[0] & 0x0F);
*min = ((input[1] >> 4) * 10) + (input[1] & 0x0F);
if (input[2] & 0x40) {
*h_mil = 0;
*h_am_pm = (input[2] & 0x20) ? 1 : 0;
*hour = (((input[2] >> 4) & 0x01) * 10) + (input[2] & 0x0F);
} else {
*h_mil = 1;
*hour = ((input[2] >> 4) * 10) + (input[2] & 0x0F);
}
*day = input[3];
*date = ((input[4] >> 4) * 10) + (input[4] & 0x0F);
*month = ((input[5] >> 4) * 10) + (input[5] & 0x0F);
*year = ((input[6] >> 4) * 10) + (input[6] & 0x0F);
}
/PIC Projects/PICX_27J13/sensor_rtc_DS3231.h
0,0 → 1,40
#ifndef RTC_DS3231_H
#define RTC_DS3231_H
 
#define DS3231_ADDRESS 0x68
 
#define DS3231_SECONDS 0x00
#define DS3231_MINUTES 0x01
#define DS3231_HOUR 0x02
#define DS3231_DAY 0x03
#define DS3231_DATE 0x04
#define DS3231_MONTH 0x05
#define DS3231_YEAR 0x06
 
#define DS3231_ALARM1_SECONDS 0x07
#define DS3231_ALARM1_MINUTES 0x08
#define DS3231_ALARM1_HOUR 0x09
#define DS3231_ALARM1_DAY_DATE 0x0A
 
#define DS3231_ALARM2_MINUTES 0x0B
#define DS3231_ALARM2_HOUR 0x0C
#define DS3231_ALARM2_DAY_DATE 0x0D
 
#define DS3231_CONTROL 0x0E
#define DS3231_STATUS 0x0F
 
void DS3231_Begin(void);
 
char DS3231_Get_Status(void);
 
void DS3231_Set_Time(char sec, char min, char hour, char day, char date,
char month, char year, char h_mil, char h_am_pm);
 
void DS3231_Get_Time(char *sec, char *min, char *hour, char *day, char *date,
char *month, char *year, char *h_mil, char *h_am_pm);
 
//void DS3231_Set_Alarm1(char sec, char min, char hour, char date, bit mil, bit am_pm, bit dt_dy);
//void DS3231_Set_Alarm2(char min, char hour, char date, bit mil, bit am_pm, bit dt_dy);
 
#endif
 
/PIC Projects/PICX_27J13/sensor_accel_LSM303.c
0,0 → 1,108
#include "defines.h"
#include "sensor_accel_LSM303.h"
#include "base_I2C.h"
 
static LSM303_DATA *lsm303_data_p;
 
void LSM303_Init(LSM303_DATA* data, char device, char sa0) {
lsm303_data_p = data;
lsm303_data_p->device = device;
switch (device) {
case LSM303DLH_DEVICE:
case LSM303DLM_DEVICE:
if (sa0 == LSM303_SA0_A_LOW)
lsm303_data_p->acc_address = ACC_ADDRESS_SA0_A_LOW;
else
lsm303_data_p->acc_address = ACC_ADDRESS_SA0_A_HIGH;
break;
case LSM303DLHC_DEVICE:
lsm303_data_p->acc_address = ACC_ADDRESS_SA0_A_HIGH;
break;
default:
break;
}
}
 
void LSM303_Begin() {
// Enable Accelerometer
// 0x27 = 0b00100111
// Normal power mode, all axes enabled
LSM303_Write_A_Reg(LSM303_CTRL_REG1_A, 0x27);
// Enable Magnetometer
// 0x00 = 0b00000000
// Continuous conversion mode
LSM303_Write_M_Reg(LSM303_MR_REG_M, 0x00);
}
 
void LSM303_Write_A_Reg(char reg, char value) {
char buffer[2];
buffer[0] = reg;
buffer[1] = value;
I2C_Master_Send(lsm303_data_p->acc_address, 2, buffer);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
void LSM303_Write_M_Reg(char reg, char value) {
char buffer[2];
buffer[0] = reg;
buffer[1] = value;
I2C_Master_Send(lsm303_data_p->mag_address, 2, buffer);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
void LSM303_Set_Mag_Gain(enum magGain value) {
char buffer[2];
buffer[0] = LSM303_CRB_REG_M;
buffer[1] = (char)value;
I2C_Master_Send(lsm303_data_p->mag_address, 2, buffer);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
void LSM303_Read_Acc(int* x, int* y, int* z) {
char buffer[6];
char value = LSM303_OUT_X_L_A | 0x80;
I2C_Master_Restart(lsm303_data_p->acc_address, value, 6);
char result;
do {
result = I2C_Get_Status();
} while (!result);
I2C_Read_Buffer(buffer);
 
// 0 = x_l, 1 = x_h, 2 = y_l, ...
*x = buffer[1] << 8 | buffer[0];
*y = buffer[3] << 8 | buffer[2];
*z = buffer[5] << 8 | buffer[4];
}
 
void LSM303_Read_Mag(int* x, int* y, int* z) {
char buffer[6];
char value = LSM303_OUT_X_H_M;
I2C_Master_Restart(lsm303_data_p->mag_address, value, 6);
char result;
do {
result = I2C_Get_Status();
} while (!result);
I2C_Read_Buffer(buffer);
 
*x = buffer[0] << 8 | buffer[1];
 
if (lsm303_data_p->device == LSM303DLH_DEVICE) {
// DLH: register address for Y comes before Z
*y = buffer[2] << 8 | buffer[3];
*z = buffer[4] << 8 | buffer[5];
} else {
// DLM, DLHC: register address for Z comes before Y
*z = buffer[2] << 8 | buffer[3];
*y = buffer[4] << 8 | buffer[5];
}
}
/PIC Projects/PICX_27J13/sensor_accel_LSM303.h
0,0 → 1,116
#ifndef ACCEL_LSM303_H
#define ACCEL_LSM303_H
 
// Device
#define LSM303DLH_DEVICE 0
#define LSM303DLM_DEVICE 1
#define LSM303DLHC_DEVICE 2
 
// SA0_A States
#define LSM303_SA0_A_LOW 0
#define LSM303_SA0_A_HIGH 1
 
// Slave Addresses
#define MAG_ADDRESS (0x3C >> 1)
#define ACC_ADDRESS_SA0_A_LOW (0x30 >> 1)
#define ACC_ADDRESS_SA0_A_HIGH (0x32 >> 1)
 
// Register Addresses
#define LSM303_CTRL_REG1_A 0x20
#define LSM303_CTRL_REG2_A 0x21
#define LSM303_CTRL_REG3_A 0x22
#define LSM303_CTRL_REG4_A 0x23
#define LSM303_CTRL_REG5_A 0x24
#define LSM303_CTRL_REG6_A 0x25 // DLHC only
#define LSM303_HP_FILTER_RESET_A 0x25 // DLH, DLM only
#define LSM303_REFERENCE_A 0x26
#define LSM303_STATUS_REG_A 0x27
 
#define LSM303_OUT_X_L_A 0x28
#define LSM303_OUT_X_H_A 0x29
#define LSM303_OUT_Y_L_A 0x2A
#define LSM303_OUT_Y_H_A 0x2B
#define LSM303_OUT_Z_L_A 0x2C
#define LSM303_OUT_Z_H_A 0x2D
 
#define LSM303_FIFO_CTRL_REG_A 0x2E // DLHC only
#define LSM303_FIFO_SRC_REG_A 0x2F // DLHC only
 
#define LSM303_INT1_CFG_A 0x30
#define LSM303_INT1_SRC_A 0x31
#define LSM303_INT1_THS_A 0x32
#define LSM303_INT1_DURATION_A 0x33
#define LSM303_INT2_CFG_A 0x34
#define LSM303_INT2_SRC_A 0x35
#define LSM303_INT2_THS_A 0x36
#define LSM303_INT2_DURATION_A 0x37
 
#define LSM303_CLICK_CFG_A 0x38 // DLHC only
#define LSM303_CLICK_SRC_A 0x39 // DLHC only
#define LSM303_CLICK_THS_A 0x3A // DLHC only
#define LSM303_TIME_LIMIT_A 0x3B // DLHC only
#define LSM303_TIME_LATENCY_A 0x3C // DLHC only
#define LSM303_TIME_WINDOW_A 0x3D // DLHC only
 
#define LSM303_CRA_REG_M 0x00
#define LSM303_CRB_REG_M 0x01
#define LSM303_MR_REG_M 0x02
 
#define LSM303_OUT_X_H_M 0x03
#define LSM303_OUT_X_L_M 0x04
#define LSM303_OUT_Y_H_M -1 // The addresses of the Y and Z magnetometer output registers
#define LSM303_OUT_Y_L_M -2 // are reversed on the DLM and DLHC relative to the DLH.
#define LSM303_OUT_Z_H_M -3 // These four defines have dummy values so the library can
#define LSM303_OUT_Z_L_M -4 // determine the correct address based on the device type.
 
#define LSM303_SR_REG_M 0x09
#define LSM303_IRA_REG_M 0x0A
#define LSM303_IRB_REG_M 0x0B
#define LSM303_IRC_REG_M 0x0C
 
#define LSM303_WHO_AM_I_M 0x0F // DLM only
 
#define LSM303_TEMP_OUT_H_M 0x31 // DLHC only
#define LSM303_TEMP_OUT_L_M 0x32 // DLHC only
 
#define LSM303DLH_OUT_Y_H_M 0x05
#define LSM303DLH_OUT_Y_L_M 0x06
#define LSM303DLH_OUT_Z_H_M 0x07
#define LSM303DLH_OUT_Z_L_M 0x08
 
#define LSM303DLM_OUT_Z_H_M 0x05
#define LSM303DLM_OUT_Z_L_M 0x06
#define LSM303DLM_OUT_Y_H_M 0x07
#define LSM303DLM_OUT_Y_L_M 0x08
 
#define LSM303DLHC_OUT_Z_H_M 0x05
#define LSM303DLHC_OUT_Z_L_M 0x06
#define LSM303DLHC_OUT_Y_H_M 0x07
#define LSM303DLHC_OUT_Y_L_M 0x08
 
typedef struct {
char acc_address;
char mag_address;
char device;
} LSM303_DATA;
 
enum magGain {
magGain_13 = 0x20, magGain_19 = 0x40,
magGain_25 = 0x60, magGain_40 = 0x80,
magGain_47 = 0xA0, magGain_56 = 0xC0,
magGain_81 = 0xE0
};
 
void LSM303_Init(LSM303_DATA *data, char device, char sa0);
void LSM303_Begin(void);
 
void LSM303_Write_A_Reg(char reg, char value);
void LSM303_Write_M_Reg(char reg, char value);
 
void LSM303_Set_Mag_Gain(enum magGain value);
 
void LSM303_Read_Acc(int *x, int *y, int *z);
void LSM303_Read_Mag(int *x, int *y, int *z);
 
#endif
 
/PIC Projects/PICX_27J13/sensor_gyro_L3G.c
0,0 → 1,54
#include "defines.h"
#include "sensor_gyro_L3G.h"
#include "base_I2C.h"
 
static L3G_DATA *l3g_data_p;
 
void L3G_Init(L3G_DATA *data, char device, char sa0) {
l3g_data_p = data;
switch(device) {
case L3G4200D_DEVICE:
if (sa0 == L3G_SA0_LOW)
l3g_data_p->address = L3G4200D_ADDRESS_SA0_LOW;
else
l3g_data_p->address = L3G4200D_ADDRESS_SA0_HIGH;
break;
case L3GD20_DEVICE:
if (sa0 == L3G_SA0_LOW)
l3g_data_p->address = L3GD20_ADDRESS_SA0_LOW;
else
l3g_data_p->address = L3GD20_ADDRESS_SA0_HIGH;
break;
default:
break;
}
}
 
void L3G_Begin() {
char buffer[2];
// Normal power mode, all axes enabled
buffer[0] = L3G_CTRL_REG1;
buffer[1] = 0x0F;
I2C_Master_Send(l3g_data_p->address, 2, buffer);
char result;
do {
result = I2C_Get_Status();
} while (!result);
}
 
void L3G_Read(int* x, int* y, int* z) {
char msg = L3G_OUT_X_L | 0x80;
char buffer[6];
char result;
 
I2C_Master_Restart(l3g_data_p->address, msg, 6);
do {
result = I2C_Get_Status();
} while (!result);
I2C_Read_Buffer(buffer);
 
// 0 = x_l, 1 = x_h, 2 = y_l, ...
*x = buffer[1] << 8 | buffer[0];
*y = buffer[3] << 8 | buffer[2];
*z = buffer[5] << 8 | buffer[4];
}
/PIC Projects/PICX_27J13/sensor_gyro_L3G.h
0,0 → 1,59
#ifndef GYRO_L3G_H
#define GYRO_L3G_H
 
// Device Types
#define L3G4200D_DEVICE 0
#define L3GD20_DEVICE 1
 
// SA0 States
#define L3G_SA0_LOW 0
#define L3G_SA0_HIGH 1
 
// Slave Addresses
#define L3G4200D_ADDRESS_SA0_LOW (0xD0 >> 1)
#define L3G4200D_ADDRESS_SA0_HIGH (0xD2 >> 1)
#define L3GD20_ADDRESS_SA0_LOW (0xD4 >> 1)
#define L3GD20_ADDRESS_SA0_HIGH (0xD6 >> 1)
 
// Register Addresses
#define L3G_WHO_AM_I 0x0F
 
#define L3G_CTRL_REG1 0x20
#define L3G_CTRL_REG2 0x21
#define L3G_CTRL_REG3 0x22
#define L3G_CTRL_REG4 0x23
#define L3G_CTRL_REG5 0x24
#define L3G_REFERENCE 0x25
#define L3G_OUT_TEMP 0x26
#define L3G_STATUS_REG 0x27
 
#define L3G_OUT_X_L 0x28
#define L3G_OUT_X_H 0x29
#define L3G_OUT_Y_L 0x2A
#define L3G_OUT_Y_H 0x2B
#define L3G_OUT_Z_L 0x2C
#define L3G_OUT_Z_H 0x2D
 
#define L3G_FIFO_CTRL_REG 0x2E
#define L3G_FIFO_SRC_REG 0x2F
 
#define L3G_INT1_CFG 0x30
#define L3G_INT1_SRC 0x31
#define L3G_INT1_THS_XH 0x32
#define L3G_INT1_THS_XL 0x33
#define L3G_INT1_THS_YH 0x34
#define L3G_INT1_THS_YL 0x35
#define L3G_INT1_THS_ZH 0x36
#define L3G_INT1_THS_ZL 0x37
#define L3G_INT1_DURATION 0x38
 
typedef struct {
char address;
} L3G_DATA;
 
void L3G_Init(L3G_DATA *data, char device, char sa0);
void L3G_Begin(void);
void L3G_Read(int *x, int *y, int *z);
 
#endif
 
/PIC Projects/PICX_27J13/base_ADC.c
0,0 → 1,55
#include <xc.h>
#include "defines.h"
#include "base_ADC.h"
 
static ADC_DATA *adc_data_p;
 
void ADC_Init(ADC_DATA *data, char TAD, char FOSC) {
adc_data_p = data;
ADC_AN0_TRIS = 1;
ADC_AN1_TRIS = 1;
ADC_AN2_TRIS = 1;
 
adc_data_p->last_channel = 0;
adc_data_p->result = 0;
 
ADCON0bits.VCFG1 = 0; // VRef- = AVss
ADCON0bits.VCFG0 = 1; // VRef+ != AVdd
ADCON1bits.ADFM = 1; // Right justified result
ADCON1bits.ADCAL = 1; // Calibrate A/D
ADCON1bits.ACQT = TAD;
ADCON1bits.ADCS = FOSC;
ADCON0bits.ADON = 1; // Enable A/D module
 
ADCON0bits.GO_DONE = 1; // Start calibration
while (ADCON0bits.GO_DONE); // Wait for calibration to finish
PIR1bits.ADIF = 0; // Clear the IF flag
ADCON1bits.ADCAL = 0; // Normal A/D operation
 
PIE1bits.ADIE = 1; // Enable A/D interrupt
 
}
 
void ADC_Start(char channel) {
adc_data_p->last_channel = channel;
ADCON0bits.CHS = channel; // Set A/D channel
ADCON0bits.GO_DONE = 1; // Start A/D conversion
}
 
void ADC_Stop() {
ADCON0bits.ADON = 0; // Disable A/D module
}
 
void ADC_Interrupt_Handler() {
adc_data_p->result = ADRES;
}
 
char ADC_Get_Result(unsigned int* ret) {
if (ADCON0bits.GO_DONE) {
return 0;
} else {
*ret = adc_data_p->result;
return 1;
}
}
/PIC Projects/PICX_27J13/base_ADC.h
0,0 → 1,48
#ifndef ADC_H
#define ADC_H
 
#define ADC_CHANNEL_AN0 0b0000
#define ADC_CHANNEL_AN1 0b0001
#define ADC_CHANNEL_AN2 0b0010
#define ADC_CHANNEL_AN3 0b0011
#define ADC_CHANNEL_AN4 0b0100
#define ADC_CHANNEL_AN5 0b0101
#define ADC_CHANNEL_AN6 0b0110
#define ADC_CHANNEL_AN7 0b0111
#define ADC_CHANNEL_AN8 0b1000
#define ADC_CHANNEL_AN9 0b1001
#define ADC_CHANNEL_AN10 0b1010
#define ADC_CHANNEL_AN11 0b1011
#define ADC_CHANNEL_AN12 0b1100
#define ADC_CHANNEL_VDDCORE 0b1110
#define ADC_CHANNEL_ABG 0b1111
 
#define ADC_TAD_20 0b111
#define ADC_TAD_16 0b110
#define ADC_TAD_12 0b101
#define ADC_TAD_8 0b100
#define ADC_TAD_6 0b011
#define ADC_TAD_4 0b010
#define ADC_TAD_2 0b001
#define ADC_TAD_0 0b000
 
#define ADC_FOSC_64_ 0b110
#define ADC_FOSC_32_ 0b010
#define ADC_FOSC_16_ 0b101
#define ADC_FOSC_8_ 0b001
#define ADC_FOSC_4_ 0b100
#define ADC_FOSC_2_ 0b000
#define ADC_FOSC_FRC_ 0b011
 
typedef struct __ADC_DATA {
char last_channel;
unsigned int result;
} ADC_DATA;
 
void ADC_Init(ADC_DATA *data, char TAD, char FOSC);
void ADC_Start(char channel);
void ADC_Stop(void);
void ADC_Interrupt_Handler(void);
char ADC_Get_Result(unsigned int *ret);
 
#endif
/PIC Projects/PICX_27J13/base_I2C.c
0,0 → 1,564
#include <xc.h>
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "base_I2C.h"
#include "base_UART.h"
 
static I2C_DATA *i2c_data_p;
 
// Set up the data structures for the base_I2C.code
// Should be called once before any i2c routines are called
void I2C_Init(I2C_DATA *data) {
i2c_data_p = data;
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSPIE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C_Configure_Master(char speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0x8; // I2C Master Mode
if (speed) {
SSPADD = 0x74; // Operate at 100KHz (48MHz)
} else {
SSPADD = 0x1A; // Operate at 400KHz (48MHz)
}
SSPSTATbits.SMP = 1; // Disable Slew Rate Control
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C_Master_Send(char address, char length, char *msg) {
char i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C_Master_Recv(char address, char length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C_Master_Restart(char address, char msg, char length) {
char c;
if (length == 0) {
c = msg;
I2C_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C_Configure_Slave(char addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPADD = addr << 1; // Set the slave address
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0xE; // Enable Slave 7-bit w/ start/stop interrupts
SSPSTATbits.SMP = 1; // Slew Off
SSPCON2bits.SEN = 1; // Enable clock-stretching
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
void I2C_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSPBUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSPBUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSPCON2bits.ACKSTAT) {
SSPCON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C_Interrupt_Slave() {
char received_data;
char data_read_from_buffer = 0;
char data_written_to_buffer = 0;
char overrun_error = 0;
char output[64];
 
// Clear SSPOV (overflow bit)
if (SSPCON1bits.SSPOV == 1) {
sprintf(output, "I2C: (ERROR) overflow detectedr\r\n");
DBG_PRINT_I2C(output, strlen(output));
SSPCON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSPSTATbits.BF == 1) {
received_data = SSPBUF;
// DBG_PRINT_I2C("I2C: data read from buffer: %x\r\n", SSPBUF);
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// Ignore anything except a start
if (SSPSTATbits.S == 1) {
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->operating_state = I2C_STARTED;
// if (data_read_from_buffer) {
// if (SSPSTATbits.D_A == 1) {
// DBG_PRINT_I2C("I2C Start: (ERROR) no address recieved\r\n");
// // This is bad because we got data and we wanted an address
// i2c_data_p->operating_state = I2C_IDLE;
// i2c_data_p->return_status = I2C_ERR_NOADDR;
// } else {
// // Determine if we are sending or receiving data
// if (SSPSTATbits.R_W == 1) {
// i2c_data_p->operating_state = I2C_SEND_DATA;
// } else {
// i2c_data_p->operating_state = I2C_RCV_DATA;
// }
// }
// } else {
// i2c_data_p->operating_state = I2C_STARTED;
// }
}
break;
}
case I2C_STARTED:
{
// In this case, we expect either an address or a stop bit
if (SSPSTATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 0) {
// Address received
if (SSPSTATbits.R_W == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
sprintf(output, "I2C: (ERROR) no data recieved\r\n");
DBG_PRINT_I2C(output, strlen(output));
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C_Process_Send(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSPBUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSPBUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSPSTATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 1) {
// Data received with stop bit
// TODO: Handle I2C buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
sprintf(output, "I2C: (ERROR) no data recieved\r\n");
DBG_PRINT_I2C(output, strlen(output));
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSPSTATbits.R_W == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
sprintf(output, "I2C: (ERROR) no data recieved\r\n");
DBG_PRINT_I2C(output, strlen(output));
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSPCON1bits.CKP == 0) {
SSPCON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
char I2C_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
char I2C_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
char I2C_Read_Buffer(char *buffer) {
char i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
char I2C_Process_Send(char c) {
char ret = 0;
switch (c) {
case 0xAA:
i2c_data_p->buffer_out[0] = 'A';
i2c_data_p->buffer_out_len = 1;
ret = 1;
break;
case 0xBB:
i2c_data_p->buffer_out[0] = '1';
i2c_data_p->buffer_out[1] = '2';
i2c_data_p->buffer_out_len = 2;
ret = 1;
break;
}
return ret;
}
/PIC Projects/PICX_27J13/base_I2C.h
0,0 → 1,81
#ifndef I2C_H
#define I2C_H
 
#define MAXI2CBUF 64
 
// I2C Operating Speed
#define I2C_400KHZ 0x0
#define I2C_100KHZ 0x1
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct {
char buffer_in[MAXI2CBUF];
char buffer_in_len;
char buffer_in_len_tmp;
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_out[MAXI2CBUF];
char buffer_out_len;
char buffer_out_ind;
 
char operating_mode;
char operating_state;
char return_status;
 
char master_dest_addr;
char master_status;
char slave_in_last_byte;
char slave_sending_data;
} I2C_DATA;
 
void I2C_Init(I2C_DATA *data);
void I2C_Interrupt_Handler(void);
void I2C_Interrupt_Slave(void);
void I2C_Interrupt_Master(void);
void I2C_Configure_Slave(char);
void I2C_Configure_Master(char speed);
void I2C_Master_Send(char address, char length, char *msg);
void I2C_Master_Recv(char address, char length);
void I2C_Master_Restart(char address, char msg, char length);
char I2C_Get_Status(void);
char I2C_Buffer_Len(void);
char I2C_Read_Buffer(char *buffer);
char I2C_Process_Send(char);
 
#endif
/PIC Projects/PICX_27J13/base_INTERRUPTS.c
0,0 → 1,161
#include <xc.h>
#include "defines.h"
#include "base_INTERRUPTS.h"
#include "base_UART.h"
#include "base_I2C.h"
#include "base_TIMERS.h"
 
void Interrupt_Init() {
// Peripheral base_INTERRUPTS.can have their priority set to high or low
// Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
 
// High priority interrupts
IPR1bits.RC1IP = 1; // USART1 RX interrupt
IPR1bits.TX1IP = 1; // USART1 TX interrupt
// IPR3bits.RC2IP = 1; // USART2 RX interrupt
IPR1bits.SSPIP = 1; // I2C interrupt
// IPR3bits.SSP2IP = 1; // MSSP2 (SPI2) interrupt
 
// Low priority interrupts
// INTCON2bits.TMR0IP = 0; // Timer0 interrupt
IPR1bits.TMR1IP = 0; // Timer1 interrupt
// IPR2bits.TMR3IP = 0; // Timer 3 interrupt
// IPR1bits.ADIP = 0; // ADC interupt
// INTCON2bits.RBIP = 0; // Port B interrupt
// INTCON3bits.INT1IP = 0; // INT1 interrupt
// Enable Port B interrupt
// INTCONbits.RBIE = 1;
// Enable interrupt for INT1
// INTCON3bits.INT1IE = 1;
}
 
void Interrupt_Enable() {
// Peripheral base_INTERRUPTS.can have their priority set to high or low.
// Enable both high-priority interrupts and low-priority interrupts
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
}
 
void Interrupt_Disable() {
RCONbits.IPEN = 0;
INTCONbits.GIEH = 0;
INTCONbits.GIEL = 0;
}
 
void interrupt InterruptHandlerHigh(void) {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// // Check to see if we have an SPI2 interrupt
// if (PIR3bits.SSP2IF) {
// // Call the handler
// SPI2_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR3bits.SSP2IF = 0;
//
// return;
// }
 
// Check to see if we have an I2C interrupt
if (PIR1bits.SSPIF) {
 
// Call the handler
I2C_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSPIF = 0;
 
return;
}
 
// Check to see if we have an interrupt on USART1 RX
if (PIR1bits.RC1IF) {
// Call the interrupt handler
UART1_Recv_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.RC1IF = 0;
 
return;
}
 
#ifndef _DEBUG // Disable UART1 TX interrupt for debug mode (using printf)
// Check to see if we have an interrupt on USART1 TX
if (PIR1bits.TX1IF) {
// Call the interrupt handler
UART1_Send_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.TX1IF = 0;
 
return;
}
#endif
 
// // Check to see if we have an interrupt on USART2 RX
// if (PIR3bits.RC2IF) {
// DBG_PRINT_INT("INT: UART2 RX\r\n");
// // Call the interrupt handler
// uart_2_recv_interrupt_handler();
//
// // Clear the interrupt flag
// PIR3bits.RC2IF = 0;
// }
}
 
void interrupt low_priority InterruptHandlerLow() {
// // Check to see if we have an interrupt on INT1
// if (INTCON3bits.INT1IF) {
// DBG_PRINT_INT("INT: INT1\r\n");
// int1_interrupt_handler();
//
// INTCON3bits.INT1IF = 0;
// }
 
// // Check to see if we have an interrupt on any port B inputs <4:7>
// if (INTCONbits.RBIF) {
// DBG_PRINT_INT("INT: Port B\r\n");
// port_b_int_interrupt_handler();
//
// INTCONbits.RBIF = 0;
// }
 
// // Check to see if we have an interrupt on timer 0
// if (INTCONbits.TMR0IF) {
// DBG_PRINT_INT("INT: Timer 0\r\n");
// // Call the handler
// timer0_interrupt_handler();
//
// // Clear this interrupt flag
// INTCONbits.TMR0IF = 0;
// }
 
// Check to see if we have an interrupt on timer 1
if (PIR1bits.TMR1IF) {
// Call the interrupt handler
Timer1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.TMR1IF = 0;
}
 
// // Check to see if we have an interrupt on timer 3
// if (PIR2bits.TMR3IF) {
// DBG_PRINT_INT("INT: Timer 3\r\n");
// timer3_interrupt_handler();
//
// PIR2bits.TMR3IF = 0;
// }
 
// // Check to see if we have an interrupt on ADC
// if (PIR1bits.ADIF) {
// // Call the interrupt handler
// ADC_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.ADIF = 0;
// }
}
/PIC Projects/PICX_27J13/base_INTERRUPTS.h
0,0 → 1,16
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable all interrupts (high and low priority)
void Interrupt_Enable(void);
 
// Disable all interrupts (high and low priority)
void Interrupt_Disable(void);
 
void interrupt InterruptHandlerHigh(void);
void interrupt low_priority InterruptHandlerLow(void);
 
#endif
/PIC Projects/PICX_27J13/base_TIMERS.c
0,0 → 1,36
#include <xc.h>
#include <delays.h>
#include "defines.h"
#include "base_TIMERS.h"
 
void Timer1_Init(void) {
T1CONbits.TMR1CS = 0x2; // Clock source using T1OSC and T1CLK pins
T1CONbits.RD16 = 0x1; // Configure for 16-bit read/writes
T1CONbits.T1OSCEN = 0x1; // Enable crystal driver
PIE1bits.TMR1IE = 0x1; // Enable interrupt
 
// Non-applicable settings
T1CONbits.T1CKPS = 0x0; // 1:1 prescale value
T1CONbits.NOT_T1SYNC = 0x1; // No external sync
T1GCONbits.TMR1GE = 0x0; // Disable gate control
}
 
void Timer1_Enable(void) {
T1CONbits.TMR1ON = 1;
}
 
void Timer1_Disable(void) {
T1CONbits.TMR1ON = 0;
}
 
void Timer1_Interrupt_Handler(void) {
#ifdef _TEST_TIMER1_RTC
TMR1H = 0x7F;
TMR1L = 0xFF;
LED_BLUE_LAT = 1;
LED_RED_LAT = 1;
Delay10KTCYx(255);
LED_BLUE_LAT = 0;
LED_RED_LAT = 0;
#endif
}
/PIC Projects/PICX_27J13/base_TIMERS.h
0,0 → 1,9
#ifndef TIMERS_H
#define TIMERS_H
 
void Timer1_Init(void);
void Timer1_Enable(void);
void Timer1_Disable(void);
void Timer1_Interrupt_Handler(void);
 
#endif
/PIC Projects/PICX_27J13/base_UART.c
0,0 → 1,215
#include <xc.h>
#include <string.h>
#include <stdio.h>
#include "defines.h"
#include "base_UART.h"
 
static UART_DATA *uart_1_data_p;
 
void UART1_Init(UART_DATA *data) {
uart_1_data_p = data;
 
UART1_TX_TRIS = 0; // Tx pin set to output
UART1_RX_TRIS = 1; // Rx pin set to input
 
BAUDCON1bits.BRG16 = 0; // 8-bit baud rate generator
SPBRG1 = 25; // Set UART speed to 115200 baud
TXSTA1bits.BRGH = 1; // High speed mode
TXSTA1bits.SYNC = 0; // Async mode
RCSTA1bits.SPEN = 1; // Serial port enable
TXSTA1bits.TX9 = 0; // 8 bit transmission
RCSTA1bits.RX9 = 0; // 8 bit reception
RCSTA1bits.CREN = 1; // Continuous receive mode
 
#ifdef _DEBUG // In debug mode we want to have TXEN constantly enabled
TXSTA1bits.TXEN = 1; // TX is always enabled
PIE1bits.TX1IE = 0; // Disable TX interrupt
#else
TXSTA1bits.TXEN = 0; // Enable transmission
PIE1bits.TX1IE = 1; // Enable TX interrupt
#endif
 
PIE1bits.RC1IE = 1; // Enable RX interrupt
 
// Initialize the buffer that holds UART messages
uart_1_data_p->buffer_in_read_ind = 0;
uart_1_data_p->buffer_in_write_ind = 0;
uart_1_data_p->buffer_in_len = 0;
uart_1_data_p->buffer_in_len_tmp = 0;
}
 
#pragma interrupt_level 0
void UART1_Recv_Interrupt_Handler() {
char c;
if (PIR1bits.RC1IF) { // Check if data receive flag is set
c = RCREG1;
#ifdef UART1_RX_TO_BUFFER
// Save received data into buffer
uart_1_data_p->buffer_in[uart_1_data_p->buffer_in_write_ind] = c;
if (uart_1_data_p->buffer_in_write_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_write_ind = 0;
} else {
uart_1_data_p->buffer_in_write_ind++;
}
 
// Store the last MAXUARTBUF values entered
if (uart_1_data_p->buffer_in_len_tmp < MAXUARTBUF) {
uart_1_data_p->buffer_in_len_tmp++;
} else {
if (uart_1_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_read_ind = 0;
} else {
uart_1_data_p->buffer_in_read_ind++;
}
}
 
// Update buffer size upon receiving newline (0x0D)
if (c == UART1_BREAK_CHAR) {
uart_1_data_p->buffer_in_len = uart_1_data_p->buffer_in_len_tmp;
uart_1_data_p->buffer_in_len_tmp = 0;
}
#endif
#ifdef UART1_RX_TO_XBEE
XBee_Serial_In(c);
#endif
}
 
if (RCSTA1bits.OERR == 1) {
// We've overrun the USART and must reset
RCSTA1bits.CREN = 0; // Reset UART1
RCSTA1bits.CREN = 1;
char output[64];
sprintf(output, "UART1: (ERROR) Overrun Occurred\r\n");
DBG_PRINT_UART(output, strlen(output));
TXSTA1bits.TXEN = 0; // Kill anything currently sending
}
}
 
void UART1_Send_Interrupt_Handler() {
// Put remaining data in TSR for transmit
if (uart_1_data_p->buffer_out_ind != uart_1_data_p->buffer_out_len) {
TXREG1 = uart_1_data_p->buffer_out[uart_1_data_p->buffer_out_ind];
uart_1_data_p->buffer_out_ind++;
} else {
while (!TXSTA1bits.TRMT); // Wait for last byte to finish sending
TXSTA1bits.TXEN = 0; // End transmission and disable TX interrupt
uart_1_data_p->buffer_out_ind = 0;
uart_1_data_p->buffer_out_len = 0;
}
}
 
//void UART1_WriteS(const char *fmt, ...) {
//#ifdef _DEBUG
// char i;
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) uart_1_data_p->buffer_out, fmt, args);
// va_end(args);
// uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
// uart_1_data_p->buffer_out_ind = 1;
// for (i = 0; i < uart_1_data_p->buffer_out_len; i++) {
// TXREG1 = uart_1_data_p->buffer_out[i];
// Nop();
// while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
// }
//#else
// va_list args;
// while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
// va_start(args, fmt);
// vsprintf((char *) uart_1_data_p->buffer_out, fmt, args);
// va_end(args);
// uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
// uart_1_data_p->buffer_out_ind = 1;
// TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
// TXSTA1bits.TXEN = 1; // Begin transmission
//#endif
//}
 
//void UART1_WriteF(float f, char m) {
// long whole = 0;
// unsigned long decimal = 0;
// unsigned int multiplier = 1;
// char i;
//
// for (i = 0; i < m; i++)
// multiplier *= 10;
//
// whole = (long)((float)f);
// decimal = (long)((float)f*multiplier) - whole*multiplier;
// // Round up if necessary
// if ((long)((float)f*multiplier*10) % 10 >= 5)
// decimal += 1;
//#ifdef _DEBUG
// sprintf((char *) uart_1_data_p->buffer_out, "%ld.%ld", whole, decimal);
// uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
// uart_1_data_p->buffer_out_ind = 1;
// for (i = 0; i < uart_1_data_p->buffer_out_len; i++) {
// TXREG1 = uart_1_data_p->buffer_out[i];
// Nop();
// while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
// }
//#else
// while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
// sprintf((char *) uart_1_data_p->buffer_out, "%ld.%ld", whole, decimal);
// uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
// uart_1_data_p->buffer_out_ind = 1;
// TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
// TXSTA1bits.TXEN = 1; // Begin transmission
//#endif
//}
 
void UART1_WriteS(char *string, char length) {
char i;
#ifdef _DEBUG
for (i = 0; i < length; i++) {
TXREG1 = string[i];
Nop();
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
}
#else
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
uart_1_data_p->buffer_out_len = length;
uart_1_data_p->buffer_out_ind = 1;
for (i = 0; i < length; i++) {
uart_1_data_p->buffer_out[i] = string[i];
}
TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
void UART1_WriteC(const char c) {
#ifdef _DEBUG
TXREG1 = c;
Nop();
while (!PIR1bits.TX1IF);
#else
while (TXSTA1bits.TXEN);
uart_1_data_p->buffer_out_len = 1;
uart_1_data_p->buffer_out_ind = 1;
TXREG1 = c;
TXSTA1bits.TXEN = 1;
#endif
 
}
 
char UART1_Buffer_Len() {
return uart_1_data_p->buffer_in_len;
}
 
/* Reader interface to the UART buffer, returns the number of bytes read */
char UART1_Read_Buffer(char *buffer) {
char i = 0;
while (uart_1_data_p->buffer_in_len != 0) {
buffer[i] = uart_1_data_p->buffer_in[uart_1_data_p->buffer_in_read_ind];
i++;
if (uart_1_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_read_ind = 0;
} else {
uart_1_data_p->buffer_in_read_ind++;
}
uart_1_data_p->buffer_in_len--;
}
return i;
}
/PIC Projects/PICX_27J13/base_UART.h
0,0 → 1,32
#ifndef UART_H
#define UART_H
 
#define MAXUARTBUF 125
 
#define UART1_BREAK_CHAR 0x0D //(CR)
 
#define UART1_RECV_BUFFER
//#define UART1_RECV_XBEE
 
typedef struct {
char buffer_in[MAXUARTBUF];
char buffer_in_read_ind;
char buffer_in_write_ind;
char buffer_in_len;
char buffer_in_len_tmp;
 
char buffer_out[MAXUARTBUF];
char buffer_out_ind;
char buffer_out_len;
} UART_DATA;
 
void UART1_Init(UART_DATA *data);
void UART1_Recv_Interrupt_Handler(void);
void UART1_Send_Interrupt_Handler(void);
//void UART1_WriteS(const char *fmt, ...);
//void UART1_WriteF(float f, char m);
void UART1_WriteS(char *string, char length);
void UART1_WriteC(const char c);
char UART1_Buffer_Len(void);
char UART1_Read_Buffer(char *buffer);
#endif
/PIC Projects/PICX_27J13/comm_xbee.c
0,0 → 1,255
#include <xc.h>
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "comm_xbee.h"
#include "base_UART.h"
 
static XBEE_DATA *xbee_data_p;
static void *xbee_data_frame;
//static void *xbee_frame;
 
/* Initialize variables used by this library */
void XBee_Init(XBEE_DATA *data) {
xbee_data_p = data;
XBEE_CTS_TRIS = 1; // RB0 is CTS, set by XBee chip
XBEE_RTS_TRIS = 0; // RB1 is RTS, set by PIC
 
XBEE_CTS_LAT = 0; // Pin set high to signal stop sending data to XBee
XBEE_RTS_LAT = 0; // Pin set high to indicate stop sending data to PIC
 
xbee_data_p->dataind = 0;
xbee_data_p->checksum_sum = 0;
xbee_data_p->frame_rdy = 0;
xbee_data_p->escape_flag = 0;
xbee_data_p->read_state = XBEE_STATE_READ_START;
 
// memset(&xbee_data, 0, 32);
// Grab a pointer to where the unique frame array starts
xbee_data_frame = &(xbee_data_p->rcv_frame.FRAME);
// xbee_frame = &(xbee_data_p->rcv_frame);
}
 
/* Here we handle the serial input from the UART interrupt */
void XBee_Serial_In(char c) {
// For some reason writing the length straight to xbee_data doesnt seem to work
// so we work around it by pointing to the length bytes directly
// XBEE_ADDRESS_16 *length = xbee_frame + 1;
#ifdef XBEE_USE_ESCAPE_CHAR
if (c == XBEE_ESCAPE_CHAR) {
// Next byte needs is an escaped char
xbee_data_p->escape_flag = 1;
return;
}
 
if (xbee_data_p->escape_flag) {
// XOR byte with 0x20 to get escaped char
c ^= XBEE_ESCAPE_VAL;
xbee_data_p->escape_flag = 0;
}
#endif
// Reset on start bit and start saving data
if (c == XBEE_START_DELIMITER) {
// On detect start delimiter, clear out initial array
xbee_data_p->dataind = 0;
xbee_data_p->checksum_sum = 0;
xbee_data_p->frame_rdy = 0;
xbee_data_p->read_state = XBEE_STATE_READ_LENGTH_HIGH;
// *((char *)xbee_frame) = XBEE_START_DELIMITER;
xbee_data_p->rcv_frame.start_delimiter = XBEE_START_DELIMITER;
 
} else {
switch (xbee_data_p->read_state) {
case XBEE_STATE_READ_START:
// Do nothing and wait till start bit is read
break;
case XBEE_STATE_READ_LENGTH_HIGH:
// Read length (MSB)
// length->INT_16.char_value[1] = c;
xbee_data_p->rcv_frame.length.INT_16.char_value[1] = c;
xbee_data_p->read_state = XBEE_STATE_READ_LENGTH_LOW;
break;
case XBEE_STATE_READ_LENGTH_LOW:
// Read length (LSB)
// length->INT_16.char_value[0] = c;
xbee_data_p->rcv_frame.length.INT_16.char_value[0] = c;
xbee_data_p->read_state = XBEE_STATE_READ_FRAME_DATA;
break;
case XBEE_STATE_READ_FRAME_DATA:
// Read unique frame data
if (xbee_data_p->dataind < xbee_data_p->rcv_frame.length.INT_16.int_value) {
*((char*) xbee_data_frame + xbee_data_p->dataind) = c;
xbee_data_p->checksum_sum += c;
xbee_data_p->dataind++;
}
// If total length is read, the next byte is the expected checksum
if (xbee_data_p->dataind == xbee_data_p->rcv_frame.length.INT_16.int_value) {
xbee_data_p->read_state = XBEE_STATE_READ_CHECKSUM;
}
break;
case XBEE_STATE_READ_CHECKSUM:
// Calculate and compare checksum
if (0xFF - xbee_data_p->checksum_sum == c) {
// Frame was recieved successfully
xbee_data_p->frame_rdy = 1;
// XBee_Process_Received_Frame();
} else {
// If checksum does not match, drop frame
char output[32];
sprintf(output, "XBEE: checksum mismatch\r\n");
DBG_PRINT_XBEE(output, strlen(output));
}
xbee_data_p->read_state = XBEE_STATE_READ_START;
break;
}
}
}
 
/* This processes the frame data within the interrupt. Dont use this. */
void XBee_Process_Received_Frame() {
// DBG_PRINT_XBEE("Length: %d\r\n", xbee_data_p->rcv_frame.length.INT_16.int_value);
// Here we process the received frame depending on the frame type
char output[64];
switch (*((char *) xbee_data_frame)) {
case XBEE_RX_AT_COMMAND_RESPONSE:
sprintf(output, "XBEE: parsing recieved AT command response frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_DATA_PACKET:
sprintf(output, "XBEE: parsing recieved data frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_DATA_TX_STATUS:
sprintf(output, "XBEE: parsing recieved TX status frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_IO_DATA_SAMPLE:
sprintf(output, "XBEE: parsing recieved IO data sample frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_EXPLICIT_COMMAND:
sprintf(output, "XBEE: parsing recieved explicit command frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
sprintf(output, "XBEE: parsing recieved remote AT command frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_ROUTE_RECORD:
sprintf(output, "XBEE: parsing recieved route record frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_NODE_IDENTIFICATION:
sprintf(output, "XBEE: parsing recieved node identification frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
case XBEE_RX_FRAME_MODEM_STATUS:
sprintf(output, "XBEE: parsing recieved modem status frame\r\n");
DBG_PRINT_XBEE(output, strlen(output));
break;
default:
sprintf(output, "XBEE: (ERROR) unrecognized frame type\r\n");
DBG_PRINT_XBEE(output, strlen(output));
}
}
 
unsigned int XBee_Get_Received_Frame(char *frame) {
if (!xbee_data_p->frame_rdy) {
return 0;
} else {
memcpy(frame, xbee_data_frame, xbee_data_p->rcv_frame.length.INT_16.int_value);
xbee_data_p->frame_rdy = 0; // Reset frame ready status
return xbee_data_p->rcv_frame.length.INT_16.int_value;
}
}
 
void XBee_Process_Transmit_Frame(char *data, char length) {
#ifdef XBEE_USE_ESCAPE_CHAR
unsigned int i = 0;
char chksum = 0;
 
// Write the start bit and length
UART1_WriteC(XBEE_START_DELIMITER);
UART1_WriteC(0);
UART1_WriteC(length);
 
// Write the frame data
for (i = 0; i < length; i++) {
chksum += data[i];
if (data[i] == XBEE_START_DELIMITER || \
data[i] == XBEE_ESCAPE_CHAR || \
data[i] == XBEE_XON || \
data[i] == XBEE_XOFF) {
UART1_WriteC(XBEE_ESCAPE_CHAR);
UART1_WriteC(data[i] ^ XBEE_ESCAPE_VAL);
} else {
UART1_WriteC(data[i]);
}
}
// Write the checksum
if (chksum == XBEE_START_DELIMITER || \
chksum == XBEE_ESCAPE_CHAR || \
chksum == XBEE_XON || \
chksum == XBEE_XOFF) {
UART1_WriteC(XBEE_ESCAPE_CHAR);
UART1_WriteC(chksum ^ XBEE_ESCAPE_VAL);
} else {
UART1_WriteC(0xFF - chksum);
}
#else
unsigned int i = 0;
char chksum = 0;
 
UART1_WriteC(XBEE_START_DELIMITER);
UART1_WriteC(0);
UART1_WriteC(length);
for (i = 0; i < length; i++) {
chksum += data[i];
UART1_WriteC(data[i]);
}
UART1_WriteC(0xFF - chksum);
#endif
}
 
void XBee_Set_RTS(char c) {
if (c) {
XBEE_RTS_LAT = 1; // Set high to stop receiving data
} else {
XBEE_RTS_LAT = 0; // Set low to resume receiving data
}
}
 
char XBee_Read_CTS() {
char c = XBEE_CTS_PORT;
if (c) {
return 0x1; // High indicates stop sending data
} else {
return 0x0; // Low indicates ok to send data
}
}
 
void XBee_Convert_Endian_64(XBEE_ADDRESS_64 *src) {
char tmp[2];
tmp[0] = src->UPPER_32.char_value[3];
tmp[1] = src->UPPER_32.char_value[2];
src->UPPER_32.char_value[3] = src->UPPER_32.char_value[0];
src->UPPER_32.char_value[2] = src->UPPER_32.char_value[1];
src->UPPER_32.char_value[1] = tmp[1];
src->UPPER_32.char_value[0] = tmp[0];
 
tmp[0] = src->LOWER_32.char_value[3];
tmp[1] = src->LOWER_32.char_value[2];
src->LOWER_32.char_value[3] = src->LOWER_32.char_value[0];
src->LOWER_32.char_value[2] = src->LOWER_32.char_value[1];
src->LOWER_32.char_value[1] = tmp[1];
src->LOWER_32.char_value[0] = tmp[0];
}
 
void XBee_Convert_Endian_16(XBEE_ADDRESS_16 *src) {
char tmp;
tmp = src->INT_16.char_value[0];
src->INT_16.char_value[0] = src->INT_16.char_value[1];
src->INT_16.char_value[1] = tmp;
}
/PIC Projects/PICX_27J13/comm_xbee.h
0,0 → 1,269
#ifndef XBEE_H
#define XBEE_H
 
#define XBEE_BUFFER_SIZE 227
 
// If API mode = 2 is enabled
#define XBEE_USE_ESCAPE_CHAR
 
#define XBEE_ESCAPE_VAL 0x20
#define XBEE_START_DELIMITER 0x7E
#define XBEE_ESCAPE_CHAR 0x7D
#define XBEE_XON 0x11
#define XBEE_XOFF 0x13
 
// Expected 'next' state
#define XBEE_STATE_READ_START 10
#define XBEE_STATE_READ_LENGTH_HIGH 11
#define XBEE_STATE_READ_LENGTH_LOW 12
#define XBEE_STATE_READ_FRAME_DATA 13
#define XBEE_STATE_READ_CHECKSUM 14
 
// Command Frame Type
#define XBEE_TX_AT_COMMAND 0x08
#define XBEE_TX_AT_COMMAND_QUEUE 0x09
#define XBEE_RX_AT_COMMAND_RESPONSE 0x88
 
#define XBEE_TX_DATA_PACKET 0x10
#define XBEE_RX_DATA_PACKET 0x90
#define XBEE_RX_DATA_TX_STATUS 0x8B
#define XBEE_RX_IO_DATA_SAMPLE 0x92
#define XBEE_TX_EXPLICIT_COMMAND 0x11
#define XBEE_RX_EXPLICIT_COMMAND 0x91
 
#define XBEE_TX_REMOTE_AT_COMMAND 0x17
#define XBEE_RX_REMOTE_AT_COMMAND_RESPONSE 0x97
 
#define XBEE_TX_CREATE_SOURCE_ROUTE 0x21
#define XBEE_RX_ROUTE_RECORD 0xA1
#define XBEE_RX_NODE_IDENTIFICATION 0x95
#define XBEE_RX_FRAME_MODEM_STATUS 0x8A
 
typedef struct {
union {
unsigned long long_value;
char char_value[4]; // Little Endian!!
} UPPER_32;
union {
unsigned long long_value;
char char_value[4]; // Little Endian!!
} LOWER_32;
} XBEE_ADDRESS_64;
 
typedef struct {
union {
unsigned int int_value;
char char_value[2]; // Little Endian!!
} INT_16;
} XBEE_ADDRESS_16;
 
// Unique Frame Components
typedef struct {
char frame_type;
char frame_id;
char command[2];
char data[XBEE_BUFFER_SIZE];
} XBEE_TX_AT_COMMAND_FRAME;
#define XBEE_TX_AT_COMMAND_FRAME_SIZE 4
 
typedef struct {
char frame_type;
char frame_id;
char command[2];
char data[XBEE_BUFFER_SIZE];
} XBEE_TX_AT_COMMAND_QUEUE_FRAME;
#define XBEE_TX_AT_COMMAND_QUEUE_FRAME_SIZE 4
 
typedef struct {
char frame_type;
char frame_id;
char command[2];
char command_status;
char data[XBEE_BUFFER_SIZE];
} XBEE_RX_AT_COMMAND_RESPONSE_FRAME;
#define XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE 5
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
char broadcast_radius;
char options;
char data[XBEE_BUFFER_SIZE];
} XBEE_TX_DATA_PACKET_FRAME;
#define XBEE_TX_DATA_PACKET_FRAME_SIZE 14
 
typedef struct {
char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char recieve_options;
char data[XBEE_BUFFER_SIZE];
} XBEE_RX_DATA_PACKET_FRAME;
#define XBEE_RX_DATA_PACKET_FRAME_SIZE 12
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_16 destination_16;
char transmit_retry_count;
char delivery_status;
char discovery_status;
} XBEE_RX_DATA_TX_STATUS_FRAME;
#define XBEE_RX_DATA_TX_STATUS_FRAME_SIZE 7
 
typedef struct {
char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char recieve_options;
char number_of_samples;
char digital_ch_mask[2];
char analog_ch_mask;
char digital_samples[2];
char analog_samples[8];
} XBEE_RX_IO_DATA_SAMPLE_FRAME;
#define XBEE_RX_IO_DATA_SAMPLE_FRAME_SIZE 26
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
char source_endpoint;
char destination_endpoint;
char cluster_id[2];
char profile_id[2];
char broadcast_radius;
char transmit_options;
char data[XBEE_BUFFER_SIZE];
} XBEE_TX_EXPLICIT_COMMAND_FRAME;
#define XBEE_TX_EXPLICIT_COMMAND_FRAME_SIZE 20
 
typedef struct {
char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char source_endpoint;
char destination_endpoint;
char cluster_id[2];
char profile_id[2];
char recieve_options;
char data[XBEE_BUFFER_SIZE];
} XBEE_RX_EXPLICIT_COMMAND_FRAME;
#define XBEE_RX_EXPLICIT_COMMAND_FRAME_SIZE 18
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
char remote_options;
char command[2];
char data[XBEE_BUFFER_SIZE];
} XBEE_TX_REMOTE_AT_COMMAND_FRAME;
#define XBEE_TX_REMOTE_AT_COMMAND_FRAME_SIZE 15
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char command[2];
char command_status;
char command_data[4];
} XBEE_RX_REMOTE_AT_COMMAND_FRAME;
#define XBEE_RX_REMOTE_AT_COMMAND_FRAME_SIZE 19
 
typedef struct {
char frame_type;
char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
char route_options;
char num_of_addresses;
char addresses[XBEE_BUFFER_SIZE];
} XBEE_TX_CREATE_SOURCE_ROUTE_FRAME;
#define XBEE_TX_CREATE_SOURCE_ROUTE_FRAME_SIZE 14
 
typedef struct {
char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char recieve_options;
char num_of_addresses;
char addresses[XBEE_BUFFER_SIZE];
} XBEE_RX_ROUTE_RECORD_FRAME;
#define XBEE_RX_ROUTE_RECORD_FRAME_SIZE 13
 
typedef struct {
char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
char recieve_options;
XBEE_ADDRESS_16 remote_16;
XBEE_ADDRESS_64 remote_64;
char NI_string[2];
XBEE_ADDRESS_16 parent_16;
char device_type;
char source_event;
char profile_id[2];
char manufacturer_id[2];
} XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME;
#define XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME_SIZE 32
 
typedef struct {
char frame_type;
char status;
} XBEE_RX_MODEM_STATUS_FRAME;
#define XBEE_RX_MODEM_STATUS_FRAME_SIZE 2
 
// Common Frame Components
typedef struct {
char start_delimiter;
XBEE_ADDRESS_16 length;
union {
XBEE_TX_AT_COMMAND_FRAME TX_AT_COMMAND;
XBEE_TX_AT_COMMAND_QUEUE_FRAME TX_AT_COMMAND_QUEUE;
XBEE_RX_AT_COMMAND_RESPONSE_FRAME RX_AT_COMMAND_RESPONSE;
XBEE_TX_DATA_PACKET_FRAME TX_DATA_PACKET;
XBEE_RX_DATA_PACKET_FRAME RX_DATA_PACKET;
XBEE_RX_DATA_TX_STATUS_FRAME RX_DATA_TX_STATUS;
XBEE_RX_IO_DATA_SAMPLE_FRAME RX_IO_DATA_SAMPLE;
XBEE_TX_EXPLICIT_COMMAND_FRAME TX_EXPLICIT_COMMAND;
XBEE_RX_EXPLICIT_COMMAND_FRAME RX_EXPLICIT_COMMAND;
XBEE_TX_REMOTE_AT_COMMAND_FRAME TX_REMOTE_AT_COMMAND;
XBEE_RX_REMOTE_AT_COMMAND_FRAME RX_REMOTE_AT_COMMAND;
XBEE_TX_CREATE_SOURCE_ROUTE_FRAME TX_CREATE_SOURCE_ROUTE;
XBEE_RX_ROUTE_RECORD_FRAME RX_ROUTE_RECORD;
XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME RX_NODE_IDENTIFICATION;
XBEE_RX_MODEM_STATUS_FRAME RX_MODEM_STATUS;
} FRAME;
} XBEE_FRAME;
 
// Overall Data Structure
typedef struct {
XBEE_FRAME rcv_frame;
unsigned int dataind;
char checksum_sum;
char read_state;
char frame_rdy;
char escape_flag;
} XBEE_DATA;
 
 
void XBee_Init(XBEE_DATA *data);
void XBee_Serial_In(char);
void XBee_Process_Received_Frame(void);
void XBee_Process_Transmit_Frame(char *data, char length);
 
unsigned int XBee_Get_Received_Frame(char *frame);
 
void XBee_Set_RTS(char);
char XBee_Read_CTS(void);
 
void XBee_Convert_Endian_64(XBEE_ADDRESS_64 *src);
void XBee_Convert_Endian_16(XBEE_ADDRESS_16 *src);
 
#endif
/PIC Projects/PICX_27J13/display_led_HT16K33.c
0,0 → 1,132
#include "display_led_HT16K33.h"
#include "base_I2C.h"
 
static const char numbertable[] = {
0x3F /* 0 */,
0x06 /* 1 */,
0x5B /* 2 */,
0x4F /* 3 */,
0x66 /* 4 */,
0x6D /* 5 */,
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F, /* 9 */
};
 
static const char alphatable[] = {
0x77, /* a */
0x7C, /* b */
0x39, /* C */
0x5E, /* d */
0x79, /* E */
0x71, /* F */
};
 
static LED_DATA *led_data_p;
 
void LED_Init(LED_DATA *data) {
led_data_p = data;
led_data_p->i2c_address = HT16K33_ADDRESS;
}
 
void LED_Start() {
char c = 0x21; // Cmd to turn on oscillator
I2C_Master_Send(led_data_p->i2c_address, 1, &c);
char result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
 
LED_Blink_Rate(HT16K33_BLINK_OFF);
LED_Set_Brightness(15); // Max brightness
LED_Clear();
LED_Write_Display();
}
 
void LED_Set_Brightness(char c) {
if (c > 15) c = 15;
c |= 0xE0;
 
I2C_Master_Send(led_data_p->i2c_address, 1, &c);
char result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
}
 
void LED_Blink_Rate(char c) {
char buffer;
 
if (c > 3) c = 0;
 
buffer = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (c << 1);
 
I2C_Master_Send(led_data_p->i2c_address, 1, &buffer);
buffer = I2C_Get_Status();
while (!buffer) {
buffer = I2C_Get_Status();
}
}
 
void LED_Write_Display() {
led_data_p->display_buffer[0] = 0x00; // Start at address 0x00
I2C_Master_Send(led_data_p->i2c_address, 17, led_data_p->display_buffer);
 
char result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
}
 
void LED_Clear() {
for (char c = 0; c < 17; c++) {
led_data_p->display_buffer[c] = 0;
}
}
 
void LED_Draw_Colon(char c) {
if (c) {
led_data_p->display_buffer[5] = 0xFF;
} else {
led_data_p->display_buffer[5] = 0;
}
}
 
void LED_Write_Digit_Raw(char loc, char bitmask) {
if (loc > 4) return;
led_data_p->display_buffer[(loc<<1)+1] = bitmask;
}
 
void LED_Write_Digit_Num(char loc, char num, char dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, numbertable[num] | dot << 7);
}
 
void LED_Write_Digit_Alpha(char loc, char alpha, char dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, alphatable[alpha] | dot << 7);
}
 
void LED_Write_Num(int i) {
LED_Write_Digit_Num(0, (i%10000)/1000, 0);
LED_Write_Digit_Num(1, (i%1000)/100, 0);
LED_Write_Digit_Num(2, (i%100)/10, 0);
LED_Write_Digit_Num(3, i%10, 0);
 
if (i < 10) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
LED_Write_Digit_Raw(3, 0);
} else if (i < 100) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
} else if (i < 1000) {
LED_Write_Digit_Raw(0, 0);
}
LED_Write_Display();
}
/PIC Projects/PICX_27J13/display_led_HT16K33.h
0,0 → 1,34
#ifndef LED_BACKPACK_H
#define LED_BACKPACK_H
 
#define HT16K33_ADDRESS 0x70
 
#define HT16K33_BLINK_CMD 0x80
#define HT16K33_BLINK_DISPLAYON 0x01
#define HT16K33_BLINK_OFF 0
#define HT16K33_BLINK_2HZ 1
#define HT16K33_BLINK_1HZ 2
#define HT16K33_BLINK_HALFHZ 3
 
#define HT16K33_CMD_BRIGHTNESS 0x0E
 
typedef struct {
char i2c_address;
char display_buffer[17];
} LED_DATA;
 
void LED_Init(LED_DATA *data);
void LED_Start(void);
void LED_Set_Brightness(char c);
void LED_Blink_Rate(char c);
void LED_Write_Display(void);
void LED_Clear(void);
void LED_Draw_Colon(char c);
void LED_Write_Digit_Raw(char loc, char bitmask);
void LED_Write_Digit_Num(char loc, char num, char dot);
void LED_Write_Digit_Alpha(char loc, char alpha, char dot);
void LED_Write_Num(int i);
 
 
#endif /* LED_BACKPACK_H */
 
/PIC Projects/PICX_27J13/display_oled_NHD-0216KZW-AB5.c
0,0 → 1,202
#include <xc.h>
#include <delays.h>
#include <string.h>
#include <stdio.h>
#include "display_oled_NHD-0216KZW-AB5.h"
#include "defines.h"
 
static OLED_CHAR_DATA *oled_char_data_p;
 
void NHD_Init(OLED_CHAR_DATA *data) {
oled_char_data_p = data;
PARALLEL_RS_TRIS = 0;
PARALLEL_RW_TRIS = 0;
PARALLEL_EN_TRIS = 0;
 
PARALLEL_D4_TRIS = 0;
PARALLEL_D5_TRIS = 0;
PARALLEL_D6_TRIS = 0;
PARALLEL_D7_TRIS = 0;
 
oled_char_data_p->display_function = LCD_FUNCTIONSET | LCD_4BITMODE;
}
 
void NHD_Begin(char cols, char rows) {
oled_char_data_p->num_lines = rows;
oled_char_data_p->current_line = 0;
 
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 0;
PARALLEL_EN_LAT = 0;
 
PARALLEL_D4_LAT = 0;
PARALLEL_D5_LAT = 0;
PARALLEL_D6_LAT = 0;
PARALLEL_D7_LAT = 0;
Delay10KTCYx(1); // ~1ms
 
// Initialization sequence
NHD_Write_4_Bits(0x3);
NHD_Write_4_Bits(0x2);
NHD_Write_4_Bits(0x2);
NHD_Write_4_Bits(0x8);
NHD_Wait_For_Ready();
 
NHD_Send_Command(0x08); // Turn Off
NHD_Send_Command(0x01); // Clear Display
NHD_Send_Command(0x06); // Set Entry Mode
NHD_Send_Command(0x02); // Return to Home Position
NHD_Send_Command(0x0C); // Turn On
}
 
void NHD_Clear() {
NHD_Send_Command(LCD_CLEARDISPLAY);
}
 
void NHD_Home() {
NHD_Send_Command(LCD_RETURNHOME);
}
 
void NHD_Set_Cursor(char col, char row) {
char row_offsets[] = {0x00, 0x40, 0x14, 0x54};
if (row >= oled_char_data_p->num_lines) {
row = 0;
}
NHD_Send_Command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
 
void NHD_Display(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_DISPLAYON;
} else {
oled_char_data_p->display_control &= ~LCD_DISPLAYON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Blink(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_BLINKON;
} else {
oled_char_data_p->display_control &= ~LCD_BLINKON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Cursor(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_CURSORON;
} else {
oled_char_data_p->display_control &= ~LCD_CURSORON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Scroll_Display_Left() {
NHD_Send_Command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
 
void NHD_Scroll_Display_Right() {
NHD_Send_Command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
 
void NHD_Left_To_Rigtht() {
oled_char_data_p->display_mode |= LCD_ENTRYLEFT;
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Right_To_Left() {
oled_char_data_p->display_mode &= ~LCD_ENTRYLEFT;
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Autoscroll(char option) {
if (option) {
oled_char_data_p->display_mode |= LCD_ENTRYSHIFTINCREMENT;
} else {
oled_char_data_p->display_mode &= ~LCD_ENTRYSHIFTINCREMENT;
}
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Create_Char(char location, char *charmap) {
location &= 0x7;
NHD_Send_Command(LCD_SETCGRAMADDR | (location << 3));
for (char i = 0; i < 8; i++) {
NHD_Send_Data(charmap[i]);
}
}
 
void NHD_Send_Command(char value) {
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 0;
NHD_Write_4_Bits(value>>4);
NHD_Write_4_Bits(value);
NHD_Wait_For_Ready();
}
 
void NHD_Send_Data(char value) {
PARALLEL_RS_LAT = 1;
PARALLEL_RW_LAT = 0;
NHD_Write_4_Bits(value>>4);
NHD_Write_4_Bits(value);
NHD_Wait_For_Ready();
}
 
void NHD_Pulse_Enable(void) {
PARALLEL_EN_LAT = 1;
Nop();
Nop();
PARALLEL_EN_LAT = 0;
}
 
void NHD_Write_4_Bits(char value) {
PARALLEL_D4_LAT = (value) & 0x01;
PARALLEL_D5_LAT = (value>>1) & 0x01;
PARALLEL_D6_LAT = (value>>2) & 0x01;
PARALLEL_D7_LAT = (value>>3) & 0x01;
NHD_Pulse_Enable();
}
 
void NHD_Wait_For_Ready() {
char busy;
PARALLEL_BUSY_TRIS = 1;
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 1;
do {
NHD_Pulse_Enable();
Nop();
busy = PARALLEL_BUSY_PORT;
NHD_Pulse_Enable();
} while (busy);
PARALLEL_BUSY_TRIS = 0;
PARALLEL_RW_LAT = 0;
}
 
void NHD_Write_String(char* msg, char length) {
for (char i = 0; i < length; i++) {
NHD_Send_Data(msg[i]);
}
}
 
//void NHD_Write_String(const rom char *fmt, ...) {
// unsigned char i, len;
// unsigned char buffer[NHD_STRING_BUFFER_SIZE];
//
// // Parse and create string
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) buffer, fmt, args);
// va_end(args);
// len = strlen((char *) buffer);
//
// // Make sure string to insert fits in buffer, truncate if necessary
// if (len > NHD_STRING_BUFFER_SIZE)
// len = NHD_STRING_BUFFER_SIZE;
//
// // Print buffer to string
// for (i = 0; i < len; i++) {
// NHD_Send_Data(buffer[i]);
// }
//}
/PIC Projects/PICX_27J13/display_oled_NHD-0216KZW-AB5.h
0,0 → 1,79
#ifndef OLED_NHD_0216KZW_AB5_H
#define OLED_NHD_0216KZW_AB5_H
 
//#define NHD_STRING_BUFFER_SIZE 64
 
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x28
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
 
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
 
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
 
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
 
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_JAPANESE 0x00
#define LCD_EUROPEAN_I 0x01
#define LCD_RUSSIAN 0x02
#define LCD_EUROPEAN_II 0x03
 
typedef struct {
unsigned char display_function;
unsigned char display_control;
unsigned char display_mode;
unsigned char current_line;
unsigned char num_lines;
} OLED_CHAR_DATA;
 
void NHD_Init(OLED_CHAR_DATA *data);
void NHD_Begin(char cols, char rows);
void NHD_Clear(void);
void NHD_Home(void);
void NHD_Display(char option);
void NHD_Blink(char option);
void NHD_Cursor(char option);
void NHD_Autoscroll(char option);
void NHD_Scroll_Display_Left(void);
void NHD_Scroll_Display_Right(void);
void NHD_Left_To_Rigtht(void);
void NHD_Right_To_Left(void);
 
void NHD_Create_Char(char location, char *charmap);
void NHD_Set_Cursor(char col, char row);
 
void NHD_Send_Data(char value);
void NHD_Send_Command(char value);
 
void NHD_Pulse_Enable(void);
void NHD_Write_4_Bits(char value);
void NHD_Wait_For_Ready(void);
 
void NHD_Write_String(char *msg, char length);
//void NHD_Write_String(const rom char *fmt, ...);
 
#endif /* OLED_NHD_0216KZW_AB5_H */
 
/PIC Projects/PICX_27J13/display_oled_ssd1306.c
0,0 → 1,835
#include <xc.h>
#include <delays.h>
#include <string.h>
#include <stdio.h>
#include "defines.h"
#include "base_SPI.h"
#include "display_oled_ssd1306.h"
#include "glcdfont.c"
#include "base_UART.h"
 
static SSD1306_DATA *ssd1306_data_p;
 
// 512 (128x32) or 1024 (128x64) bytes allocated for LCD buffer
// See linker file for details
static char LCD_BUFFER[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8,
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80,
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF,
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF,
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F,
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00,
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F,
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00,
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E,
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC,
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06,
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8,
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C,
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F,
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07,
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#endif
};
 
int SSD1306_Abs(int i) {
if (i < 0)
return -i;
else
return i;
}
 
void SSD1306_Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
 
void SSD1306_Init(SSD1306_DATA *data) {
ssd1306_data_p = data;
ssd1306_data_p->_width = ssd1306_data_p->WIDTH = SSD1306_LCDWIDTH;
ssd1306_data_p->_height = ssd1306_data_p->HEIGHT = SSD1306_LCDHEIGHT;
ssd1306_data_p->rotation = 0;
ssd1306_data_p->cursor_x = ssd1306_data_p->cursor_y = 0;
ssd1306_data_p->textsize = 1;
ssd1306_data_p->textcolor = SSD1306_WHITE;
ssd1306_data_p->textbgcolor = SSD1306_BLACK;
ssd1306_data_p->wrap = 1;
}
 
void SSD1306_Begin(char vccstate) {
// Toggle reset pin
SPI_RESET_LAT = 0;
Delay10KTCYx(1);
SPI_RESET_LAT = 1;
 
#if defined SSD1306_128_32
// Init sequence for 128x32 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x1F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x02);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
SSD1306_Command(0x8F);
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
#if defined SSD1306_128_64
// Init sequence for 128x64 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x3F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x12);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x9F);
} else {
SSD1306_Command(0xCF);
}
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
SSD1306_Command(SSD1306_DISPLAYON); // Turn on OLED panel
}
 
void SSD1306_Command(char cmd) {
char c = cmd;
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(&c, 1);
}
 
void SSD1306_Data(char data) {
char c = data;
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(&c, 1);
}
 
void SSD1306_Clear_Display() {
memset(LCD_BUFFER, 0, (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8));
}
 
void SSD1306_Invert_Display(char c) {
if (c) {
SSD1306_Command(SSD1306_INVERTDISPLAY);
} else {
SSD1306_Command((SSD1306_NORMALDISPLAY));
}
}
 
void SSD1306_Display() {
SSD1306_Command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
SSD1306_Command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // line #0
 
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(LCD_BUFFER, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
 
// if (SSD1306_LCDHEIGHT == 32) {
// SPI2_Write_Repeat(0, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
// }
}
 
void SSD1306_Draw_Pixel(int x, int y, unsigned int color) {
if ((x < 0) || (x >= ssd1306_data_p->_width) || (y < 0) || (y >= ssd1306_data_p->_height))
return;
 
// check rotation, move pixel around if necessary
switch (ssd1306_data_p->rotation) {
case 1:
SSD1306_Swap(&x, &y);
x = SSD1306_LCDWIDTH - x - 1;
break;
case 2:
x = SSD1306_LCDWIDTH - x - 1;
y = SSD1306_LCDHEIGHT - y - 1;
break;
case 3:
SSD1306_Swap(&x, &y);
y = SSD1306_LCDHEIGHT - y - 1;
break;
default:
break;
}
 
// Need to do this for some reason since x + (y / 8) * SSD1306_LCDWIDTH returns -128?!
// TODO: Change this back when they fix the compiler
int loc = (y / 8) * SSD1306_LCDWIDTH;
loc += x;
// x is which column
if (color == SSD1306_WHITE) {
LCD_BUFFER[loc] |= 1<<(y % 8);
} else {
LCD_BUFFER[loc] &= ~(1<<(y % 8));
}
}
 
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color) {
int dx, dy, err, ystep;
int steep = SSD1306_Abs(y1 - y0) > SSD1306_Abs(x1 - x0);
if (steep) {
SSD1306_Swap(&x0, &y0);
SSD1306_Swap(&x1, &y1);
}
 
if (x0 > x1) {
SSD1306_Swap(&x0, &x1);
SSD1306_Swap(&y0, &y1);
}
 
dx = x1 - x0;
dy = SSD1306_Abs(y1 - y0);
 
err = dx / 2;
 
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
 
for (; x0 <= x1; x0++) {
 
if (steep) {
SSD1306_Draw_Pixel(y0, x0, color);
} else {
SSD1306_Draw_Pixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
 
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color) {
SSD1306_Draw_Line(x, y, x, y + h - 1, color);
}
 
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color) {
SSD1306_Draw_Line(x, y, x + w - 1, y, color);
}
 
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color) {
SSD1306_Draw_Fast_HLine(x, y, w, color);
SSD1306_Draw_Fast_HLine(x, y + h, w, color);
SSD1306_Draw_Fast_VLine(x, y, h, color);
SSD1306_Draw_Fast_VLine(x + w, y, h, color);
}
 
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color) {
int i;
for (i = x; i < x + w; i++) {
SSD1306_Draw_Fast_VLine(i, y, h, color);
}
}
 
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
SSD1306_Draw_Pixel(x0, y0 + r, color);
SSD1306_Draw_Pixel(x0, y0 - r, color);
SSD1306_Draw_Pixel(x0 + r, y0, color);
SSD1306_Draw_Pixel(x0 - r, y0, color);
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
}
}
 
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, char cornername, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
}
}
}
 
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color) {
SSD1306_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
SSD1306_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
}
 
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, char cornername, int delta, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
if (cornername & 0x1) {
SSD1306_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
 
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
SSD1306_Draw_Line(x0, y0, x1, y1, color);
SSD1306_Draw_Line(x1, y1, x2, y2, color);
SSD1306_Draw_Line(x2, y2, x0, y0, color);
}
 
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
int a, b, y, last;
int dx01 = x1 - x0;
int dy01 = y1 - y0;
int dx02 = x2 - x0;
int dy02 = y2 - y0;
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int sa = 0;
int sb = 0;
 
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
if (y1 > y2) {
SSD1306_Swap(&y2, &y1);
SSD1306_Swap(&x2, &x1);
}
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
 
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
SSD1306_Draw_Fast_HLine(a, y0, b - a + 1, color);
return;
}
 
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
 
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
 
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
}
 
void SSD1306_Draw_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1306_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
SSD1306_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
SSD1306_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
SSD1306_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
 
// draw four corners
SSD1306_Draw_Circle_Helper(x + r, y + r, r, 1, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
SSD1306_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
}
 
void SSD1306_Fill_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1306_Fill_Rect(x + r, y, w - 2 * r, h, color);
 
// draw four corners
SSD1306_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
SSD1306_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
 
void SSD1306_Draw_Bitmap(int x, int y, const char* bitmap, int w, int h, unsigned int color) {
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (bitmap[i + (j / 8) * w] & (j % 8)) {
SSD1306_Draw_Pixel(x + i, y + j, color);
}
}
}
}
 
void SSD1306_Draw_Char(int x, int y, char c, unsigned int color, unsigned int bg, char size) {
int i, j;
unsigned int line;
 
if ((x >= ssd1306_data_p->_width) || // Clip right
(y >= ssd1306_data_p->_height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
 
for (i = 0; i < 6; i++) {
if (i == 5)
line = 0x0;
else
line = font[(c * 5) + i];
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) {// default size
SSD1306_Draw_Pixel(x + i, y + j, color);
} else { // big size
SSD1306_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
}
} else if (bg != color) {
if (size == 1) { // default size
SSD1306_Draw_Pixel(x + i, y + j, bg);
} else { // big size
SSD1306_Fill_Rect(x + i*size, y + j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
 
void SSD1306_Write(char c) {
if (c == '\n' || c == '\r') {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
// } else if (c == '\r') {
// // skip em
} else {
SSD1306_Draw_Char(ssd1306_data_p->cursor_x, ssd1306_data_p->cursor_y, c, ssd1306_data_p->textcolor, ssd1306_data_p->textbgcolor, ssd1306_data_p->textsize);
ssd1306_data_p->cursor_x += ssd1306_data_p->textsize * 6;
if (ssd1306_data_p->wrap && (ssd1306_data_p->cursor_x > (ssd1306_data_p->_width - ssd1306_data_p->textsize * 6))) {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
}
}
}
 
void SSD1306_Write_String(char* msg, char length) {
for (char i = 0; i < length; i++) {
SSD1306_Write(msg[i]);
}
}
 
//void SSD1306_Write_String(const rom char *fmt, ...) {
// char i, len;
// char buffer[SSD1306_STRING_BUFFER_SIZE];
//
// // Parse and create string
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) buffer, fmt, args);
// va_end(args);
// len = strlen((char *) buffer);
//
// // Make sure string to insert fits in buffer, truncate if necessary
// if (len > SSD1306_STRING_BUFFER_SIZE)
// len = SSD1306_STRING_BUFFER_SIZE;
//
// // Print buffer to string
// for (i = 0; i < len; i++) {
// SSD1306_Write(buffer[i]);
// }
//}
 
//void SSD1306_Append_String(const rom char *fmt, ...) {
// char i, len;
// char buffer[SSD1306_STRING_BUFFER_SIZE];
//
// // Parse and create string
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) buffer, fmt, args);
// va_end(args);
//
// // Make sure string to insert fits in buffer, truncate if necessary
// len = strlen((char *) buffer);
//
// if (len == 1) { // This will only occur on "\n"
// // Do nothing?
// return;
// }
//
// if (len > SSD1306_STRING_BUFFER_SIZE)
// len = SSD1306_STRING_BUFFER_SIZE;
//
// // Omit the newline if string fill entire line
// if (((len - 1)%(ssd1306_data_p->_width / 6)) == 0) { // 16 or 10
// len -= 1;
// }
//
// // Shift everything right and insert string at beginning
// for (i = 127; i > len - 1; i--) {
// ssd1306_data_p->lcd_buffer[i] = ssd1306_data_p->lcd_buffer[i - len];
// }
// memcpy((char *)ssd1306_data_p->lcd_buffer, (const char *) buffer, len);
//
// // Print full buffer to screen
// SSD1306_Clear_Display();
// SSD1306_Display();
//
// SSD1306_Set_Cursor(0,0);
// for (i = 0; i < SSD1306_LCD_BUFFER_SIZE-1; i++) {
// SSD1306_Write(ssd1306_data_p->lcd_buffer[i]);
// }
//}
 
void SSD1306_Set_Cursor(int x, int y) {
ssd1306_data_p->cursor_x = x;
ssd1306_data_p->cursor_y = y;
}
 
void SSD1306_Set_Text_Color(unsigned int c) {
// for 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = c;
}
 
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg) {
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = bg;
}
 
void SSD1306_Set_Text_Size(char s) {
ssd1306_data_p->textsize = (s > 0) ? s : 1;
}
 
void SSD1306_Set_Text_Wrap(char w) {
ssd1306_data_p->wrap = w;
}
 
void SSD1306_Set_Rotation(char x) {
x %= 4; // cant be higher than 3
ssd1306_data_p->rotation = x;
switch (x) {
case 0:
case 2:
ssd1306_data_p->_width = ssd1306_data_p->WIDTH;
ssd1306_data_p->_height = ssd1306_data_p->HEIGHT;
break;
case 1:
case 3:
ssd1306_data_p->_width = ssd1306_data_p->HEIGHT;
ssd1306_data_p->_height = ssd1306_data_p->WIDTH;
break;
}
}
 
 
 
void SSD1306_Test_DrawChar() {
char i;
SSD1306_Set_Text_Size(1);
SSD1306_Set_Text_Color(SSD1306_WHITE);
SSD1306_Set_Cursor(0, 0);
 
for (i = 0; i < 168; i++) {
if (i == '\n') continue;
SSD1306_Write(i);
// if ((i > 0) && (i % 21 == 0))
// SSD1306_write('\n');
}
SSD1306_Display();
}
 
void SSD1306_Test_DrawCircle() {
int i;
for (i = 0; i < ssd1306_data_p->_height; i += 2) {
SSD1306_Draw_Circle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2, i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRect(void) {
int i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 2) {
SSD1306_Draw_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRect(void) {
char color = 1;
int i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 3) {
// alternate colors
SSD1306_Fill_Rect(i, i, ssd1306_data_p->_width - i * 2, ssd1306_data_p->_height - i * 2, color % 2);
SSD1306_Display();
color++;
}
}
 
void SSD1306_Test_DrawTriangle(void) {
int i;
int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = 0; i < min / 2; i += 5) {
SSD1306_Draw_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillTriangle(void) {
char color = SSD1306_WHITE;
int i;
int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = min / 2; i > 0; i -= 5) {
SSD1306_Fill_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRoundRect(void) {
int i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Draw_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRoundRect(void) {
char color = SSD1306_WHITE;
int i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Fill_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, color);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawLine(void) {
int i;
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(0, 0, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = ssd1306_data_p->_width - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
}
/PIC Projects/PICX_27J13/display_oled_ssd1306.h
0,0 → 1,132
#ifndef OLED_SSD1306_H
#define OLED_SSD1306_H
 
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
 
SSD1306_128_64 128x64 pixel display
 
SSD1306_128_32 128x32 pixel display
 
You also need to set the LCDWIDTH and LCDHEIGHT defines to an
appropriate size
 
-----------------------------------------------------------------------*/
#define SSD1306_128_64
// #define SSD1306_128_32
/*=========================================================================*/
 
#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 32
#endif
 
//#define SSD1306_STRING_BUFFER_SIZE 32
 
#define SSD1306_BLACK 0
#define SSD1306_WHITE 1
 
#define SSD1306_I2C_ADDRESS 0x3D // 011110+SA0+RW
 
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
 
typedef struct {
int WIDTH, HEIGHT; // raw display size
int _width, _height; // size depending on rotation
int cursor_x, cursor_y;
unsigned int textcolor, textbgcolor;
char textsize;
char rotation;
char wrap; // If set, wrap text at right side
} SSD1306_DATA;
 
// Misc functions
int SSD1306_Abs(int i);
void SSD1306_Swap(int *a, int *b);
 
// Core functions
void SSD1306_Init(SSD1306_DATA *data);
void SSD1306_Begin(char vcc);
void SSD1306_Command(char cmd);
void SSD1306_Data(char data);
 
void SSD1306_Clear_Display(void);
void SSD1306_Invert_Display(char);
void SSD1306_Display(void);
 
// Drawing functions
void SSD1306_Draw_Pixel(int x, int y, unsigned int color);
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color);
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color);
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color);
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color);
 
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color);
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, char cornername, unsigned int color);
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color);
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, char cornername, int delta, unsigned int color);
 
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1306_Draw_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
void SSD1306_Fill_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
 
void SSD1306_Draw_Bitmap(int x, int y, const char *bitmap, int w, int h, unsigned int color);
void SSD1306_Draw_Char(int x, int y, char c, unsigned int color, unsigned int bg, char size);
 
void SSD1306_Write(char c);
void SSD1306_Write_String(char *msg, char length);
//void SSD1306_Write_String(const rom char *fmt, ...);
//void SSD1306_Append_String(const rom char *fmt, ...);
 
void SSD1306_Set_Cursor(int x, int y);
void SSD1306_Set_Text_Color(unsigned int c);
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg);
void SSD1306_Set_Text_Size(char s);
void SSD1306_Set_Text_Wrap(char w);
void SSD1306_Set_Rotation(char r);
 
// Test functions
void SSD1306_Test_DrawChar(void);
void SSD1306_Test_DrawCircle(void);
void SSD1306_Test_DrawRect(void);
void SSD1306_Test_FillRect(void);
void SSD1306_Test_DrawTriangle(void);
void SSD1306_Test_FillTriangle(void);
void SSD1306_Test_DrawRoundRect(void);
void SSD1306_Test_FillRoundRect(void);
void SSD1306_Test_DrawLine(void);
 
#endif /* OLED_SSD1306_H */
 
/PIC Projects/PICX_27J13/display_oled_ssd1331.c
0,0 → 1,902
#include <xc.h>
#include <delays.h>
#include <string.h>
#include <stdio.h>
#include "defines.h"
#include "display_oled_ssd1331.h"
#include "base_SPI.h"
#include "string.h"
#include "glcdfont.c"
 
static SSD1331_DATA *ssd1331_data_p;
 
int SSD1331_Abs(int i) {
if (i < 0)
return -i;
else
return i;
}
 
void SSD1331_Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
 
void SSD1331_Init(SSD1331_DATA *data) {
ssd1331_data_p = data;
ssd1331_data_p->_width = ssd1331_data_p->WIDTH = SSD1331_LCDWIDTH;
ssd1331_data_p->_height = ssd1331_data_p->HEIGHT = SSD1331_LCDHEIGHT;
ssd1331_data_p->rotation = 0;
ssd1331_data_p->cursor_x = ssd1331_data_p->cursor_y = 0;
ssd1331_data_p->textsize = 1;
ssd1331_data_p->textcolor = ssd1331_data_p->textbgcolor = 0xFFFF;
ssd1331_data_p->wrap = 1;
}
 
void SSD1331_Begin() {
char buffer[37];
 
// Toggle reset pin
SPI_RESET_LAT = 0;
Delay10KTCYx(1);
SPI_RESET_LAT = 1;
 
// Initialization Sequence
buffer[0] = SSD1331_CMD_DISPLAYOFF; // 0xAE
buffer[1] = SSD1331_CMD_SETREMAP; // 0xA0
#if defined SSD1331_COLORORDER_RGB
buffer[2] = 0x72; // RGB Color
#else
buffer[2] = 0x76; // BGR Color
#endif
buffer[3] = SSD1331_CMD_STARTLINE; // 0xA1
buffer[4] = 0x0;
buffer[5] = SSD1331_CMD_DISPLAYOFFSET; // 0xA2
buffer[6] = 0x0;
buffer[7] = SSD1331_CMD_NORMALDISPLAY; // 0xA4
buffer[8] = SSD1331_CMD_SETMULTIPLEX; // 0xA8
buffer[9] = 0x3F; // 0x3F 1/64 duty
buffer[10] = SSD1331_CMD_SETMASTER; // 0xAD
buffer[11] = 0x8E;
buffer[12] = SSD1331_CMD_POWERMODE; // 0xB0
buffer[13] = 0x0B;
buffer[14] = SSD1331_CMD_PRECHARGE; // 0xB1
buffer[15] = 0x31;
buffer[16] = SSD1331_CMD_CLOCKDIV; // 0xB3
buffer[17] = 0xF0; // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
buffer[18] = SSD1331_CMD_PRECHARGEA; // 0x8A
buffer[19] = 0x64;
buffer[20] = SSD1331_CMD_PRECHARGEB; // 0x8B
buffer[21] = 0x78;
buffer[22] = SSD1331_CMD_PRECHARGEA; // 0x8C
buffer[23] = 0x64;
buffer[24] = SSD1331_CMD_PRECHARGELEVEL; // 0xBB
buffer[25] = 0x3A;
buffer[26] = SSD1331_CMD_VCOMH; // 0xBE
buffer[27] = 0x3E;
buffer[28] = SSD1331_CMD_MASTERCURRENT; // 0x87
buffer[29] = 0x06;
buffer[30] = SSD1331_CMD_CONTRASTA; // 0x81
buffer[31] = 0x91;
buffer[32] = SSD1331_CMD_CONTRASTB; // 0x82
buffer[33] = 0x50;
buffer[34] = SSD1331_CMD_CONTRASTC; // 0x83
buffer[35] = 0x7D;
buffer[36] = SSD1331_CMD_DISPLAYON; //--turn on oled panel
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 37);
}
 
void SSD1331_GoTo(int x, int y) {
char buffer[6];
if ((x >= SSD1331_LCDWIDTH) || (y >= SSD1331_LCDHEIGHT)) return;
 
// set x and y coordinate
buffer[0] = (SSD1331_CMD_SETCOLUMN);
buffer[1] = (x); // Start x address
buffer[2] = (SSD1331_LCDWIDTH - 1); // End x address
 
buffer[3] = (SSD1331_CMD_SETROW);
buffer[4] = (y); // Start y address
buffer[5] = (SSD1331_LCDHEIGHT - 1); // End y address
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 6);
}
 
void SSD1331_Command(char cmd) {
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(&cmd, 1);
}
 
void SSD1331_Data(char data) {
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(&data, 1);
}
 
void SSD1331_Clear_Display() {
char buffer[5];
 
buffer[0] = SSD1331_CMD_CLEARWINDOW;
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = SSD1331_LCDWIDTH-1;
buffer[4] = SSD1331_LCDHEIGHT-1;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 5);
 
Delay1KTCYx(4);
}
 
void SSD1331_Draw_Pixel(int x, int y, unsigned int color) {
char buffer[2];
buffer[0] = color >> 8;
buffer[1] = color;
if ((x < 0) || (x >= ssd1331_data_p->_width) || (y < 0) || (y >= ssd1331_data_p->_height)) return;
 
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 1:
SSD1331_Swap(&x, &y);
x = SSD1331_LCDWIDTH - x - 1;
break;
case 2:
x = SSD1331_LCDWIDTH - x - 1;
y = SSD1331_LCDHEIGHT - y - 1;
break;
case 3:
SSD1331_Swap(&x, &y);
y = SSD1331_LCDHEIGHT - y - 1;
break;
}
 
SSD1331_GoTo(x, y);
 
// setup for data
SPI_DC_SELECT_LAT = 1; // D/C high (data)
 
SPI2_Write(buffer, 2);
}
 
void SSD1331_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color) {
char buffer[8];
 
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 1:
SSD1331_Swap(&x0, &y0);
SSD1331_Swap(&x1, &y1);
x0 = SSD1331_LCDWIDTH - x0 - 1;
x1 = SSD1331_LCDWIDTH - x1 - 1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - x0 - 1;
y0 = SSD1331_LCDHEIGHT - y0 - 1;
x1 = SSD1331_LCDWIDTH - x1 - 1;
y1 = SSD1331_LCDHEIGHT - y1 - 1;
break;
case 3:
SSD1331_Swap(&x0, &y0);
SSD1331_Swap(&x1, &y1);
y0 = SSD1331_LCDHEIGHT - y0 - 1;
y1 = SSD1331_LCDHEIGHT - y1 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_DRAWLINE;
buffer[1] = x0;
buffer[2] = y0;
buffer[3] = x1;
buffer[4] = y1;
buffer[5] = (color >> 11) << 1;
buffer[6] = (color >> 5) & 0x3F;
buffer[7] = (color << 1) & 0x3F;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 8);
}
 
void SSD1331_Draw_Fast_VLine(int x, int y, int h, unsigned int color) {
SSD1331_Draw_Line(x, y, x, y + h - 1, color);
}
 
void SSD1331_Draw_Fast_HLine(int x, int y, int w, unsigned int color) {
SSD1331_Draw_Line(x, y, x + w - 1, y, color);
}
 
void SSD1331_Draw_Rect(int tx0, int ty0, int tx1, int ty1, unsigned int color) {
char buffer[13];
int x0,y0,x1,y1;
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 0:
x0 = tx0;
y0 = ty0;
x1 = tx1;
y1 = ty1;
break;
case 1:
x0 = SSD1331_LCDWIDTH - ty1 - 1;
y0 = tx0;
x1 = SSD1331_LCDWIDTH - ty0 - 1;
y1 = tx1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - tx1 - 1;
y0 = SSD1331_LCDHEIGHT - ty1 - 1;
x1 = SSD1331_LCDWIDTH - tx0 - 1;
y1 = SSD1331_LCDHEIGHT - ty0 - 1;
break;
case 3:
x0 = ty0;
y0 = SSD1331_LCDHEIGHT - tx1 - 1;
x1 = ty1;
y1 = SSD1331_LCDHEIGHT - tx0 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_FILL;
buffer[1] = 0;
buffer[2] = SSD1331_CMD_DRAWRECT;
buffer[3] = x0;
buffer[4] = y0;
buffer[5] = x1;
buffer[6] = y1;
buffer[7] = (color >> 11) << 1;
buffer[8] = (color >> 5) & 0x3F;
buffer[9] = (color << 1) & 0x3F;
buffer[10] = 0;
buffer[11] = 0;
buffer[12] = 0;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 13);
}
 
void SSD1331_Fill_Rect(int tx0, int ty0, int tx1, int ty1, unsigned int color) {
char buffer[13];
int x0,y0,x1,y1;
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 0:
x0 = tx0;
y0 = ty0;
x1 = tx1;
y1 = ty1;
break;
case 1:
x0 = SSD1331_LCDWIDTH - ty1 - 1;
y0 = tx0;
x1 = SSD1331_LCDWIDTH - ty0 - 1;
y1 = tx1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - tx1 - 1;
y0 = SSD1331_LCDHEIGHT - ty1 - 1;
x1 = SSD1331_LCDWIDTH - tx0 - 1;
y1 = SSD1331_LCDHEIGHT - ty0 - 1;
break;
case 3:
x0 = ty0;
y0 = SSD1331_LCDHEIGHT - tx1 - 1;
x1 = ty1;
y1 = SSD1331_LCDHEIGHT - tx0 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_FILL;
buffer[1] = 1;
buffer[2] = SSD1331_CMD_DRAWRECT;
buffer[3] = x0;
buffer[4] = y0;
buffer[5] = x1;
buffer[6] = y1;
buffer[7] = (color >> 11) << 1;
buffer[8] = (color >> 5) & 0x3F;
buffer[9] = (color << 1) & 0x3F;
buffer[10] = (color >> 11) << 1;
buffer[11] = (color >> 5) & 0x3F;
buffer[12] = (color << 1) & 0x3F;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 13);
 
Delay1KTCYx(4);
}
 
void SSD1331_Draw_Circle(int x0, int y0, int r, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
SSD1331_Draw_Pixel(x0, y0 + r, color);
SSD1331_Draw_Pixel(x0, y0 - r, color);
SSD1331_Draw_Pixel(x0 + r, y0, color);
SSD1331_Draw_Pixel(x0 - r, y0, color);
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
SSD1331_Draw_Pixel(x0 + x, y0 + y, color);
SSD1331_Draw_Pixel(x0 - x, y0 + y, color);
SSD1331_Draw_Pixel(x0 + x, y0 - y, color);
SSD1331_Draw_Pixel(x0 - x, y0 - y, color);
SSD1331_Draw_Pixel(x0 + y, y0 + x, color);
SSD1331_Draw_Pixel(x0 - y, y0 + x, color);
SSD1331_Draw_Pixel(x0 + y, y0 - x, color);
SSD1331_Draw_Pixel(x0 - y, y0 - x, color);
}
}
 
void SSD1331_Draw_Circle_Helper(int x0, int y0, int r, char cornername, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
SSD1331_Draw_Pixel(x0 + x, y0 + y, color);
SSD1331_Draw_Pixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
SSD1331_Draw_Pixel(x0 + x, y0 - y, color);
SSD1331_Draw_Pixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
SSD1331_Draw_Pixel(x0 - y, y0 + x, color);
SSD1331_Draw_Pixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
SSD1331_Draw_Pixel(x0 - y, y0 - x, color);
SSD1331_Draw_Pixel(x0 - x, y0 - y, color);
}
}
}
 
void SSD1331_Fill_Circle(int x0, int y0, int r, unsigned int color) {
SSD1331_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
SSD1331_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
}
 
void SSD1331_Fill_Circle_Helper(int x0, int y0, int r, char cornername, int delta, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
if (cornername & 0x1) {
SSD1331_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
SSD1331_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
SSD1331_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
SSD1331_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
void SSD1331_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
SSD1331_Draw_Line(x0, y0, x1, y1, color);
SSD1331_Draw_Line(x1, y1, x2, y2, color);
SSD1331_Draw_Line(x2, y2, x0, y0, color);
}
 
void SSD1331_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
int a, b, y, last;
int dx01 = x1 - x0;
int dy01 = y1 - y0;
int dx02 = x2 - x0;
int dy02 = y2 - y0;
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int sa = 0;
int sb = 0;
 
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
SSD1331_Swap(&y0, &y1);
SSD1331_Swap(&x0, &x1);
}
if (y1 > y2) {
SSD1331_Swap(&y2, &y1);
SSD1331_Swap(&x2, &x1);
}
if (y0 > y1) {
SSD1331_Swap(&y0, &y1);
SSD1331_Swap(&x0, &x1);
}
 
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
SSD1331_Draw_Fast_HLine(a, y0, b - a + 1, color);
return;
}
 
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
 
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1331_Swap(&a, &b);
SSD1331_Draw_Fast_HLine(a, y, b - a + 1, color);
}
 
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1331_Swap(&a, &b);
SSD1331_Draw_Fast_HLine(a, y, b - a + 1, color);
}
}
 
void SSD1331_Draw_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1331_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
SSD1331_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
SSD1331_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
SSD1331_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
 
// draw four corners
SSD1331_Draw_Circle_Helper(x + r, y + r, r, 1, color);
SSD1331_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
SSD1331_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
SSD1331_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
}
 
void SSD1331_Fill_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1331_Fill_Rect(x + r, y, w - 2 * r, h, color);
 
// draw four corners
SSD1331_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
SSD1331_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
 
void SSD1331_Draw_Bitmap(int x, int y, const char* bitmap, int w, int h, unsigned int color) {
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (bitmap[i + (j / 8) * w] & (j % 8)) {
SSD1331_Draw_Pixel(x + i, y + j, color);
}
}
}
}
 
void SSD1331_Draw_Char(int x, int y, char c, unsigned int color, unsigned int bg, char size) {
int i, j;
unsigned int line;
 
if ((x >= ssd1331_data_p->_width) || // Clip right
(y >= ssd1331_data_p->_height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
 
for (i = 0; i < 6; i++) {
if (i == 5)
line = 0x0;
else
line = font[(c * 5) + i];
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) {// default size
SSD1331_Draw_Pixel(x + i, y + j, color);
} else { // big size
SSD1331_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
}
} else if (bg != color) {
if (size == 1) { // default size
SSD1331_Draw_Pixel(x + i, y + j, bg);
} else { // big size
SSD1331_Fill_Rect(x + i*size, y + j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
 
void SSD1331_Write(char c) {
if (c == '\n' || c == '\r') {
ssd1331_data_p->cursor_y += ssd1331_data_p->textsize * 8;
ssd1331_data_p->cursor_x = 0;
// } else if (c == '\r') {
// // skip em
} else {
SSD1331_Draw_Char(ssd1331_data_p->cursor_x, ssd1331_data_p->cursor_y, c, ssd1331_data_p->textcolor, ssd1331_data_p->textbgcolor, ssd1331_data_p->textsize);
ssd1331_data_p->cursor_x += ssd1331_data_p->textsize * 6;
if (ssd1331_data_p->wrap && (ssd1331_data_p->cursor_x > (ssd1331_data_p->_width - ssd1331_data_p->textsize * 6))) {
ssd1331_data_p->cursor_y += ssd1331_data_p->textsize * 8;
ssd1331_data_p->cursor_x = 0;
}
}
}
 
void SSD1331_Write_String(char* msg, char length) {
for (char i = 0; i < length; i++) {
SSD1331_Write(msg[i]);
}
}
 
//void SSD1331_Write_String(const rom char *fmt, ...) {
// unsigned char i, len;
// unsigned char buffer[SSD1331_STRING_BUFFER_SIZE];
//
// // Parse and create string
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) buffer, fmt, args);
// va_end(args);
// len = strlen((char *) buffer);
//
// // Make sure string to insert fits in buffer, truncate if necessary
// if (len > SSD1331_STRING_BUFFER_SIZE)
// len = SSD1331_STRING_BUFFER_SIZE;
//
// // Print buffer to string
// for (i = 0; i < len; i++) {
// SSD1331_Write(buffer[i]);
// }
//}
 
void SSD1331_Set_Cursor(int x, int y) {
ssd1331_data_p->cursor_x = x;
ssd1331_data_p->cursor_y = y;
}
 
void SSD1331_Set_Text_Color(unsigned int c) {
// for 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
ssd1331_data_p->textcolor = c;
ssd1331_data_p->textbgcolor = c;
}
 
void SSD1331_Set_Text_Color_BG(unsigned int c, unsigned int bg) {
ssd1331_data_p->textcolor = c;
ssd1331_data_p->textbgcolor = bg;
}
 
void SSD1331_Set_Text_Size(char s) {
ssd1331_data_p->textsize = (s > 0) ? s : 1;
}
 
void SSD1331_Set_Text_Wrap(char w) {
ssd1331_data_p->wrap = w;
}
 
void SSD1331_Set_Rotation(char x) {
x %= 4; // cant be higher than 3
ssd1331_data_p->rotation = x;
switch (x) {
case 0:
case 2:
ssd1331_data_p->_width = ssd1331_data_p->WIDTH;
ssd1331_data_p->_height = ssd1331_data_p->HEIGHT;
break;
case 1:
case 3:
ssd1331_data_p->_width = ssd1331_data_p->HEIGHT;
ssd1331_data_p->_height = ssd1331_data_p->WIDTH;
break;
}
}
 
unsigned int SSD1331_Color565(char r, char g, char b) {
unsigned int c;
c = r >> 3;
c <<= 6;
c |= g >> 2;
c <<= 5;
c |= b >> 3;
 
return c;
}
 
void SSD1331_Test_DrawLines(unsigned int color) {
int x, y;
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(0, 0, x, ssd1331_data_p->_height - 1, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(0, 0, ssd1331_data_p->_width - 1, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, 0, x, ssd1331_data_p->_height - 1, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, 0, 0, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(0, ssd1331_data_p->_height - 1, x, 0, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(0, ssd1331_data_p->_height - 1, ssd1331_data_p->_width - 1, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, ssd1331_data_p->_height - 1, x, 0, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, ssd1331_data_p->_height - 1, 0, y, color);
}
}
 
void SSD1331_Test_DrawRect(unsigned int color) {
int x;
SSD1331_Clear_Display();
if (ssd1331_data_p->_height < ssd1331_data_p->_width) {
for (x = 0; x < ssd1331_data_p->_height - 1; x += 6) {
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color);
}
} else {
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color);
}
}
}
 
void SSD1331_Test_FillRect(unsigned int color1, unsigned int color2) {
int x;
SSD1331_Clear_Display();
if (ssd1331_data_p->_height < ssd1331_data_p->_width) {
for (x = ssd1331_data_p->_height - 1; x > 6; x -= 6) {
SSD1331_Fill_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color1);
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color2);
}
} else {
for (x = ssd1331_data_p->_width - 1; x > 6; x -= 6) {
SSD1331_Fill_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color1);
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color2);
}
}
}
 
void SSD1331_Test_DrawCircle(unsigned int radius, unsigned int color) {
int x, y;
for (x = 0; x < ssd1331_data_p->_width - 1 + radius; x += radius * 2) {
for (y = 0; y < ssd1331_data_p->_height - 1 + radius; y += radius * 2) {
SSD1331_Draw_Circle(x, y, radius, color);
}
}
}
 
void SSD1331_Test_FillCircle(unsigned int radius, unsigned int color) {
char x, y;
for (x = radius; x < ssd1331_data_p->_width - 1; x += radius * 2) {
for (y = radius; y < ssd1331_data_p->_height - 1; y += radius * 2) {
SSD1331_Fill_Circle(x, y, radius, color);
}
}
}
 
void SSD1331_Test_DrawTria(void) {
int color = 0xF800;
int t;
int w = ssd1331_data_p->_width / 2;
int x = ssd1331_data_p->_height;
int y = 0;
int z = ssd1331_data_p->_width;
SSD1331_Clear_Display();
for (t = 0; t <= 15; t += 1) {
SSD1331_Draw_Triangle(w, y, y, x, z, x, color);
x -= 4;
y += 4;
z -= 4;
color += 100;
}
}
 
void SSD1331_Test_DrawRoundRect(void) {
int color = 100;
int i, t, x, y, w, h;
SSD1331_Clear_Display();
for (t = 0; t <= 4; t += 1) {
x = 0;
y = 0;
w = ssd1331_data_p->_width;
h = ssd1331_data_p->_height;
for (i = 0; i <= 24; i += 1) {
SSD1331_Draw_Round_Rect(x, y, w, h, 5, color);
x += 2;
y += 3;
w -= 4;
h -= 6;
color += 1100;
}
color += 100;
}
}
 
void SSD1331_Test_MediaButtons(void) {
// play
SSD1331_Clear_Display();
SSD1331_Fill_Round_Rect(25, 10, 78, 60, 8, SSD1331_WHITE);
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_RED);
Delay10KTCYx(100);
// pause
SSD1331_Fill_Round_Rect(25, 90, 78, 60, 8, SSD1331_WHITE);
SSD1331_Fill_Round_Rect(39, 98, 20, 45, 5, SSD1331_GREEN);
SSD1331_Fill_Round_Rect(69, 98, 20, 45, 5, SSD1331_GREEN);
Delay10KTCYx(100);
// play color
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_BLUE);
Delay10KTCYx(100);
// pause color
SSD1331_Fill_Round_Rect(39, 98, 20, 45, 5, SSD1331_RED);
SSD1331_Fill_Round_Rect(69, 98, 20, 45, 5, SSD1331_RED);
// play color
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_GREEN);
}
 
void SSD1331_Test_Pattern(void) {
char buffer[2];
unsigned int i, j;
SSD1331_GoTo(0, 0);
 
for (i = 0; i < 64; i++) {
for (j = 0; j < 96; j++) {
if (i > 55) {
buffer[0] = (SSD1331_WHITE >> 8);
buffer[1] = (SSD1331_WHITE);
} else if (i > 47) {
buffer[0] = (SSD1331_BLUE >> 8);
buffer[1] = (SSD1331_BLUE);
} else if (i > 39) {
buffer[0] = (SSD1331_GREEN >> 8);
buffer[1] = (SSD1331_GREEN);
} else if (i > 31) {
buffer[0] = (SSD1331_CYAN >> 8);
buffer[1] = (SSD1331_CYAN);
} else if (i > 23) {
buffer[0] = (SSD1331_RED >> 8);
buffer[1] = (SSD1331_RED);
} else if (i > 15) {
buffer[0] = (SSD1331_MAGENTA >> 8);
buffer[1] = (SSD1331_MAGENTA);
} else if (i > 7) {
buffer[0] = (SSD1331_YELLOW >> 8);
buffer[1] = (SSD1331_YELLOW);
} else {
buffer[0] = (SSD1331_BLACK >> 8);
buffer[1] = (SSD1331_BLACK);
}
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(buffer, 2);
}
}
}
/PIC Projects/PICX_27J13/display_oled_ssd1331.h
0,0 → 1,123
#ifndef OLED_SSD1331_H
#define OLED_SSD1331_H
 
#define SSD1331_LCDWIDTH 96
#define SSD1331_LCDHEIGHT 64
//#define SSD1331_STRING_BUFFER_SIZE 64
 
// Select one of these defines to set the pixel color order
#define SSD1331_COLORORDER_RGB
// #define SSD1331_COLORORDER_BGR
 
// SSD1331 Commands
#define SSD1331_CMD_DRAWLINE 0x21
#define SSD1331_CMD_DRAWRECT 0x22
#define SSD1331_CMD_CLEARWINDOW 0x25
#define SSD1331_CMD_FILL 0x26
#define SSD1331_CMD_SETCOLUMN 0x15
#define SSD1331_CMD_SETROW 0x75
#define SSD1331_CMD_CONTRASTA 0x81
#define SSD1331_CMD_CONTRASTB 0x82
#define SSD1331_CMD_CONTRASTC 0x83
#define SSD1331_CMD_MASTERCURRENT 0x87
#define SSD1331_CMD_SETREMAP 0xA0
#define SSD1331_CMD_STARTLINE 0xA1
#define SSD1331_CMD_DISPLAYOFFSET 0xA2
#define SSD1331_CMD_NORMALDISPLAY 0xA4
#define SSD1331_CMD_DISPLAYALLON 0xA5
#define SSD1331_CMD_DISPLAYALLOFF 0xA6
#define SSD1331_CMD_INVERTDISPLAY 0xA7
#define SSD1331_CMD_SETMULTIPLEX 0xA8
#define SSD1331_CMD_SETMASTER 0xAD
#define SSD1331_CMD_DISPLAYOFF 0xAE
#define SSD1331_CMD_DISPLAYON 0xAF
#define SSD1331_CMD_POWERMODE 0xB0
#define SSD1331_CMD_PRECHARGE 0xB1
#define SSD1331_CMD_CLOCKDIV 0xB3
#define SSD1331_CMD_PRECHARGEA 0x8A
#define SSD1331_CMD_PRECHARGEB 0x8B
#define SSD1331_CMD_PRECHARGEC 0x8C
#define SSD1331_CMD_PRECHARGELEVEL 0xBB
#define SSD1331_CMD_VCOMH 0xBE
 
// Color definitions
#define SSD1331_BLACK 0x0000
#define SSD1331_BLUE 0x001F
#define SSD1331_RED 0xF800
#define SSD1331_GREEN 0x07E0
#define SSD1331_CYAN 0x07FF
#define SSD1331_MAGENTA 0xF81F
#define SSD1331_YELLOW 0xFFE0
#define SSD1331_WHITE 0xFFFF
 
typedef struct {
int WIDTH, HEIGHT; // raw display size
int _width, _height; // size depending on rotation
int cursor_x, cursor_y;
unsigned int textcolor, textbgcolor;
char textsize;
char rotation;
char wrap; // If set, wrap text at right side
} SSD1331_DATA;
 
// Misc functions
int SSD1331_Abs(int i);
void SSD1331_Swap(int *a, int *b);
unsigned int SSD1331_Color565(char r, char g, char b);
 
// Core functions
void SSD1331_Init(SSD1331_DATA *data);
void SSD1331_Begin(void);
void SSD1331_GoTo(int x, int y);
 
void SSD1331_Command(char c);
void SSD1331_Data(char d);
 
// Display functions
void SSD1331_Clear_Display(void);
 
void SSD1331_Draw_Pixel(int x, int y, unsigned int color);
void SSD1331_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1331_Draw_Fast_VLine(int x, int y, int h, unsigned int color);
void SSD1331_Draw_Fast_HLine(int x, int y, int w, unsigned int color);
void SSD1331_Draw_Rect(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1331_Fill_Rect(int x0, int y0, int x1, int y1, unsigned int color);
 
void SSD1331_Draw_Circle(int x0, int y0, int r, unsigned int color);
void SSD1331_Draw_Circle_Helper(int x0, int y0, int r, char cornername, unsigned int color);
void SSD1331_Fill_Circle(int x0, int y0, int r, unsigned int color);
void SSD1331_Fill_Circle_Helper(int x0, int y0, int r, char cornername, int delta, unsigned int color);
 
void SSD1331_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1331_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1331_Draw_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
void SSD1331_Fill_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
 
void SSD1331_Draw_Bitmap(int x, int y, const char *bitmap, int w, int h, unsigned int color);
void SSD1331_Draw_Char(int x, int y, char c, unsigned int color, unsigned int bg, char size);
 
void SSD1331_Write(char c);
void SSD1331_Write_String(char *msg, char length);
//void SSD1331_Write_String(const rom char *fmt, ...);
//void SSD1331_Append_String(const rom char *fmt, ...);
 
void SSD1331_Set_Cursor(int x, int y);
void SSD1331_Set_Text_Color(unsigned int c);
void SSD1331_Set_Text_Color_BG(unsigned int c, unsigned int bg);
void SSD1331_Set_Text_Size(char s);
void SSD1331_Set_Text_Wrap(char w);
void SSD1331_Set_Rotation(char r);
 
// Test functions
void SSD1331_Test_DrawLines(unsigned int color);
void SSD1331_Test_DrawRect(unsigned int color);
void SSD1331_Test_FillRect(unsigned int color1, unsigned int color2);
void SSD1331_Test_DrawCircle(unsigned int radius, unsigned int color);
void SSD1331_Test_FillCircle(unsigned int radius, unsigned int color);
void SSD1331_Test_DrawTria(void);
void SSD1331_Test_DrawRoundRect(void);
void SSD1331_Test_MediaButtons(void);
void SSD1331_Test_Pattern(void);
 
#endif /* OLED_SSD1331_H */
 
/PIC Projects/PICX_27J13/sensor_lux_TSL2561.c
0,0 → 1,233
#include "sensor_lux_TSL2561.h"
#include "defines.h"
#include "base_I2C.h"
#include <delays.h>
 
static TSL2561_DATA *tsl2561_data_p;
 
void LUX_Init(TSL2561_DATA *data, char address) {
tsl2561_data_p = data;
tsl2561_data_p->address = address;
tsl2561_data_p->integration = TSL2561_INTEGRATIONTIME_13MS;
tsl2561_data_p->gain = TSL2561_GAIN_16X;
}
 
void LUX_Begin(void) {
char result, buffer[2];
char toSend = TSL2561_REGISTER_ID;
DBG_PRINT_LUX("Sending %X to address %X\r\n", toSend, tsl2561_data_p->address);
I2C_Master_Send(tsl2561_data_p->address, 1, &toSend);
do {
result = I2C_Get_Status();
} while (!result);
 
I2C_Master_Recv(tsl2561_data_p->address, 1);
do {
result = I2C_Get_Status();
} while (!result);
char length = I2C_Read_Buffer(buffer);
DBG_PRINT_LUX("Received %d bytes: ", length);
for (char i = 0; i < length; i++) {
DBG_PRINT_LUX("%c ", buffer[i]);
}
DBG_PRINT_LUX("\r\n");
 
// Set default integration time and gain
LUX_Set_Timing(tsl2561_data_p->integration);
LUX_Set_Gain(tsl2561_data_p->gain);
 
// Start the chip in power-down mode
LUX_Disable();
}
 
void LUX_Enable() {
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
 
void LUX_Disable() {
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
 
void LUX_Set_Gain(tsl2561Gain_t gain) {
LUX_Enable();
tsl2561_data_p->gain = gain;
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
void LUX_Set_Timing(tsl2561IntegrationTime_t integration) {
LUX_Enable();
tsl2561_data_p->integration = integration;
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
unsigned long LUX_Calculate_Lux(unsigned int ch0, unsigned int ch1) {
unsigned long chScale, channel0, channel1, ratio1, ratio, temp, lux;
unsigned int b, m;
 
switch (tsl2561_data_p->integration) {
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: // No scaling ... integration time = 402ms
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
}
 
// Scale for gain (1x or 16x)
if (!tsl2561_data_p->gain)
chScale = chScale << 4;
 
// scale the channel values
channel0 = (ch0 * chScale) >> TSL2561_LUX_CHSCALE;
channel1 = (ch1 * chScale) >> TSL2561_LUX_CHSCALE;
 
// find the ratio of the channel values (Channel1/Channel0)
ratio1 = 0;
if (channel0 != 0)
ratio1 = (channel1 << (TSL2561_LUX_RATIOSCALE+1)) / channel0;
 
// round the ratio value
ratio = (ratio1 + 1) >> 1;
 
#ifdef TSL2561_PACKAGE_CS
if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1C)) {
b = TSL2561_LUX_B1C; m = TSL2561_LUX_M1C;
} else if (ratio <= TSL2561_LUX_K2C) {
b = TSL2561_LUX_B2C; m = TSL2561_LUX_M2C;
} else if (ratio <= TSL2561_LUX_K3C) {
b = TSL2561_LUX_B3C; m = TSL2561_LUX_M3C;
} else if (ratio <= TSL2561_LUX_K4C) {
b = TSL2561_LUX_B4C; m = TSL2561_LUX_M4C;
} else if (ratio <= TSL2561_LUX_K5C) {
b = TSL2561_LUX_B5C; m = TSL2561_LUX_M5C;
} else if (ratio <= TSL2561_LUX_K6C) {
b = TSL2561_LUX_B6C; m = TSL2561_LUX_M6C;
} else if (ratio <= TSL2561_LUX_K7C) {
b = TSL2561_LUX_B7C; m = TSL2561_LUX_M7C;
} else if (ratio > TSL2561_LUX_K8C) {
b = TSL2561_LUX_B8C; m = TSL2561_LUX_M8C;
}
#else
// if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1T)) {
if ((ratio <= TSL2561_LUX_K1T)) {
b = TSL2561_LUX_B1T; m = TSL2561_LUX_M1T;
} else if (ratio <= TSL2561_LUX_K2T) {
b = TSL2561_LUX_B2T; m = TSL2561_LUX_M2T;
} else if (ratio <= TSL2561_LUX_K3T) {
b = TSL2561_LUX_B3T; m = TSL2561_LUX_M3T;
} else if (ratio <= TSL2561_LUX_K4T) {
b = TSL2561_LUX_B4T; m = TSL2561_LUX_M4T;
} else if (ratio <= TSL2561_LUX_K5T) {
b = TSL2561_LUX_B5T; m = TSL2561_LUX_M5T;
} else if (ratio <= TSL2561_LUX_K6T) {
b = TSL2561_LUX_B6T; m = TSL2561_LUX_M6T;
} else if (ratio <= TSL2561_LUX_K7T) {
b = TSL2561_LUX_B7T; m = TSL2561_LUX_M7T;
} else if (ratio > TSL2561_LUX_K8T) {
b = TSL2561_LUX_B8T; m = TSL2561_LUX_M8T;
}
#endif
// temp = ((channel0 * b) - (channel1 * m));
// TODO: Change this back once they fix compiler
temp = (channel0 * b);
temp -= (channel1 * m);
 
// // do not allow negative lux value
// if (temp < 0)
// temp = 0;
 
// round lsb (2^(LUX_SCALE-1))
temp += (1 << (TSL2561_LUX_LUXSCALE-1));
 
// strip off fractional portion
lux = temp >> TSL2561_LUX_LUXSCALE;
 
return lux;
}
 
unsigned long LUX_Get_Full_Luminosity() {
unsigned long x;
 
// Enable the device by setting the control bit to 0x03
LUX_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data_p->integration) {
case TSL2561_INTEGRATIONTIME_13MS:
Delay10KTCYx(67);
break;
case TSL2561_INTEGRATIONTIME_101MS:
Delay10KTCYx(255);
Delay10KTCYx(230);
break;
default:
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(145);
break;
}
 
x = LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
 
LUX_Disable();
 
return x;
}
 
unsigned int LUX_Get_Luminosity(char channel) {
unsigned long x = LUX_Get_Full_Luminosity();
 
if (channel == 0) {
// Reads two byte value from channel 0 (visible + infrared)
return (x & 0xFFFF);
} else if (channel == 1) {
// Reads two byte value from channel 1 (infrared)
return (x >> 16);
} else if (channel == 2) {
// Reads all and subtracts out just the visible!
return ( (x & 0xFFFF) - (x >> 16));
}
 
// Unknown channel!
return 0;
}
 
void LUX_Write_2_Bytes(char reg, char value) {
char buffer[2], result;
buffer[0] = reg;
buffer[1] = value;
I2C_Master_Send(tsl2561_data_p->address, 2, buffer);
do {
result = I2C_Get_Status();
} while (!result);
}
 
unsigned int LUX_Read_2_Bytes(char reg) {
char result, length, buffer[2];
unsigned int ret;
 
I2C_Master_Restart(tsl2561_data_p->address, reg, 2);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer(buffer);
ret = buffer[1] << 8;
ret |= buffer[0];
 
return ret;
}
/PIC Projects/PICX_27J13/sensor_lux_TSL2561.h
0,0 → 1,132
#ifndef LUX_TSL2561_H
#define LUX_TSL2561_H
 
#define TSL2561_VISIBLE 2 // channel 0 - channel 1
#define TSL2561_INFRARED 1 // channel 1
#define TSL2561_FULLSPECTRUM 0 // channel 0
 
// 3 i2c address options!
#define TSL2561_ADDR_LOW 0x29
#define TSL2561_ADDR_FLOAT 0x39
#define TSL2561_ADDR_HIGH 0x49
 
// Lux calculations differ slightly for CS package
//#define TSL2561_PACKAGE_CS
#define TSL2561_PACKAGE_T_FN_CL
 
#define TSL2561_READBIT (0x01)
 
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
#define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
#define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
#define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write
 
#define TSL2561_CONTROL_POWERON (0x03)
#define TSL2561_CONTROL_POWEROFF (0x00)
 
#define TSL2561_LUX_LUXSCALE (14) // Scale by 2^14
#define TSL2561_LUX_RATIOSCALE (9) // Scale ratio by 2^9
#define TSL2561_LUX_CHSCALE (10) // Scale channel values by 2^10
#define TSL2561_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^TSL2561_LUX_CHSCALE
#define TSL2561_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^TSL2561_LUX_CHSCALE
 
// T, FN and CL package values
#define TSL2561_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
#define TSL2561_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
#define TSL2561_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
#define TSL2561_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
#define TSL2561_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
#define TSL2561_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
#define TSL2561_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
#define TSL2561_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
#define TSL2561_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
#define TSL2561_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
#define TSL2561_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
#define TSL2561_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
#define TSL2561_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
#define TSL2561_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
#define TSL2561_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
#define TSL2561_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
#define TSL2561_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
#define TSL2561_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
#define TSL2561_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
#define TSL2561_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
 
// CS package values
#define TSL2561_LUX_K1C (0x0043) // 0.130 * 2^RATIO_SCALE
#define TSL2561_LUX_B1C (0x0204) // 0.0315 * 2^LUX_SCALE
#define TSL2561_LUX_M1C (0x01ad) // 0.0262 * 2^LUX_SCALE
#define TSL2561_LUX_K2C (0x0085) // 0.260 * 2^RATIO_SCALE
#define TSL2561_LUX_B2C (0x0228) // 0.0337 * 2^LUX_SCALE
#define TSL2561_LUX_M2C (0x02c1) // 0.0430 * 2^LUX_SCALE
#define TSL2561_LUX_K3C (0x00c8) // 0.390 * 2^RATIO_SCALE
#define TSL2561_LUX_B3C (0x0253) // 0.0363 * 2^LUX_SCALE
#define TSL2561_LUX_M3C (0x0363) // 0.0529 * 2^LUX_SCALE
#define TSL2561_LUX_K4C (0x010a) // 0.520 * 2^RATIO_SCALE
#define TSL2561_LUX_B4C (0x0282) // 0.0392 * 2^LUX_SCALE
#define TSL2561_LUX_M4C (0x03df) // 0.0605 * 2^LUX_SCALE
#define TSL2561_LUX_K5C (0x014d) // 0.65 * 2^RATIO_SCALE
#define TSL2561_LUX_B5C (0x0177) // 0.0229 * 2^LUX_SCALE
#define TSL2561_LUX_M5C (0x01dd) // 0.0291 * 2^LUX_SCALE
#define TSL2561_LUX_K6C (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6C (0x0101) // 0.0157 * 2^LUX_SCALE
#define TSL2561_LUX_M6C (0x0127) // 0.0180 * 2^LUX_SCALE
#define TSL2561_LUX_K7C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7C (0x0037) // 0.00338 * 2^LUX_SCALE
#define TSL2561_LUX_M7C (0x002b) // 0.00260 * 2^LUX_SCALE
#define TSL2561_LUX_K8C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8C (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8C (0x0000) // 0.000 * 2^LUX_SCALE
 
enum {
TSL2561_REGISTER_CONTROL = 0x00,
TSL2561_REGISTER_TIMING = 0x01,
TSL2561_REGISTER_THRESHHOLDL_LOW = 0x02,
TSL2561_REGISTER_THRESHHOLDL_HIGH = 0x03,
TSL2561_REGISTER_THRESHHOLDH_LOW = 0x04,
TSL2561_REGISTER_THRESHHOLDH_HIGH = 0x05,
TSL2561_REGISTER_INTERRUPT = 0x06,
TSL2561_REGISTER_CRC = 0x08,
TSL2561_REGISTER_ID = 0x0A,
TSL2561_REGISTER_CHAN0_LOW = 0x0C,
TSL2561_REGISTER_CHAN0_HIGH = 0x0D,
TSL2561_REGISTER_CHAN1_LOW = 0x0E,
TSL2561_REGISTER_CHAN1_HIGH = 0x0F
};
 
typedef enum {
TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms
TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms
TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms
} tsl2561IntegrationTime_t;
 
typedef enum {
TSL2561_GAIN_0X = 0x00, // No gain
TSL2561_GAIN_16X = 0x10 // 16x gain
} tsl2561Gain_t;
 
typedef struct __TSL25611_DATA {
char address;
tsl2561IntegrationTime_t integration;
tsl2561Gain_t gain;
} TSL2561_DATA;
 
void LUX_Init(TSL2561_DATA *data, char address);
void LUX_Begin(void);
void LUX_Enable(void);
void LUX_Disable(void);
void LUX_Set_Timing(tsl2561IntegrationTime_t integration);
void LUX_Set_Gain(tsl2561Gain_t gain);
unsigned long LUX_Calculate_Lux(unsigned int ch0, unsigned int ch1);
unsigned long LUX_Get_Full_Luminosity(void);
unsigned int LUX_Get_Luminosity(char channel);
 
void LUX_Write_2_Bytes(char reg, char value);
unsigned int LUX_Read_2_Bytes(char reg);
 
#endif /* LUX_TSL2561_H */
 
/PIC Projects/PICX_27J13/sensor_nfc_PN532.c
0,0 → 1,474
#include <xc.h>
#include <string.h>
#include <delays.h>
#include "defines.h"
#include "sensor_nfc_PN532.h"
#include "base_I2C.h"
 
static NFC_DATA *nfc_data_p;
 
// Const value arrays for comparison use
static const char pn532response_firmwarevers[] = {0x01, 0x00, 0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03};
static const char pn532ack[] = {0x01, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00};
 
void NFC_Init(NFC_DATA *data) {
nfc_data_p = data;
NFC_IRQ_TRIS = 1; // IRQ Pin is RC5
 
/* NFC reset is disabled due to lack of pins */
// NFC_RESET_TRIS = 0; // Reset Pin is RC2
//
// // Reset the PN532
// NFC_RESET_LAT = 1;
// NFC_RESET_LAT = 0;
// Delay10TCYx(1);
// NFC_RESET_LAT = 1;
}
 
// Configures the SAM (Secure Access Module)
char NFC_SAMConfig() {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_SAMCONFIGURATION;
nfc_data_p->packetbuffer[1] = 0x01; // Normal mode
nfc_data_p->packetbuffer[2] = 0x14; // Timeout 50ms * 20 = 1s
nfc_data_p->packetbuffer[3] = 0x01; // Use IRQ pin
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
return 0;
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 8);
 
return (nfc_data_p->packetbuffer[7] == 0x15);
}
 
// Checks the firmware version of the PN5xx chip
NFC_FIRMWARE_VERSION NFC_Get_Firmware_Version(void) {
NFC_FIRMWARE_VERSION response = {0, 0, 0, 0};
 
// Create and send command
nfc_data_p->packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 1))
return response;
 
// Read back data from the PN532
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
 
// Compare and check returned values
if (strncmp((char *) nfc_data_p->packetbuffer, (char *) pn532response_firmwarevers, 8) != 0)
return response;
 
// Save and return info
response.IC = nfc_data_p->packetbuffer[8];
response.Ver = nfc_data_p->packetbuffer[9];
response.Rev = nfc_data_p->packetbuffer[10];
response.Support = nfc_data_p->packetbuffer[11];
 
return response;
}
 
// Sends a command and waits a specified period for the ACK
char NFC_Send_Command_Check_Ack(char *cmd, char cmdlen) {
unsigned int timer = 0;
 
// Write the command
NFC_I2C_Write_Cmd(cmd, cmdlen);
 
// Wait for chip to be ready
while (NFC_I2C_Read_Status() != PN532_I2C_READY) {
if (PN532_TIMEOUT != 0) {
timer += 1;
if (timer > PN532_TIMEOUT)
return 0;
}
Delay10TCYx(1);
}
 
// Check ACK
if (!NFC_I2C_Read_ACK()) {
return 0;
}
 
return 1;
}
 
// Passive polling, waits for an ISO14443A target to enter the field
char NFC_Read_Passive_Target_ID(NFC_TargetDataMiFare *cardData) {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
nfc_data_p->packetbuffer[1] = 2; // Max 2 cards at once
nfc_data_p->packetbuffer[2] = PN532_MIFARE_ISO14443A; // Mifare only
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 3))
return 0;
 
// Wait for IRQ line
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 35);
 
/* InListPassiveTarget response should be in the following format:
* Byte Description
* ---------- ------------------
* b0 Data ACK
* b1..7 Frame header and preamble
* b8 Tags found
* b9..N NFC_TargetDataMiFare[2]
* bN+1..N+2 Checksum + postamble
*/
 
// Check # of tags found
if (!nfc_data_p->packetbuffer[8])
return 0;
// Save data from first card
if (nfc_data_p->packetbuffer[13] == 4) {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[9], 9);
} else {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[9], 12);
}
 
// Save data from second card
if (nfc_data_p->packetbuffer[8] == 2) {
// Offset will vary depending on length of first card
if (nfc_data_p->packetbuffer[13] == 4) {
if (nfc_data_p->packetbuffer[22] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[18], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[18], 12);
}
} else { // Length of first UID is 7
if (nfc_data_p->packetbuffer[25] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[21], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[21], 12);
}
}
}
// Return the number of cards detected
return nfc_data_p->packetbuffer[8];
}
 
// Active polling, returns number of cards in the field
char NFC_Poll_Targets(char number, char period, NFC_TargetDataMiFare *cardData) {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INAUTOPOLL;
nfc_data_p->packetbuffer[1] = number; // Number of polling
nfc_data_p->packetbuffer[2] = period; // Polling period in units of 150ms
nfc_data_p->packetbuffer[3] = 0x10; // Check for Mifare cards only
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
return 0;
 
// Wait for IRQ line
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 37);
 
/* InAutoPoll response should be in the following format:
* Byte Description
* ---------- ------------------
* b0 Data ACK
* b1..7 Frame header and preamble
* b6 Tags found
* b7 Polled target type (should be 0x10 Mifare)
* b8 TargetData length (1/2)
* b9..N NFC_TargetDataMiFare[1/2]
* bN+1..N+2 Checksum + postamble
*/
 
// Check # of tags found
if (!nfc_data_p->packetbuffer[8])
return 0;
 
// Save data from first card
if (nfc_data_p->packetbuffer[15] == 4) {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[11], 9);
} else {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[11], 12);
}
 
// Save data from second card
if (nfc_data_p->packetbuffer[8] == 2) {
// Offset will vary depending on length of first card
if (nfc_data_p->packetbuffer[15] == 4) {
if (nfc_data_p->packetbuffer[26] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[22], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[22], 12);
}
} else {
if (nfc_data_p->packetbuffer[29] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[25], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[25], 12);
}
}
}
 
// Return the number of cards detected
return nfc_data_p->packetbuffer[8];
}
 
//// Indicates whether the specified block number is the first block
//// in the sector (block 0 relative to the current sector)
//char NFC_mifareclassic_IsFirstBlock(unsigned long uiBlock) {
// // Test if we are in the small or big sectors
// if (uiBlock < 128)
// return ((uiBlock) % 4 == 0);
// else
// return ((uiBlock) % 16 == 0);
//}
 
//// Indicates whether the specified block number is the sector trailer
//char NFC_mifareclassic_IsTrailerBlock(unsigned long uiBlock) {
// // Test if we are in the small or big sectors
// if (uiBlock < 128)
// return ((uiBlock + 1) % 4 == 0);
// else
// return ((uiBlock + 1) % 16 == 0);
//}
 
//// Tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command
//char NFC_mifareclassic_AuthenticateBlock(char *uid, char uidLen, unsigned long blockNumber, char keyNumber, char *keyData) {
// // See section 7.3.8 of the PN532 User Manual
// // blockNumber = The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards)\
// // keyNumber = Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
// // keyData = Pointer to a byte array containing the 6 byte key value
//
// // Assemble frame data
// nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; /* Data Exchange Header */
// nfc_data_p->packetbuffer[1] = 1; /* Max card numbers */
// nfc_data_p->packetbuffer[2] = (keyNumber) ? MIFARE_CMD_AUTH_A : MIFARE_CMD_AUTH_B;
// nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (1K = 0..63, 4K = 0..255 */
// for (char i = 0; i < 6; i++) {
// nfc_data_p->packetbuffer[4 + i] = keyData[i];
// }
// for (char i = 0; i < uidLen; i++) {
// nfc_data_p->packetbuffer[10 + i] = uid[i];
// }
//
// // Send frame and check for ACK
// if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 10 + uidLen))
// return 0;
//
// // Read response from PN532
// NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
//
// return 1;
//}
 
//// Tries to read an entire 16-byte data block at the specified block address
//char NFC_mifareclassic_ReadDataBlock(char blockNumber, char *data) {
// // Assemble frame data
// nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
// nfc_data_p->packetbuffer[1] = 1; /* Card number */
// nfc_data_p->packetbuffer[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */
// nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
//
// // Send frame and check for ACK
// if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
// return 0;
//
// // Read reponse
// NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
//
// // If byte 9 isnt 0x00 we probably have and error
// if (nfc_data_p->packetbuffer[8] != 0x00) {
// return 0;
// }
//
// // Copy the 16 data bytes into the data buffer
// // Block contents starts at byte 10 of a valid response
// for (char i = 0; i < 16; i++) {
// data[i] = nfc_data_p->packetbuffer[9 + i];
// }
//
// return 1;
//}
 
//// Tries to write an entire 16-byte data block at the specified block address
//char NFC_mifareclassic_WriteDataBlock(char blockNumber, char *data) {
// // Assemble frame data
// nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
// nfc_data_p->packetbuffer[1] = 1; /* Card number */
// nfc_data_p->packetbuffer[2] = MIFARE_CMD_WRITE; /* Mifare Write command = 0xA0 */
// nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
// for (char i = 0; i < 16; i++) { /* Data Payload */
// nfc_data_p->packetbuffer[4 + i] = data[i];
// }
//
// // Send frame and check for ACK
// if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 20))
// return 0;
//
// // Read response
// NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
//
// return 1;
//}
 
//// Formats a Mifare Classic card to store NDEF Records
//char NFC_mifareclassic_FormatNDEF(void) {
// char sectorbuffer1[16] = {0x14, 0x01, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
// char sectorbuffer2[16] = {0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
// char sectorbuffer3[16] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0x78, 0x77, 0x88, 0xC1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
//
// // Write blocks 1 and 2
// if (!NFC_mifareclassic_WriteDataBlock(1, sectorbuffer1))
// return 0;
// if (!NFC_mifareclassic_WriteDataBlock(2, sectorbuffer2))
// return 0;
// // Write key A and access rights
// if (!NFC_mifareclassic_WriteDataBlock(3, sectorbuffer3))
// return 0;
//
// return 1;
//}
 
//// Writes an NDEF URI Record to the specified sector (1..15)
///* Note that this function assumes that the Mifare Classic card is
// already formatted to work as an "NFC Forum Tag" and uses a MAD1
// file system. You can use the NXP TagWriter app on Android to
// properly format cards for this. */
//char NFC_mifareclassic_WriteNDEFURI(char sectorNumber, char uriIdentifier, const char * url) {
// // uriIdentifier = The uri identifier code (0 = none, 0x01 = "http://www.", etc.)
// // url = The uri text to write (max 38 characters)
//
// // Figure out how long the string is
// char len = strlen(url);
//
// char sectorbuffer1[16] = {0x00, 0x00, 0x03, len + 5, 0xD1, 0x01, len + 1, 0x55, uriIdentifier, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// char sectorbuffer2[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// char sectorbuffer3[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// char sectorbuffer4[16] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7, 0x7F, 0x07, 0x88, 0x40, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
//
// // Make sure we're within a 1K limit for the sector number
// if ((sectorNumber < 1) || (sectorNumber > 15))
// return 0;
//
// // Make sure the URI payload is between 1 and 38 chars
// if ((len < 1) || (len > 38))
// return 0;
//
// if (len <= 6) {
// // Unlikely we'll get a url this short, but why not ...
// memcpy(sectorbuffer1 + 9, url, len);
// sectorbuffer1[len + 9] = 0xFE;
// } else if (len == 7) {
// // 0xFE needs to be wrapped around to next block
// memcpy(sectorbuffer1 + 9, url, len);
// sectorbuffer2[0] = 0xFE;
// } else if ((len > 7) || (len <= 22)) {
// // Url fits in two blocks
// memcpy(sectorbuffer1 + 9, url, 7);
// memcpy(sectorbuffer2, url + 7, len - 7);
// sectorbuffer2[len - 7] = 0xFE;
// } else if (len == 23) {
// // 0xFE needs to be wrapped around to final block
// memcpy(sectorbuffer1 + 9, url, 7);
// memcpy(sectorbuffer2, url + 7, len - 7);
// sectorbuffer3[0] = 0xFE;
// } else {
// // Url fits in three blocks
// memcpy(sectorbuffer1 + 9, url, 7);
// memcpy(sectorbuffer2, url + 7, 16);
// memcpy(sectorbuffer3, url + 23, len - 24);
// sectorbuffer3[len - 22] = 0xFE;
// }
//
// // Now write all three blocks back to the card
// if (!(NFC_mifareclassic_WriteDataBlock(sectorNumber * 4, sectorbuffer1)))
// return 0;
// if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 1, sectorbuffer2)))
// return 0;
// if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 2, sectorbuffer3)))
// return 0;
// if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 3, sectorbuffer4)))
// return 0;
//
// return 1;
//}
 
// Reads and checks for the ACK signal
char NFC_I2C_Read_ACK() {
char buffer[7];
 
// Check ACK
NFC_I2C_Read_Data(buffer, 6);
 
// Return if the 7 bytes matches the ACK pattern
return (strncmp((char *) buffer, (char *) pn532ack, 7) == 0);
}
 
// Checks the IRQ pin to know if the PN532 is ready
char NFC_I2C_Read_Status() {
if (NFC_IRQ_PORT == 1) {
return PN532_I2C_BUSY;
} else {
return PN532_I2C_READY;
}
}
 
// Reads n bytes of data from the PN532 via I2C
void NFC_I2C_Read_Data(char *buffer, char length) {
char result;
 
// Wait for IRQ to go low
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
// Read bytes from PN532 into buffer
I2C_Master_Recv(PN532_I2C_ADDRESS, length + 2);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
I2C_Read_Buffer((char *) buffer);
 
/* Remaining packet byte layout is as follows:
Byte Description
----- ----------------------
* 0 Data ready ACK
* 1 Preamble (0x00)
* 2-3 Start code (0x00,0xFF)
* 4 Length (TFI to N)
* 5 Length Checksum (Length + LCS = 0x00)
* 6 TFI (Frame identifier)
* 0xD4 - Host to PN532
* 0xD5 - PN532 to Host
* 7-N Data (Length - 1 bytes)
* N+1 Data checksum (TFI + Data~N + DCS = 0x00)
* N+2 Postamble (0x00) */
}
 
// Writes a command to the PN532, automatically inserting the preamble and required frame details (checksum, len, etc.)
void NFC_I2C_Write_Cmd(char* cmd, char cmdlen) {
char checksum;
char buffer[PN532_PACKBUFFSIZ + 8];
char buffer_ind = 6;
cmdlen++;
 
checksum = PN532_PREAMBLE + PN532_PREAMBLE + PN532_STARTCODE2 + PN532_HOSTTOPN532;
 
// Fill out required frame fields
buffer[0] = PN532_PREAMBLE;
buffer[1] = PN532_PREAMBLE;
buffer[2] = PN532_STARTCODE2;
buffer[3] = cmdlen;
buffer[4] = ~cmdlen + 1;
buffer[5] = PN532_HOSTTOPN532;
 
 
// Copy cmd to be sent
for (char i = 0; i < cmdlen - 1; i++) {
checksum += cmd[i];
buffer[buffer_ind] = cmd[i];
buffer_ind++;
}
 
buffer[buffer_ind] = ~checksum;
buffer_ind++;
buffer[buffer_ind] = PN532_POSTAMBLE;
buffer_ind++;
 
I2C_Master_Send(PN532_I2C_ADDRESS, buffer_ind, buffer);
}
/PIC Projects/PICX_27J13/sensor_nfc_PN532.h
0,0 → 1,173
#ifndef NFC_H
#define NFC_H
 
/* PN532 NFC Reader from Adafruit */
 
#define PN532_PREAMBLE (0x00)
#define PN532_STARTCODE1 (0x00)
#define PN532_STARTCODE2 (0xFF)
#define PN532_POSTAMBLE (0x00)
 
#define PN532_HOSTTOPN532 (0xD4)
 
// PN532 Commands
#define PN532_COMMAND_DIAGNOSE (0x00)
#define PN532_COMMAND_GETFIRMWAREVERSION (0x02)
#define PN532_COMMAND_GETGENERALSTATUS (0x04)
#define PN532_COMMAND_READREGISTER (0x06)
#define PN532_COMMAND_WRITEREGISTER (0x08)
#define PN532_COMMAND_READGPIO (0x0C)
#define PN532_COMMAND_WRITEGPIO (0x0E)
#define PN532_COMMAND_SETSERIALBAUDRATE (0x10)
#define PN532_COMMAND_SETPARAMETERS (0x12)
#define PN532_COMMAND_SAMCONFIGURATION (0x14)
#define PN532_COMMAND_POWERDOWN (0x16)
#define PN532_COMMAND_RFCONFIGURATION (0x32)
#define PN532_COMMAND_RFREGULATIONTEST (0x58)
#define PN532_COMMAND_INJUMPFORDEP (0x56)
#define PN532_COMMAND_INJUMPFORPSL (0x46)
#define PN532_COMMAND_INLISTPASSIVETARGET (0x4A)
#define PN532_COMMAND_INATR (0x50)
#define PN532_COMMAND_INPSL (0x4E)
#define PN532_COMMAND_INDATAEXCHANGE (0x40)
#define PN532_COMMAND_INCOMMUNICATETHRU (0x42)
#define PN532_COMMAND_INDESELECT (0x44)
#define PN532_COMMAND_INRELEASE (0x52)
#define PN532_COMMAND_INSELECT (0x54)
#define PN532_COMMAND_INAUTOPOLL (0x60)
#define PN532_COMMAND_TGINITASTARGET (0x8C)
#define PN532_COMMAND_TGSETGENERALBYTES (0x92)
#define PN532_COMMAND_TGGETDATA (0x86)
#define PN532_COMMAND_TGSETDATA (0x8E)
#define PN532_COMMAND_TGSETMETADATA (0x94)
#define PN532_COMMAND_TGGETINITIATORCOMMAND (0x88)
#define PN532_COMMAND_TGRESPONSETOINITIATOR (0x90)
#define PN532_COMMAND_TGGETTARGETSTATUS (0x8A)
 
#define PN532_WAKEUP (0x55)
 
#define PN532_SPI_STATREAD (0x02)
#define PN532_SPI_DATAWRITE (0x01)
#define PN532_SPI_DATAREAD (0x03)
#define PN532_SPI_READY (0x01)
 
#define PN532_I2C_ADDRESS (0x48 >> 1)
#define PN532_I2C_READBIT (0x01)
#define PN532_I2C_BUSY (0x00)
#define PN532_I2C_READY (0x01)
#define PN532_I2C_READYTIMEOUT (20)
 
#define PN532_MIFARE_ISO14443A (0x00)
 
// Mifare Commands
#define MIFARE_CMD_AUTH_A (0x60)
#define MIFARE_CMD_AUTH_B (0x61)
#define MIFARE_CMD_READ (0x30)
#define MIFARE_CMD_WRITE (0xA0)
#define MIFARE_CMD_TRANSFER (0xB0)
#define MIFARE_CMD_DECREMENT (0xC0)
#define MIFARE_CMD_INCREMENT (0xC1)
#define MIFARE_CMD_STORE (0xC2)
 
// Prefixes for NDEF Records (to identify record type)
#define NDEF_URIPREFIX_NONE (0x00)
#define NDEF_URIPREFIX_HTTP_WWWDOT (0x01)
#define NDEF_URIPREFIX_HTTPS_WWWDOT (0x02)
#define NDEF_URIPREFIX_HTTP (0x03)
#define NDEF_URIPREFIX_HTTPS (0x04)
#define NDEF_URIPREFIX_TEL (0x05)
#define NDEF_URIPREFIX_MAILTO (0x06)
#define NDEF_URIPREFIX_FTP_ANONAT (0x07)
#define NDEF_URIPREFIX_FTP_FTPDOT (0x08)
#define NDEF_URIPREFIX_FTPS (0x09)
#define NDEF_URIPREFIX_SFTP (0x0A)
#define NDEF_URIPREFIX_SMB (0x0B)
#define NDEF_URIPREFIX_NFS (0x0C)
#define NDEF_URIPREFIX_FTP (0x0D)
#define NDEF_URIPREFIX_DAV (0x0E)
#define NDEF_URIPREFIX_NEWS (0x0F)
#define NDEF_URIPREFIX_TELNET (0x10)
#define NDEF_URIPREFIX_IMAP (0x11)
#define NDEF_URIPREFIX_RTSP (0x12)
#define NDEF_URIPREFIX_URN (0x13)
#define NDEF_URIPREFIX_POP (0x14)
#define NDEF_URIPREFIX_SIP (0x15)
#define NDEF_URIPREFIX_SIPS (0x16)
#define NDEF_URIPREFIX_TFTP (0x17)
#define NDEF_URIPREFIX_BTSPP (0x18)
#define NDEF_URIPREFIX_BTL2CAP (0x19)
#define NDEF_URIPREFIX_BTGOEP (0x1A)
#define NDEF_URIPREFIX_TCPOBEX (0x1B)
#define NDEF_URIPREFIX_IRDAOBEX (0x1C)
#define NDEF_URIPREFIX_FILE (0x1D)
#define NDEF_URIPREFIX_URN_EPC_ID (0x1E)
#define NDEF_URIPREFIX_URN_EPC_TAG (0x1F)
#define NDEF_URIPREFIX_URN_EPC_PAT (0x20)
#define NDEF_URIPREFIX_URN_EPC_RAW (0x21)
#define NDEF_URIPREFIX_URN_EPC (0x22)
#define NDEF_URIPREFIX_URN_NFC (0x23)
 
#define PN532_GPIO_VALIDATIONBIT (0x80)
#define PN532_GPIO_P30 (0)
#define PN532_GPIO_P31 (1)
#define PN532_GPIO_P32 (2)
#define PN532_GPIO_P33 (3)
#define PN532_GPIO_P34 (4)
#define PN532_GPIO_P35 (5)
 
#define PN532_PACKBUFFSIZ 64
#define PN532_TIMEOUT 1000
 
typedef struct {
char IC;
char Ver;
char Rev;
char Support;
} NFC_FIRMWARE_VERSION;
 
typedef struct {
char TG;
char SENS_RES[2];
char SEL_RES;
char NFCID_LEN;
char NFCID[7];
} NFC_TargetDataMiFare;
// Size can be 9 or 12 bytes
 
typedef struct {
char packetbuffer[PN532_PACKBUFFSIZ];
} NFC_DATA;
 
void NFC_Init(NFC_DATA *data);
 
// Generic PN532 functions
char NFC_SAMConfig(void);
NFC_FIRMWARE_VERSION NFC_Get_Firmware_Version(void);
char NFC_Send_Command_Check_Ack(char *cmd, char cmdlen);
//char NFC_writeGPIO(char pinstate);
//char NFC_readGPIO(void);
 
// ISO14443A functions
char NFC_Read_Passive_Target_ID(NFC_TargetDataMiFare *uidData);
char NFC_Poll_Targets(char number, char period, NFC_TargetDataMiFare *uidData);
 
// Mifare Classic functions
//char NFC_mifareclassic_IsFirstBlock(unsigned long uiBlock);
//char NFC_mifareclassic_IsTrailerBlock(unsigned long uiBlock);
//char NFC_mifareclassic_AuthenticateBlock(char *uid, char uidLen, unsigned long blockNumber, char keyNumber, char *keyData);
//char NFC_mifareclassic_ReadDataBlock(char blockNumber, char *data);
//char NFC_mifareclassic_WriteDataBlock(char blockNumber, char *data);
//char NFC_mifareclassic_FormatNDEF(void);
//char NFC_mifareclassic_WriteNDEFURI(char sectorNumber, char uriIdentifier, const char * url);
 
// Mifare Ultralight functions
//char NFC_mifareultralight_ReadPage(char page, char * buffer);
 
// Low level SPI functions
char NFC_I2C_Read_ACK(void);
char NFC_I2C_Read_Status(void);
void NFC_I2C_Read_Data(char *buffer, char length);
void NFC_I2C_Write_Cmd(char *cmd, char cmdlen);
 
#endif
 
/PIC Projects/PICX_27J13/sensor_temp_BMP085.c
0,0 → 1,192
#include <delays.h>
#include <math.h>
#include "defines.h"
#include "sensor_temp_BMP085.h"
#include "base_I2C.h"
 
 
static BMP085_DATA *bmp085_data_p;
 
void BMP_Init(BMP085_DATA *data) {
bmp085_data_p = data;
}
 
void BMP_Begin(char mode) {
if (mode > BMP085_ULTRAHIGHRES)
mode = BMP085_ULTRAHIGHRES;
bmp085_data_p->oversampling = mode;
 
if (BMP_Read8(0xD0) != 0x55) {
DBG_PRINT_BMP("Error contacting BMP085!\r\n");
return;
}
 
bmp085_data_p->ac1 = BMP_Read16(BMP085_CAL_AC1);
bmp085_data_p->ac2 = BMP_Read16(BMP085_CAL_AC2);
bmp085_data_p->ac3 = BMP_Read16(BMP085_CAL_AC3);
bmp085_data_p->ac4 = BMP_Read16(BMP085_CAL_AC4);
bmp085_data_p->ac5 = BMP_Read16(BMP085_CAL_AC5);
bmp085_data_p->ac6 = BMP_Read16(BMP085_CAL_AC6);
 
bmp085_data_p->b1 = BMP_Read16(BMP085_CAL_B1);
bmp085_data_p->b2 = BMP_Read16(BMP085_CAL_B2);
 
bmp085_data_p->mb = BMP_Read16(BMP085_CAL_MB);
bmp085_data_p->mc = BMP_Read16(BMP085_CAL_MC);
bmp085_data_p->md = BMP_Read16(BMP085_CAL_MD);
 
DBG_PRINT_BMP("AC1 = %d\r\n", bmp085_data_p->ac1);
DBG_PRINT_BMP("AC2 = %d\r\n", bmp085_data_p->ac2);
DBG_PRINT_BMP("AC3 = %d\r\n", bmp085_data_p->ac3);
DBG_PRINT_BMP("AC4 = %u\r\n", bmp085_data_p->ac4);
DBG_PRINT_BMP("AC5 = %u\r\n", bmp085_data_p->ac5);
DBG_PRINT_BMP("AC6 = %u\r\n", bmp085_data_p->ac6);
 
DBG_PRINT_BMP("B1 = %d\r\n", bmp085_data_p->b1);
DBG_PRINT_BMP("B2 = %d\r\n", bmp085_data_p->b2);
 
DBG_PRINT_BMP("MB = %d\r\n", bmp085_data_p->mb);
DBG_PRINT_BMP("MC = %d\r\n", bmp085_data_p->mc);
DBG_PRINT_BMP("MD = %d\r\n", bmp085_data_p->md);
}
 
unsigned int BMP_Read_Raw_Temperature() {
unsigned int ret;
 
BMP_Write8(BMP085_CONTROL, BMP085_READTEMPCMD);
Delay10KTCYx(255);
ret = BMP_Read16(BMP085_TEMPDATA);
DBG_PRINT_BMP("Raw Temp: %d\r\n", ret);
return ret;
}
 
unsigned long BMP_Read_Raw_Pressure() {
unsigned long ret;
 
BMP_Write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (bmp085_data_p->oversampling << 6));
 
if (bmp085_data_p->oversampling == BMP085_ULTRALOWPOWER)
Delay10KTCYx(255);
else if (bmp085_data_p->oversampling == BMP085_STANDARD)
Delay10KTCYx(255);
else if (bmp085_data_p->oversampling == BMP085_HIGHRES)
Delay10KTCYx(255);
else
Delay10KTCYx(255);
 
ret = BMP_Read16(BMP085_PRESSUREDATA);
ret <<= 8;
ret |= BMP_Read8(BMP085_PRESSUREDATA+2);
ret >>= (8 - bmp085_data_p->oversampling);
 
DBG_PRINT_BMP("Raw Pressure: %ld\r\n", ret);
 
return ret;
}
 
long BMP_Read_Pressure() {
long UT, UP, B3, B5, B6, X1, X2, X3, p;
unsigned long B4, B7;
 
UT = BMP_Read_Raw_Temperature();
UP = BMP_Read_Raw_Pressure();
 
// Temperature calculations
X1 = ((UT - (long) bmp085_data_p->ac6) * (long) bmp085_data_p->ac5) >> 15;
X2 = ((long) bmp085_data_p->mc << 11);
X2 -= (X1 + bmp085_data_p->md);
X2 /= 2; // round up
X2 /= (X1 + bmp085_data_p->md);
B5 = X1 + X2;
 
// Pressure calcs
B6 = B5 - 4000;
X1 = ((long) bmp085_data_p->b2 * ((B6 * B6) >> 12)) >> 11;
X2 = ((long) bmp085_data_p->ac2 * B6) >> 11;
X3 = X1 + X2;
B3 = ((((long) bmp085_data_p->ac1 * 4 + X3) << bmp085_data_p->oversampling) + 2) / 4;
 
X1 = ((long) bmp085_data_p->ac3 * B6) >> 13;
X2 = ((long) bmp085_data_p->b1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = ((unsigned long) bmp085_data_p->ac4 * (unsigned long) (X3 + 32768)) >> 15;
B7 = ((unsigned long) UP - B3) * (unsigned long) (50000UL >> bmp085_data_p->oversampling);
 
if (B7 < 0x80000000) {
p = (B7 * 2) / B4;
} else {
p = (B7 / B4) * 2;
}
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
 
p = p + ((X1 + X2 + (long)3791)>>4);
 
return p;
}
 
float BMP_Read_Temperature() {
long UT, X1, X2, B5;
float temp;
 
UT = BMP_Read_Raw_Temperature();
 
X1 = ((UT - (long) bmp085_data_p->ac6) * (long) bmp085_data_p->ac5) >> 15;
X2 = ((long) bmp085_data_p->mc << 11) / (X1 + (long) bmp085_data_p->md);
B5 = X1 + X2;
temp = (B5 + 8) >> 4;
temp /= 10;
 
return temp;
}
 
float BMP_Read_Altitude(float seaLevelPressure) {
float altitude;
float pressure = BMP_Read_Pressure();
altitude = 44330 * (1.0 - pow(pressure /seaLevelPressure,0.1903));
return altitude;
}
 
char BMP_Read8(char a) {
char buffer[6], result, length, ret = 0;
I2C_Master_Restart(BMP085_I2CADDR, a, 1);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
ret = buffer[0];
 
return ret;
}
 
unsigned int BMP_Read16(char a) {
char buffer[6], result, length;
unsigned int ret;
 
I2C_Master_Restart(BMP085_I2CADDR, a, 2);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
ret = buffer[0];
ret <<= 8;
ret |= buffer[1];
 
return ret;
}
 
void BMP_Write8(char a, char d) {
char buffer[2], result;
buffer[0] = a;
buffer[1] = d;
 
I2C_Master_Send(BMP085_I2CADDR, 2, buffer);
do {
result = I2C_Get_Status();
} while (!result);
}
/PIC Projects/PICX_27J13/sensor_temp_BMP085.h
0,0 → 1,47
#ifndef TEMP_BMP085_H
#define TEMP_BMP085_H
 
#define BMP085_I2CADDR 0x77
 
#define BMP085_ULTRALOWPOWER 0
#define BMP085_STANDARD 1
#define BMP085_HIGHRES 2
#define BMP085_ULTRAHIGHRES 3
#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
 
#define BMP085_CONTROL 0xF4
#define BMP085_TEMPDATA 0xF6
#define BMP085_PRESSUREDATA 0xF6
#define BMP085_READTEMPCMD 0x2E
#define BMP085_READPRESSURECMD 0x34
 
typedef struct {
int ac1, ac2, ac3, b1, b2, mb, mc, md;
unsigned int ac4, ac5, ac6;
char oversampling;
} BMP085_DATA;
 
void BMP_Init(BMP085_DATA *data);
void BMP_Begin(char mode);
unsigned int BMP_Read_Raw_Temperature(void);
unsigned long BMP_Read_Raw_Pressure(void);
float BMP_Read_Temperature(void);
long BMP_Read_Pressure(void);
float BMP_Read_Altitude(float seaLevelPressure);
 
char BMP_Read8(char a);
unsigned int BMP_Read16(char a);
void BMP_Write8(char a, char d);
 
#endif /* TEMP_BMP085_H */
 
/PIC Projects/PICX_27J13/glcdfont.c
0,0 → 1,263
#ifndef FONT5X7_H
#define FONT5X7_H
 
// standard ascii 5x7 font
 
const char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
/PIC Projects/PICX_27J13/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PICX_27J13
Property changes:
Added: svn:ignore
+build
+dist
/PIC Projects/PIC_27J13/nbproject/Makefile-default.mk
0,0 → 1,341
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.
 
 
# Include project Makefile
ifeq "${IGNORE_LOCAL}" "TRUE"
# do not include local makefile. User is passing all local related variables already
else
include Makefile
# Include makefile containing local settings
ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk"
include nbproject/Makefile-local-default.mk
endif
endif
 
# Environment
MKDIR=gnumkdir -p
RM=rm -f
MV=mv
CP=cp
 
# Macros
CND_CONF=default
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
IMAGE_TYPE=debug
OUTPUT_SUFFIX=cof
DEBUGGABLE_SUFFIX=cof
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
else
IMAGE_TYPE=production
OUTPUT_SUFFIX=hex
DEBUGGABLE_SUFFIX=cof
FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
endif
 
# Object Directory
OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 
# Distribution Directory
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
# Object Files Quoted if spaced
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/i2c.o ${OBJECTDIR}/interrupts.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o ${OBJECTDIR}/oled_ssd1331.o ${OBJECTDIR}/timers.o ${OBJECTDIR}/led_HT16K33.o ${OBJECTDIR}/lux_TSL2561.o ${OBJECTDIR}/nfc_PN532.o ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o ${OBJECTDIR}/temp_BMP085.o
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/i2c.o.d ${OBJECTDIR}/interrupts.o.d ${OBJECTDIR}/spi.o.d ${OBJECTDIR}/uart.o.d ${OBJECTDIR}/oled_ssd1306.o.d ${OBJECTDIR}/glcdfont.o.d ${OBJECTDIR}/adc.o.d ${OBJECTDIR}/xbee.o.d ${OBJECTDIR}/oled_ssd1331.o.d ${OBJECTDIR}/timers.o.d ${OBJECTDIR}/led_HT16K33.o.d ${OBJECTDIR}/lux_TSL2561.o.d ${OBJECTDIR}/nfc_PN532.o.d ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o.d ${OBJECTDIR}/temp_BMP085.o.d
 
# Object Files
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/i2c.o ${OBJECTDIR}/interrupts.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o ${OBJECTDIR}/oled_ssd1331.o ${OBJECTDIR}/timers.o ${OBJECTDIR}/led_HT16K33.o ${OBJECTDIR}/lux_TSL2561.o ${OBJECTDIR}/nfc_PN532.o ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o ${OBJECTDIR}/temp_BMP085.o
 
 
CFLAGS=
ASFLAGS=
LDLIBSOPTIONS=
 
############# Tool locations ##########################################
# If you copy a project from one host to another, the path where the #
# compiler is installed may be different. #
# If you open this project with MPLAB X in the new host, this #
# makefile will be regenerated and the paths will be corrected. #
#######################################################################
# fixDeps replaces a bunch of sed/cat/printf statements that slow down the build
FIXDEPS=fixDeps
 
.build-conf: ${BUILD_SUBPROJECTS}
${MAKE} ${MAKE_OPTIONS} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
 
MP_PROCESSOR_OPTION=18F27J13
MP_PROCESSOR_OPTION_LD=18f27j13
MP_LINKER_DEBUG_OPTION=
# ------------------------------------------------------------------------------------
# Rules for buildStep: assemble
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
else
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: compile
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/main.o main.c
@${DEP_GEN} -d ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/i2c.o: i2c.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/i2c.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/i2c.o i2c.c
@${DEP_GEN} -d ${OBJECTDIR}/i2c.o
@${FIXDEPS} "${OBJECTDIR}/i2c.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/interrupts.o: interrupts.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/interrupts.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/interrupts.o interrupts.c
@${DEP_GEN} -d ${OBJECTDIR}/interrupts.o
@${FIXDEPS} "${OBJECTDIR}/interrupts.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/spi.o: spi.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/spi.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/spi.o spi.c
@${DEP_GEN} -d ${OBJECTDIR}/spi.o
@${FIXDEPS} "${OBJECTDIR}/spi.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/uart.o: uart.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/uart.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/uart.o uart.c
@${DEP_GEN} -d ${OBJECTDIR}/uart.o
@${FIXDEPS} "${OBJECTDIR}/uart.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_ssd1306.o: oled_ssd1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_ssd1306.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1306.o oled_ssd1306.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1306.o
@${FIXDEPS} "${OBJECTDIR}/oled_ssd1306.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/glcdfont.o: glcdfont.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/glcdfont.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/glcdfont.o glcdfont.c
@${DEP_GEN} -d ${OBJECTDIR}/glcdfont.o
@${FIXDEPS} "${OBJECTDIR}/glcdfont.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/adc.o: adc.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/adc.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/adc.o adc.c
@${DEP_GEN} -d ${OBJECTDIR}/adc.o
@${FIXDEPS} "${OBJECTDIR}/adc.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/xbee.o: xbee.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/xbee.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/xbee.o xbee.c
@${DEP_GEN} -d ${OBJECTDIR}/xbee.o
@${FIXDEPS} "${OBJECTDIR}/xbee.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_ssd1331.o: oled_ssd1331.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_ssd1331.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o
@${FIXDEPS} "${OBJECTDIR}/oled_ssd1331.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/timers.o: timers.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/timers.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/timers.o timers.c
@${DEP_GEN} -d ${OBJECTDIR}/timers.o
@${FIXDEPS} "${OBJECTDIR}/timers.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/led_HT16K33.o: led_HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/led_HT16K33.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/led_HT16K33.o led_HT16K33.c
@${DEP_GEN} -d ${OBJECTDIR}/led_HT16K33.o
@${FIXDEPS} "${OBJECTDIR}/led_HT16K33.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/lux_TSL2561.o: lux_TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/lux_TSL2561.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/lux_TSL2561.o lux_TSL2561.c
@${DEP_GEN} -d ${OBJECTDIR}/lux_TSL2561.o
@${FIXDEPS} "${OBJECTDIR}/lux_TSL2561.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/nfc_PN532.o: nfc_PN532.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/nfc_PN532.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/nfc_PN532.o nfc_PN532.c
@${DEP_GEN} -d ${OBJECTDIR}/nfc_PN532.o
@${FIXDEPS} "${OBJECTDIR}/nfc_PN532.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_NHD-0216KZW-AB5.o: oled_NHD-0216KZW-AB5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o oled_NHD-0216KZW-AB5.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o
@${FIXDEPS} "${OBJECTDIR}/oled_NHD-0216KZW-AB5.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/temp_BMP085.o: temp_BMP085.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/temp_BMP085.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/temp_BMP085.o temp_BMP085.c
@${DEP_GEN} -d ${OBJECTDIR}/temp_BMP085.o
@${FIXDEPS} "${OBJECTDIR}/temp_BMP085.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
else
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/main.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/main.o main.c
@${DEP_GEN} -d ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/i2c.o: i2c.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/i2c.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/i2c.o i2c.c
@${DEP_GEN} -d ${OBJECTDIR}/i2c.o
@${FIXDEPS} "${OBJECTDIR}/i2c.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/interrupts.o: interrupts.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/interrupts.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/interrupts.o interrupts.c
@${DEP_GEN} -d ${OBJECTDIR}/interrupts.o
@${FIXDEPS} "${OBJECTDIR}/interrupts.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/spi.o: spi.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/spi.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/spi.o spi.c
@${DEP_GEN} -d ${OBJECTDIR}/spi.o
@${FIXDEPS} "${OBJECTDIR}/spi.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/uart.o: uart.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/uart.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/uart.o uart.c
@${DEP_GEN} -d ${OBJECTDIR}/uart.o
@${FIXDEPS} "${OBJECTDIR}/uart.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_ssd1306.o: oled_ssd1306.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_ssd1306.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1306.o oled_ssd1306.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1306.o
@${FIXDEPS} "${OBJECTDIR}/oled_ssd1306.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/glcdfont.o: glcdfont.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/glcdfont.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/glcdfont.o glcdfont.c
@${DEP_GEN} -d ${OBJECTDIR}/glcdfont.o
@${FIXDEPS} "${OBJECTDIR}/glcdfont.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/adc.o: adc.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/adc.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/adc.o adc.c
@${DEP_GEN} -d ${OBJECTDIR}/adc.o
@${FIXDEPS} "${OBJECTDIR}/adc.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/xbee.o: xbee.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/xbee.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/xbee.o xbee.c
@${DEP_GEN} -d ${OBJECTDIR}/xbee.o
@${FIXDEPS} "${OBJECTDIR}/xbee.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_ssd1331.o: oled_ssd1331.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_ssd1331.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o
@${FIXDEPS} "${OBJECTDIR}/oled_ssd1331.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/timers.o: timers.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/timers.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/timers.o timers.c
@${DEP_GEN} -d ${OBJECTDIR}/timers.o
@${FIXDEPS} "${OBJECTDIR}/timers.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/led_HT16K33.o: led_HT16K33.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/led_HT16K33.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/led_HT16K33.o led_HT16K33.c
@${DEP_GEN} -d ${OBJECTDIR}/led_HT16K33.o
@${FIXDEPS} "${OBJECTDIR}/led_HT16K33.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/lux_TSL2561.o: lux_TSL2561.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/lux_TSL2561.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/lux_TSL2561.o lux_TSL2561.c
@${DEP_GEN} -d ${OBJECTDIR}/lux_TSL2561.o
@${FIXDEPS} "${OBJECTDIR}/lux_TSL2561.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/nfc_PN532.o: nfc_PN532.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/nfc_PN532.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/nfc_PN532.o nfc_PN532.c
@${DEP_GEN} -d ${OBJECTDIR}/nfc_PN532.o
@${FIXDEPS} "${OBJECTDIR}/nfc_PN532.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/oled_NHD-0216KZW-AB5.o: oled_NHD-0216KZW-AB5.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o oled_NHD-0216KZW-AB5.c
@${DEP_GEN} -d ${OBJECTDIR}/oled_NHD-0216KZW-AB5.o
@${FIXDEPS} "${OBJECTDIR}/oled_NHD-0216KZW-AB5.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
${OBJECTDIR}/temp_BMP085.o: temp_BMP085.c nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} ${OBJECTDIR}
@${RM} ${OBJECTDIR}/temp_BMP085.o.d
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -ml -oa- -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/temp_BMP085.o temp_BMP085.c
@${DEP_GEN} -d ${OBJECTDIR}/temp_BMP085.o
@${FIXDEPS} "${OBJECTDIR}/temp_BMP085.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c18
endif
 
# ------------------------------------------------------------------------------------
# Rules for buildStep: link
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk 18f27j13.lkr
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_LD} $(MP_EXTRA_LD_PRE) "18f27j13.lkr" -p$(MP_PROCESSOR_OPTION_LD) -w -x -u_DEBUG -z__MPLAB_BUILD=1 -u_CRUNTIME -z__MPLAB_DEBUG=1 -z__MPLAB_DEBUGGER_PK3=1 $(MP_LINKER_DEBUG_OPTION) -l ${MP_CC_DIR}\\..\\lib -o dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
else
dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk 18f27j13.lkr
@${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE}
${MP_LD} $(MP_EXTRA_LD_PRE) "18f27j13.lkr" -p$(MP_PROCESSOR_OPTION_LD) -w -z__MPLAB_BUILD=1 -u_CRUNTIME -l ${MP_CC_DIR}\\..\\lib -o dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED}
endif
 
 
# Subprojects
.build-subprojects:
 
 
# Subprojects
.clean-subprojects:
 
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/default
${RM} -r dist/default
 
# Enable dependency checking
.dep.inc: .depcheck-impl
 
DEPFILES=$(shell mplabwildcard ${POSSIBLE_DEPFILES})
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
/PIC Projects/PIC_27J13/nbproject/Makefile-genesis.properties
0,0 → 1,8
#
#Fri Dec 21 15:59:39 EST 2012
default.com-microchip-mplab-nbide-toolchainC18-C18LanguageToolchain.md5=e4cd2f1e5bba11c8ba952dafee98d887
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\mplabc18\\v3.42\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=d94e033fce233e60ccb9abf3a212a9b7
default.languagetoolchain.version=3.42
host.platform=windows
conf.ids=default
/PIC Projects/PIC_27J13/nbproject/configurations.xml
0,0 → 1,175
<?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62">
<logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles"
displayName="Header Files"
projectFiles="true">
<itemPath>i2c.h</itemPath>
<itemPath>interrupts.h</itemPath>
<itemPath>spi.h</itemPath>
<itemPath>uart.h</itemPath>
<itemPath>oled_ssd1306.h</itemPath>
<itemPath>adc.h</itemPath>
<itemPath>xbee.h</itemPath>
<itemPath>oled_ssd1331.h</itemPath>
<itemPath>defines.h</itemPath>
<itemPath>timers.h</itemPath>
<itemPath>led_HT16K33.h</itemPath>
<itemPath>lux_TSL2561.h</itemPath>
<itemPath>nfc_PN532.h</itemPath>
<itemPath>oled_NHD-0216KZW-AB5.h</itemPath>
<itemPath>temp_BMP085.h</itemPath>
</logicalFolder>
<logicalFolder name="LibraryFiles"
displayName="Library Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
projectFiles="true">
<itemPath>18f27j13.lkr</itemPath>
</logicalFolder>
<logicalFolder name="ObjectFiles"
displayName="Object Files"
projectFiles="true">
</logicalFolder>
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
<itemPath>main.c</itemPath>
<itemPath>i2c.c</itemPath>
<itemPath>interrupts.c</itemPath>
<itemPath>spi.c</itemPath>
<itemPath>uart.c</itemPath>
<itemPath>oled_ssd1306.c</itemPath>
<itemPath>glcdfont.c</itemPath>
<itemPath>adc.c</itemPath>
<itemPath>xbee.c</itemPath>
<itemPath>oled_ssd1331.c</itemPath>
<itemPath>timers.c</itemPath>
<itemPath>led_HT16K33.c</itemPath>
<itemPath>lux_TSL2561.c</itemPath>
<itemPath>nfc_PN532.c</itemPath>
<itemPath>oled_NHD-0216KZW-AB5.c</itemPath>
<itemPath>temp_BMP085.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false">
<itemPath>Makefile</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
<conf name="default" type="2">
<toolsSet>
<developmentServer>localhost</developmentServer>
<targetDevice>PIC18F27J13</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
<platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>C18</languageToolchain>
<languageToolchainVersion>3.42</languageToolchainVersion>
<platform>3</platform>
</toolsSet>
<compileType>
<linkerTool>
<linkerLibItems>
</linkerLibItems>
</linkerTool>
<loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile>
<alternateLoadableFile></alternateLoadableFile>
</loading>
</compileType>
<makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
<makeCustomizationPreStep></makeCustomizationPreStep>
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
<makeCustomizationPostStep></makeCustomizationPostStep>
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
<C18>
<property key="code-model" value="ml"/>
<property key="data-model" value="oa-"/>
<property key="default-char-unsigned" value="false"/>
<property key="enable-all-optimizations" value="true"/>
<property key="enable-int-promotion" value="true"/>
<property key="enable-multi-bank-stack-model" value="false"/>
<property key="enable-ob" value="true"/>
<property key="enable-od" value="true"/>
<property key="enable-om" value="true"/>
<property key="enable-on" value="false"/>
<property key="enable-op" value="true"/>
<property key="enable-opa" value="true"/>
<property key="enable-or" value="true"/>
<property key="enable-os" value="true"/>
<property key="enable-ot" value="true"/>
<property key="enable-ou" value="true"/>
<property key="enable-ow" value="true"/>
<property key="extra-include-directories" value=""/>
<property key="optimization-master" value="Enable all"/>
<property key="preprocessor-macros" value=""/>
<property key="procedural-abstraction-passes" value="9"/>
<property key="storage-class" value="sca"/>
<property key="verbose" value="false"/>
<property key="warning-level" value="2"/>
</C18>
<C18-AS>
<property key="cross.reference.file" value=""/>
<property key="default.radix" value="HEX"/>
<property key="enable.case.sensitivity" value="true"/>
<property key="hex.output.format" value="INHX32"/>
<property key="preprocessor.macros" value=""/>
<property key="warning.level" value="0"/>
</C18-AS>
<C18-LD>
<property key="cod-file" value="false"/>
<property key="extra-lib-directories" value=""/>
<property key="hex-output-format" value="INHX32"/>
<property key="map-file" value=""/>
</C18-LD>
<C18LanguageToolchain>
<property key="extended-mode" value="false"/>
<property key="extended-mode-mcc18" value="false"/>
<property key="extended-mode-mpasm" value="false"/>
<property key="extended-mode-mplink" value="false"/>
<property key="stack-analysis" value="false"/>
<property key="stack-analysis-mcc18" value="false"/>
<property key="stack-analysis-mplink" value="false"/>
</C18LanguageToolchain>
<PICkit3PlatformTool>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze Peripherals" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="false"/>
<property key="memories.configurationmemory" value="false"/>
<property key="memories.eeprom" value="false"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="false"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x1fff7"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programmertogo.imagename" value=""/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmspeed" value="2"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x3f"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="voltagevalue" value="3.25"/>
</PICkit3PlatformTool>
</conf>
</confs>
</configurationDescriptor>
/PIC Projects/PIC_27J13/nbproject/Makefile-local-default.mk
0,0 → 1,37
#
# Generated Makefile - do not edit!
#
#
# This file contains information about the location of compilers and other tools.
# If you commmit this file into your revision control server, you will be able to
# to checkout the project and build it from the command line with make. However,
# if more than one person works on the same project, then this file might show
# conflicts since different users are bound to have compilers in different places.
# In that case you might choose to not commit this file and let MPLAB X recreate this file
# for each user. The disadvantage of not commiting this file is that you must run MPLAB X at
# least once so the file gets created and the project can be built. Finally, you can also
# avoid using this file at all if you are only building from the command line with make.
# You can invoke make with the values of the macros:
# $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ...
#
SHELL=cmd.exe
PATH_TO_IDE_BIN=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/
# Adding MPLAB X bin directory to path.
PATH:=C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/:$(PATH)
# Path to java used to run MPLAB X when this makefile was created
MP_JAVA_PATH="C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.6.0_32-windows-x64\java-windows/bin/"
OS_CURRENT="$(shell uname -s)"
MP_CC="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\mcc18.exe"
# MP_CPPC is not defined
# MP_BC is not defined
MP_AS="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\..\mpasm\MPASMWIN.exe"
MP_LD="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\mplink.exe"
MP_AR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\mplib.exe"
DEP_GEN=${MP_JAVA_PATH}java -jar "C:/Program Files (x86)/Microchip/MPLABX/mplab_ide/mplab_ide/modules/../../bin/extractobjectdependencies.jar"
MP_CC_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin"
# MP_CPPC_DIR is not defined
# MP_BC_DIR is not defined
MP_AS_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\..\mpasm"
MP_LD_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin"
MP_AR_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin"
# MP_BC_DIR is not defined
/PIC Projects/PIC_27J13/nbproject/Makefile-impl.mk
0,0 → 1,69
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL
 
 
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
 
 
# Project Name
PROJECTNAME=PIC_27J13
 
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
 
# All Configurations
ALLCONFS=default
 
 
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
 
 
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
 
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
 
 
 
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
 
 
 
# dependency checking support
.depcheck-impl:
# @echo "# This code depends on make tool being used" >.dep.inc
# @if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi
/PIC Projects/PIC_27J13/nbproject/Makefile-variables.mk
0,0 → 1,13
#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
# default configuration
CND_ARTIFACT_DIR_default=dist/default/production
CND_ARTIFACT_NAME_default=PIC_27J13.production.hex
CND_ARTIFACT_PATH_default=dist/default/production/PIC_27J13.production.hex
CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package
CND_PACKAGE_NAME_default=pic27j13.tar
CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/pic27j13.tar
/PIC Projects/PIC_27J13/nbproject/Package-default.bash
0,0 → 1,73
#!/bin/bash -x
 
#
# Generated - do not edit!
#
 
# Macros
TOP=`pwd`
CND_CONF=default
CND_DISTDIR=dist
TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging
TMPDIRNAME=tmp-packaging
OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
OUTPUT_BASENAME=PIC_27J13.${IMAGE_TYPE}.${OUTPUT_SUFFIX}
PACKAGE_TOP_DIR=pic27j13/
 
# Functions
function checkReturnCode
{
rc=$?
if [ $rc != 0 ]
then
exit $rc
fi
}
function makeDirectory
# $1 directory path
# $2 permission (optional)
{
mkdir -p "$1"
checkReturnCode
if [ "$2" != "" ]
then
chmod $2 "$1"
checkReturnCode
fi
}
function copyFileToTmpDir
# $1 from-file path
# $2 to-file path
# $3 permission
{
cp "$1" "$2"
checkReturnCode
if [ "$3" != "" ]
then
chmod $3 "$2"
checkReturnCode
fi
}
 
# Setup
cd "${TOP}"
mkdir -p ${CND_DISTDIR}/${CND_CONF}/package
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}
 
# Copy files and create directories and links
cd "${TOP}"
makeDirectory ${TMPDIR}/pic27j13/bin
copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
# Generate tar file
cd "${TOP}"
rm -f ${CND_DISTDIR}/${CND_CONF}/package/pic27j13.tar
cd ${TMPDIR}
tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/pic27j13.tar *
checkReturnCode
 
# Cleanup
cd "${TOP}"
rm -rf ${TMPDIR}
/PIC Projects/PIC_27J13/nbproject/project.properties
--- PIC_27J13/nbproject/project.xml (nonexistent)
+++ PIC_27J13/nbproject/project.xml (revision 342)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>com.microchip.mplab.nbide.embedded.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>PIC_27J13</name>
+ <creation-uuid>116783ce-ce82-4f46-901c-ed02c852cd72</creation-uuid>
+ <make-project-type>0</make-project-type>
+ <c-extensions>c</c-extensions>
+ <cpp-extensions/>
+ <header-extensions>h</header-extensions>
+ <sourceEncoding>ISO-8859-1</sourceEncoding>
+ <make-dep-projects/>
+ </data>
+ </configuration>
+</project>
/PIC Projects/PIC_27J13/adc.h
0,0 → 1,48
#ifndef ADC_H
#define ADC_H
 
#define ADC_CHANNEL_AN0 0b0000
#define ADC_CHANNEL_AN1 0b0001
#define ADC_CHANNEL_AN2 0b0010
#define ADC_CHANNEL_AN3 0b0011
#define ADC_CHANNEL_AN4 0b0100
#define ADC_CHANNEL_AN5 0b0101
#define ADC_CHANNEL_AN6 0b0110
#define ADC_CHANNEL_AN7 0b0111
#define ADC_CHANNEL_AN8 0b1000
#define ADC_CHANNEL_AN9 0b1001
#define ADC_CHANNEL_AN10 0b1010
#define ADC_CHANNEL_AN11 0b1011
#define ADC_CHANNEL_AN12 0b1100
#define ADC_CHANNEL_VDDCORE 0b1110
#define ADC_CHANNEL_ABG 0b1111
 
#define ADC_TAD_20 0b111
#define ADC_TAD_16 0b110
#define ADC_TAD_12 0b101
#define ADC_TAD_8 0b100
#define ADC_TAD_6 0b011
#define ADC_TAD_4 0b010
#define ADC_TAD_2 0b001
#define ADC_TAD_0 0b000
 
#define ADC_FOSC_64 0b110
#define ADC_FOSC_32 0b010
#define ADC_FOSC_16 0b101
#define ADC_FOSC_8 0b001
#define ADC_FOSC_4 0b100
#define ADC_FOSC_2 0b000
#define ADC_FOSC_FRC 0b011
 
typedef struct __ADC_DATA {
unsigned char last_channel;
unsigned int result;
} ADC_DATA;
 
void ADC_Init(unsigned char TAD, unsigned char FOSC);
void ADC_Start(unsigned char channel);
void ADC_Stop(void);
void ADC_Interrupt_Handler(void);
char ADC_Get_Result(unsigned int *ret);
 
#endif
/PIC Projects/PIC_27J13/defines.h
0,0 → 1,123
#ifndef DEFINES_H
#define DEFINES_H
 
#include <p18f27j13.h>
#include "uart.h"
 
#define UART1_RX_TO_BUFFER
//#define UART1_RX_TO_XBEE
 
// Option to disable SPI MISO
#define SPI2_WRITE_ONLY
 
//#define _DEBUG
 
//#define _TEST_UART
//#define _TEST_I2C_MASTER
//#define _TEST_I2C_SLAVE
//#define _TEST_SPI
//#define _TEST_NFC
//#define _TEST_LED_BACKPACK
//#define _TEST_SSD1306_OLED
//#define _TEST_SSD1331_OLED
//#define _TEST_ADC
//#define _TEST_XBEE
//#define _TEST_NFC_TO_SSD1306_OLED
//#define _TEST_TIMER1_RTC
//#define _TEST_LUX
//#define _TEST_OLED_CHAR
//#define _TEST_BMP
 
// Enable or disable debug prints depending on project preprocessor (_DEBUG)
#ifdef _DEBUG
#define DBG_PRINT_MAIN(x) UART1_WriteS(x)
#define DBG_PRINT_MAIN_F(x) UART1_WriteF(x)
#define DBG_PRINT_UART(x) UART1_WriteS(x)
#define DBG_PRINT_I2C(x) UART1_WriteS(x)
#define DBG_PRINT_SPI(x) UART1_WriteS(x)
#define DBG_PRINT_XBEE(x) UART1_WriteS(x)
#define DBG_PRINT_PORTB_INT(x)
#define DBG_PRINT_INT(x)
#define DBG_PRINT_LUX(x)
#define DBG_PRINT_BMP(x)
#else
#define DBG_PRINT_MAIN(x)
#define DBG_PRINT_MAIN_F(x)
#define DBG_PRINT_UART(x)
#define DBG_PRINT_I2C(x)
#define DBG_PRINT_SPI(x)
#define DBG_PRINT_XBEE(x)
#define DBG_PRINT_PORTB_INT(x)
#define DBG_PRINT_INT(x)
#define DBG_PRINT_LUX(x)
#define DBG_PRINT_BMP(x)
#endif
 
// Pin allocations
#define LED_BLUE_TRIS TRISCbits.TRISC5
#define LED_BLUE_LAT LATCbits.LATC5
#define LED_RED_TRIS TRISCbits.TRISC2
#define LED_RED_LAT LATCbits.LATC2
 
#define ADC_AN0_TRIS TRISAbits.TRISA0
#define ADC_AN1_TRIS TRISAbits.TRISA1
#define ADC_AN2_TRIS TRISAbits.TRISA2
 
#define XBEE_CTS_TRIS TRISBbits.TRISB0
#define XBEE_CTS_LAT LATBbits.LATB0
#define XBEE_CTS_PORT PORTBbits.RB0
#define XBEE_RTS_TRIS TRISBbits.TRISB1
#define XBEE_RTS_LAT LATBbits.LATB1
 
#define SPI_MOSI_TRIS TRISBbits.TRISB0
#ifndef SPI2_WRITE_ONLY
#define SPI_MISO_TRIS TRISBbits.TRISB0
#endif
#define SPI_CLK_TRIS TRISAbits.TRISA0
#define SPI_DC_SELECT_TRIS TRISAbits.TRISA1
#define SPI_DC_SELECT_LAT LATAbits.LATA1
#define SPI_RESET_TRIS TRISAbits.TRISA2
#define SPI_RESET_LAT LATAbits.LATA2
#define SPI_SLAVE_SELECT_TRIS TRISAbits.TRISA3
#define SPI_SLAVE_SELECT_LAT LATAbits.LATA3
 
#define PARALLEL_RS_TRIS TRISBbits.TRISB7
#define PARALLEL_RS_LAT LATBbits.LATB7
#define PARALLEL_RW_TRIS TRISBbits.TRISB6
#define PARALLEL_RW_LAT LATBbits.LATB6
#define PARALLEL_EN_TRIS TRISBbits.TRISB5
#define PARALLEL_EN_LAT LATBbits.LATB5
#define PARALLEL_D4_TRIS TRISBbits.TRISB4
#define PARALLEL_D4_LAT LATBbits.LATB4
#define PARALLEL_D5_TRIS TRISBbits.TRISB3
#define PARALLEL_D5_LAT LATBbits.LATB3
#define PARALLEL_D6_TRIS TRISBbits.TRISB2
#define PARALLEL_D6_LAT LATBbits.LATB2
#define PARALLEL_D7_TRIS TRISBbits.TRISB1
#define PARALLEL_D7_LAT LATBbits.LATB1
#define PARALLEL_BUSY_TRIS TRISBbits.TRISB1
#define PARALLEL_BUSY_PORT PORTBbits.RB1
 
#define NFC_IRQ_TRIS TRISAbits.TRISA5
#define NFC_IRQ_PORT PORTAbits.RA5
//#define NFC_RESET_TRIS TRISCbits.TRISC2
//#define NFC_RESET_LAT LATCbits.LATC2
 
#define I2C_CLK_TRIS TRISCbits.TRISC3
#define I2C_DAT_TRIS TRISCbits.TRISC4
 
#define UART1_RX_TRIS TRISCbits.TRISC7
#define UART1_TX_TRIS TRISCbits.TRISC6
 
// PPS bindings (RP Pins)
#define PPS_SPI2_CLK_IN 0 // A0
#define PPS_SPI2_CLK_OUT RPOR0 // A0
#define PPS_SPI2_MOSI RPOR3 // B0
#ifndef SPI2_WRITE_ONLY
#define PPS_SPI2_MISO 3 // NA
#endif
 
//#define PPS_UART2_RX 5
//#define PPS_UART2_TX RPOR6
 
#endif
/PIC Projects/PIC_27J13/i2c.h
0,0 → 1,81
#ifndef I2C_H
#define I2C_H
 
#define MAXI2CBUF 64
 
// I2C Operating Speed
#define I2C_400KHZ 0x0
#define I2C_100KHZ 0x1
 
// Operating State
#define I2C_IDLE 0x1
#define I2C_STARTED 0x2
#define I2C_RCV_DATA 0x3
#define I2C_SEND_DATA 0x4
#define I2C_SEND_ADDR 0x5
#define I2C_SEND_ADDR_2 0x6
#define I2C_CHECK_ACK_SEND 0x7
#define I2C_CHECK_ACK_RECV 0x8
#define I2C_CHECK_ACK_RESTART 0x9
#define I2C_REQ_DATA 0xA
#define I2C_SEND_STOP 0xB
#define I2C_SEND_START 0xC
 
// Operating Mode
#define I2C_MODE_SLAVE 0x10
#define I2C_MODE_MASTER 0x11
 
// Master Status
#define I2C_MASTER_SEND 0x20
#define I2C_MASTER_RECV 0x21
#define I2C_MASTER_RESTART 0x22
#define I2C_MASTER_IDLE 0x23
 
// Return Status
#define I2C_SEND_OK 0x30
#define I2C_SEND_FAIL 0x31
#define I2C_RECV_OK 0x32
#define I2C_RECV_FAIL 0x33
#define I2C_DATA_AVAL 0x34
#define I2C_ERR_NOADDR 0x35
#define I2C_ERR_OVERRUN 0x36
#define I2C_ERR_NODATA 0x37
#define I2C_ERR_BUFFER_OVERRUN 0x38
 
typedef struct __I2C_DATA {
unsigned char buffer_in[MAXI2CBUF];
unsigned char buffer_in_len;
unsigned char buffer_in_len_tmp;
unsigned char buffer_in_read_ind;
unsigned char buffer_in_write_ind;
unsigned char buffer_out[MAXI2CBUF];
unsigned char buffer_out_len;
unsigned char buffer_out_ind;
 
unsigned char operating_mode;
unsigned char operating_state;
unsigned char return_status;
 
unsigned char master_dest_addr;
unsigned char master_status;
unsigned char slave_in_last_byte;
unsigned char slave_sending_data;
} I2C_DATA;
 
void I2C_Init(void);
void I2C_Interrupt_Handler(void);
void I2C_Interrupt_Slave(void);
void I2C_Interrupt_Master(void);
void I2C_Configure_Slave(unsigned char);
void I2C_Configure_Master(unsigned char speed);
void I2C_Master_Send(unsigned char address, unsigned char length, unsigned char *msg);
void I2C_Master_Recv(unsigned char address, unsigned char length);
void I2C_Master_Restart(unsigned char address, unsigned char msg, unsigned char length);
unsigned char I2C_Get_Status(void);
unsigned char I2C_Buffer_Len(void);
unsigned char I2C_Read_Buffer(char *buffer);
unsigned char I2C_Process_Send(unsigned char);
 
#endif
/PIC Projects/PIC_27J13/interrupts.h
0,0 → 1,18
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
 
// Note: As the interrupt system is currently setup, at the end
// of each high-priority interrupt, the system will check to
// see if the processor may be put to sleep. This is done
// with the call sleep_high_interrupt_if_okay() which is defined
// in msg_queues.h -- init_queues() MUST be called prior to
// enabling interrupts if sleep_high_interrupt_if_okay() is called!
 
// Initialize the interrupts
void Interrupt_Init(void);
 
// Enable the interrupts (high and low priority)
void Interrupt_Enable(void);
void Interrupt_Disable(void);
 
#endif
/PIC Projects/PIC_27J13/pin_interrupts.h
0,0 → 1,10
#ifndef PIN_INTERRUPTS_H
#define PIN_INTERRUPTS_H
 
void intx_init(void);
void int1_interrupt_handler(void);
 
void port_b_int_init(void);
void port_b_int_interrupt_handler(void);
 
#endif
/PIC Projects/PIC_27J13/pwm.h
0,0 → 1,10
#ifndef PWM_H
#define PWM_H
 
void pwm_init(void);
void pwm_start(void);
void pwm_stop(void);
 
static char pwm_on = 0;
 
#endif
/PIC Projects/PIC_27J13/timers.h
0,0 → 1,9
#ifndef TIMERS_H
#define TIMERS_H
 
void Timer1_Init(void);
void Timer1_Enable(void);
void Timer1_Disable(void);
void Timer1_Interrupt_Handler(void);
 
#endif
/PIC Projects/PIC_27J13/uart.h
0,0 → 1,32
#ifndef UART_H
#define UART_H
 
#define MAXUARTBUF 125
 
#define UART1_BREAK_CHAR 0x0D //(CR)
 
#define UART1_RECV_BUFFER
//#define UART1_RECV_XBEE
 
typedef struct __UART_DATA {
unsigned char buffer_in[MAXUARTBUF];
unsigned char buffer_in_read_ind;
unsigned char buffer_in_write_ind;
unsigned char buffer_in_len;
unsigned char buffer_in_len_tmp;
 
unsigned char buffer_out[MAXUARTBUF];
unsigned char buffer_out_ind;
unsigned char buffer_out_len;
} UART_DATA;
 
void UART1_Init(void);
void UART1_Recv_Interrupt_Handler(void);
void UART1_Send_Interrupt_Handler(void);
void UART1_WriteS(const rom char *fmt, ...);
void UART1_WriteF(float f, unsigned char m);
void UART1_WriteB(const char *msg, unsigned char length);
void UART1_WriteC(const unsigned char c);
unsigned char UART1_Buffer_Len(void);
unsigned char UART1_Read_Buffer(unsigned char *buffer);
#endif
/PIC Projects/PIC_27J13/xbee.h
0,0 → 1,269
#ifndef XBEE_H
#define XBEE_H
 
#define XBEE_BUFFER_SIZE 227
 
// If API mode = 2 is enabled
#define XBEE_USE_ESCAPE_CHAR
 
#define XBEE_ESCAPE_VAL 0x20
#define XBEE_START_DELIMITER 0x7E
#define XBEE_ESCAPE_CHAR 0x7D
#define XBEE_XON 0x11
#define XBEE_XOFF 0x13
 
// Expected 'next' state
#define XBEE_STATE_READ_START 10
#define XBEE_STATE_READ_LENGTH_HIGH 11
#define XBEE_STATE_READ_LENGTH_LOW 12
#define XBEE_STATE_READ_FRAME_DATA 13
#define XBEE_STATE_READ_CHECKSUM 14
 
// Command Frame Type
#define XBEE_TX_AT_COMMAND 0x08
#define XBEE_TX_AT_COMMAND_QUEUE 0x09
#define XBEE_RX_AT_COMMAND_RESPONSE 0x88
 
#define XBEE_TX_DATA_PACKET 0x10
#define XBEE_RX_DATA_PACKET 0x90
#define XBEE_RX_DATA_TX_STATUS 0x8B
#define XBEE_RX_IO_DATA_SAMPLE 0x92
#define XBEE_TX_EXPLICIT_COMMAND 0x11
#define XBEE_RX_EXPLICIT_COMMAND 0x91
 
#define XBEE_TX_REMOTE_AT_COMMAND 0x17
#define XBEE_RX_REMOTE_AT_COMMAND_RESPONSE 0x97
 
#define XBEE_TX_CREATE_SOURCE_ROUTE 0x21
#define XBEE_RX_ROUTE_RECORD 0xA1
#define XBEE_RX_NODE_IDENTIFICATION 0x95
#define XBEE_RX_FRAME_MODEM_STATUS 0x8A
 
typedef struct {
union {
unsigned long long_value;
unsigned char char_value[4]; // Little Endian!!
} UPPER_32;
union {
unsigned long long_value;
unsigned char char_value[4]; // Little Endian!!
} LOWER_32;
} XBEE_ADDRESS_64;
 
typedef struct {
union {
unsigned int int_value;
unsigned char char_value[2]; // Little Endian!!
} INT_16;
} XBEE_ADDRESS_16;
 
// Unique Frame Components
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
unsigned char command[2];
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_TX_AT_COMMAND_FRAME;
#define XBEE_TX_AT_COMMAND_FRAME_SIZE 4
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
unsigned char command[2];
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_TX_AT_COMMAND_QUEUE_FRAME;
#define XBEE_TX_AT_COMMAND_QUEUE_FRAME_SIZE 4
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
unsigned char command[2];
unsigned char command_status;
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_RX_AT_COMMAND_RESPONSE_FRAME;
#define XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE 5
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
unsigned char broadcast_radius;
unsigned char options;
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_TX_DATA_PACKET_FRAME;
#define XBEE_TX_DATA_PACKET_FRAME_SIZE 14
 
typedef struct {
unsigned char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char recieve_options;
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_RX_DATA_PACKET_FRAME;
#define XBEE_RX_DATA_PACKET_FRAME_SIZE 12
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_16 destination_16;
unsigned char transmit_retry_count;
unsigned char delivery_status;
unsigned char discovery_status;
} XBEE_RX_DATA_TX_STATUS_FRAME;
#define XBEE_RX_DATA_TX_STATUS_FRAME_SIZE 7
 
typedef struct {
unsigned char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char recieve_options;
unsigned char number_of_samples;
unsigned char digital_ch_mask[2];
unsigned char analog_ch_mask;
unsigned char digital_samples[2];
unsigned char analog_samples[8];
} XBEE_RX_IO_DATA_SAMPLE_FRAME;
#define XBEE_RX_IO_DATA_SAMPLE_FRAME_SIZE 26
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
unsigned char source_endpoint;
unsigned char destination_endpoint;
unsigned char cluster_id[2];
unsigned char profile_id[2];
unsigned char broadcast_radius;
unsigned char transmit_options;
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_TX_EXPLICIT_COMMAND_FRAME;
#define XBEE_TX_EXPLICIT_COMMAND_FRAME_SIZE 20
 
typedef struct {
unsigned char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char source_endpoint;
unsigned char destination_endpoint;
unsigned char cluster_id[2];
unsigned char profile_id[2];
unsigned char recieve_options;
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_RX_EXPLICIT_COMMAND_FRAME;
#define XBEE_RX_EXPLICIT_COMMAND_FRAME_SIZE 18
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
unsigned char remote_options;
unsigned char command[2];
unsigned char data[XBEE_BUFFER_SIZE];
} XBEE_TX_REMOTE_AT_COMMAND_FRAME;
#define XBEE_TX_REMOTE_AT_COMMAND_FRAME_SIZE 15
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char command[2];
unsigned char command_status;
unsigned char command_data[4];
} XBEE_RX_REMOTE_AT_COMMAND_FRAME;
#define XBEE_RX_REMOTE_AT_COMMAND_FRAME_SIZE 19
 
typedef struct {
unsigned char frame_type;
unsigned char frame_id;
XBEE_ADDRESS_64 destination_64;
XBEE_ADDRESS_16 destination_16;
unsigned char route_options;
unsigned char num_of_addresses;
unsigned char addresses[XBEE_BUFFER_SIZE];
} XBEE_TX_CREATE_SOURCE_ROUTE_FRAME;
#define XBEE_TX_CREATE_SOURCE_ROUTE_FRAME_SIZE 14
 
typedef struct {
unsigned char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char recieve_options;
unsigned char num_of_addresses;
unsigned char addresses[XBEE_BUFFER_SIZE];
} XBEE_RX_ROUTE_RECORD_FRAME;
#define XBEE_RX_ROUTE_RECORD_FRAME_SIZE 13
 
typedef struct {
unsigned char frame_type;
XBEE_ADDRESS_64 source_64;
XBEE_ADDRESS_16 source_16;
unsigned char recieve_options;
XBEE_ADDRESS_16 remote_16;
XBEE_ADDRESS_64 remote_64;
unsigned char NI_string[2];
XBEE_ADDRESS_16 parent_16;
unsigned char device_type;
unsigned char source_event;
unsigned char profile_id[2];
unsigned char manufacturer_id[2];
} XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME;
#define XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME_SIZE 32
 
typedef struct {
unsigned char frame_type;
unsigned char status;
} XBEE_RX_MODEM_STATUS_FRAME;
#define XBEE_RX_MODEM_STATUS_FRAME_SIZE 2
 
// Common Frame Components
typedef struct __XBEE_FRAME {
unsigned char start_delimiter;
XBEE_ADDRESS_16 length;
union {
XBEE_TX_AT_COMMAND_FRAME TX_AT_COMMAND;
XBEE_TX_AT_COMMAND_QUEUE_FRAME TX_AT_COMMAND_QUEUE;
XBEE_RX_AT_COMMAND_RESPONSE_FRAME RX_AT_COMMAND_RESPONSE;
XBEE_TX_DATA_PACKET_FRAME TX_DATA_PACKET;
XBEE_RX_DATA_PACKET_FRAME RX_DATA_PACKET;
XBEE_RX_DATA_TX_STATUS_FRAME RX_DATA_TX_STATUS;
XBEE_RX_IO_DATA_SAMPLE_FRAME RX_IO_DATA_SAMPLE;
XBEE_TX_EXPLICIT_COMMAND_FRAME TX_EXPLICIT_COMMAND;
XBEE_RX_EXPLICIT_COMMAND_FRAME RX_EXPLICIT_COMMAND;
XBEE_TX_REMOTE_AT_COMMAND_FRAME TX_REMOTE_AT_COMMAND;
XBEE_RX_REMOTE_AT_COMMAND_FRAME RX_REMOTE_AT_COMMAND;
XBEE_TX_CREATE_SOURCE_ROUTE_FRAME TX_CREATE_SOURCE_ROUTE;
XBEE_RX_ROUTE_RECORD_FRAME RX_ROUTE_RECORD;
XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME RX_NODE_IDENTIFICATION;
XBEE_RX_MODEM_STATUS_FRAME RX_MODEM_STATUS;
} FRAME;
} XBEE_FRAME;
 
// Overall Data Structure
typedef struct __xbee_data {
XBEE_FRAME rcv_frame;
unsigned int dataind;
unsigned char checksum_sum;
unsigned char read_state;
unsigned char frame_rdy;
unsigned char escape_flag;
} XBEE_DATA;
 
 
void XBee_Init(void);
void XBee_Serial_In(unsigned char);
void XBee_Process_Received_Frame(void);
void XBee_Process_Transmit_Frame(unsigned char *data, unsigned char length);
 
unsigned int XBee_Get_Received_Frame(unsigned char *frame);
 
void XBee_Set_RTS(unsigned char);
unsigned char XBee_Read_CTS(void);
 
void XBee_Convert_Endian_64(XBEE_ADDRESS_64 *src);
void XBee_Convert_Endian_16(XBEE_ADDRESS_16 *src);
 
#endif
/PIC Projects/PIC_27J13/led_HT16K33.c
0,0 → 1,137
#include "led_HT16K33.h"
#include "i2c.h"
 
static const char numbertable[] = {
0x3F /* 0 */,
0x06 /* 1 */,
0x5B /* 2 */,
0x4F /* 3 */,
0x66 /* 4 */,
0x6D /* 5 */,
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F, /* 9 */
};
 
static const char alphatable[] = {
0x77, /* a */
0x7C, /* b */
0x39, /* C */
0x5E, /* d */
0x79, /* E */
0x71, /* F */
};
 
static LED_DATA led_data;
static LED_DATA *led_data_p = &led_data;
 
void LED_Init() {
led_data_p->i2c_address = 0x70;
}
 
void LED_Start() {
unsigned char result;
unsigned char c = 0x21; // Cmd to turn on oscillator
I2C_Master_Send(led_data_p->i2c_address, 1, &c);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
 
LED_Blink_Rate(HT16K33_BLINK_OFF);
LED_Set_Brightness(15); // Max brightness
LED_Clear();
LED_Write_Display();
}
 
void LED_Set_Brightness(unsigned char c) {
unsigned char result;
if (c > 15) c = 15;
c |= 0xE0;
 
I2C_Master_Send(led_data_p->i2c_address, 1, &c);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
}
 
void LED_Blink_Rate(unsigned char c) {
unsigned char buffer;
 
if (c > 3) c = 0;
 
buffer = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (c << 1);
 
I2C_Master_Send(led_data_p->i2c_address, 1, &buffer);
buffer = I2C_Get_Status();
while (!buffer) {
buffer = I2C_Get_Status();
}
}
 
void LED_Write_Display() {
unsigned char result;
led_data_p->display_buffer[0] = 0x00; // Start at address 0x00
I2C_Master_Send(led_data_p->i2c_address, 17, led_data_p->display_buffer);
 
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
}
 
void LED_Clear() {
unsigned char c;
for (c = 0; c < 17; c++) {
led_data_p->display_buffer[c] = 0;
}
}
 
void LED_Draw_Colon(unsigned char c) {
if (c) {
led_data_p->display_buffer[5] = 0xFF;
} else {
led_data_p->display_buffer[5] = 0;
}
}
 
void LED_Write_Digit_Raw(unsigned char loc, unsigned char bitmask) {
if (loc > 4) return;
led_data_p->display_buffer[(loc<<1)+1] = bitmask;
}
 
void LED_Write_Digit_Num(unsigned char loc, unsigned char num, unsigned char dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, numbertable[num] | dot << 7);
}
 
void LED_Write_Digit_Alpha(unsigned char loc, unsigned char alpha, unsigned char dot) {
if (loc > 4) return;
if (loc > 1) loc++;
LED_Write_Digit_Raw(loc, alphatable[alpha] | dot << 7);
}
 
void LED_Write_Num(unsigned int i) {
LED_Write_Digit_Num(0, (i%10000)/1000, 0);
LED_Write_Digit_Num(1, (i%1000)/100, 0);
LED_Write_Digit_Num(2, (i%100)/10, 0);
LED_Write_Digit_Num(3, i%10, 0);
 
if (i < 10) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
LED_Write_Digit_Raw(3, 0);
} else if (i < 100) {
LED_Write_Digit_Raw(0, 0);
LED_Write_Digit_Raw(1, 0);
} else if (i < 1000) {
LED_Write_Digit_Raw(0, 0);
}
LED_Write_Display();
}
/PIC Projects/PIC_27J13/led_HT16K33.h
0,0 → 1,32
#ifndef LED_BACKPACK_H
#define LED_BACKPACK_H
 
#define HT16K33_BLINK_CMD 0x80
#define HT16K33_BLINK_DISPLAYON 0x01
#define HT16K33_BLINK_OFF 0
#define HT16K33_BLINK_2HZ 1
#define HT16K33_BLINK_1HZ 2
#define HT16K33_BLINK_HALFHZ 3
 
#define HT16K33_CMD_BRIGHTNESS 0x0E
 
typedef struct {
unsigned char i2c_address;
unsigned char display_buffer[17];
} LED_DATA;
 
void LED_Init(void);
void LED_Start(void);
void LED_Set_Brightness(unsigned char c);
void LED_Blink_Rate(unsigned char c);
void LED_Write_Display(void);
void LED_Clear(void);
void LED_Draw_Colon(unsigned char c);
void LED_Write_Digit_Raw(unsigned char loc, unsigned char bitmask);
void LED_Write_Digit_Num(unsigned char loc, unsigned char num, unsigned char dot);
void LED_Write_Digit_Alpha(unsigned char loc, unsigned char alpha, unsigned char dot);
void LED_Write_Num(unsigned int i);
 
 
#endif /* LED_BACKPACK_H */
 
/PIC Projects/PIC_27J13/lux_TSL2561.c
0,0 → 1,229
#include "lux_TSL2561.h"
#include "defines.h"
#include "i2c.h"
#include <delays.h>
 
static TSL2561_DATA tsl2561_data;
static TSL2561_DATA *tsl2561_data_p = &tsl2561_data;
 
void LUX_Init(unsigned char address) {
tsl2561_data_p->address = address;
tsl2561_data_p->integration = TSL2561_INTEGRATIONTIME_13MS;
tsl2561_data_p->gain = TSL2561_GAIN_16X;
}
 
void LUX_Begin(void) {
unsigned char i, result, length, buffer[10];
unsigned char toSend = TSL2561_REGISTER_ID;
DBG_PRINT_LUX("Sending %X to address %X\r\n", toSend, tsl2561_data_p->address);
I2C_Master_Send(tsl2561_data_p->address, 1, &toSend);
do {
result = I2C_Get_Status();
} while (!result);
 
I2C_Master_Recv(tsl2561_data_p->address, 1);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
DBG_PRINT_LUX("Received %d bytes: ", length);
for (i = 0; i < length; i++) {
DBG_PRINT_LUX("%c ", buffer[i]);
}
DBG_PRINT_LUX("\r\n");
 
// Set default integration time and gain
LUX_Set_Timing(tsl2561_data_p->integration);
LUX_Set_Gain(tsl2561_data_p->gain);
 
// Start the chip in power-down mode
LUX_Disable();
}
 
void LUX_Enable() {
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
 
void LUX_Disable() {
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
 
void LUX_Set_Gain(tsl2561Gain_t gain) {
LUX_Enable();
tsl2561_data_p->gain = gain;
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
void LUX_Set_Timing(tsl2561IntegrationTime_t integration) {
LUX_Enable();
tsl2561_data_p->integration = integration;
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
unsigned long LUX_Calculate_Lux(unsigned int ch0, unsigned int ch1) {
unsigned long chScale, channel0, channel1, ratio1, ratio, temp, lux;
unsigned int b, m;
 
switch (tsl2561_data_p->integration) {
case TSL2561_INTEGRATIONTIME_13MS:
chScale = TSL2561_LUX_CHSCALE_TINT0;
break;
case TSL2561_INTEGRATIONTIME_101MS:
chScale = TSL2561_LUX_CHSCALE_TINT1;
break;
default: // No scaling ... integration time = 402ms
chScale = (1 << TSL2561_LUX_CHSCALE);
break;
}
 
// Scale for gain (1x or 16x)
if (!tsl2561_data_p->gain)
chScale = chScale << 4;
 
// scale the channel values
channel0 = (ch0 * chScale) >> TSL2561_LUX_CHSCALE;
channel1 = (ch1 * chScale) >> TSL2561_LUX_CHSCALE;
 
// find the ratio of the channel values (Channel1/Channel0)
ratio1 = 0;
if (channel0 != 0)
ratio1 = (channel1 << (TSL2561_LUX_RATIOSCALE+1)) / channel0;
 
// round the ratio value
ratio = (ratio1 + 1) >> 1;
 
#ifdef TSL2561_PACKAGE_CS
if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1C)) {
b = TSL2561_LUX_B1C; m = TSL2561_LUX_M1C;
} else if (ratio <= TSL2561_LUX_K2C) {
b = TSL2561_LUX_B2C; m = TSL2561_LUX_M2C;
} else if (ratio <= TSL2561_LUX_K3C) {
b = TSL2561_LUX_B3C; m = TSL2561_LUX_M3C;
} else if (ratio <= TSL2561_LUX_K4C) {
b = TSL2561_LUX_B4C; m = TSL2561_LUX_M4C;
} else if (ratio <= TSL2561_LUX_K5C) {
b = TSL2561_LUX_B5C; m = TSL2561_LUX_M5C;
} else if (ratio <= TSL2561_LUX_K6C) {
b = TSL2561_LUX_B6C; m = TSL2561_LUX_M6C;
} else if (ratio <= TSL2561_LUX_K7C) {
b = TSL2561_LUX_B7C; m = TSL2561_LUX_M7C;
} else if (ratio > TSL2561_LUX_K8C) {
b = TSL2561_LUX_B8C; m = TSL2561_LUX_M8C;
}
#else
if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1T)) {
b = TSL2561_LUX_B1T; m = TSL2561_LUX_M1T;
} else if (ratio <= TSL2561_LUX_K2T) {
b = TSL2561_LUX_B2T; m = TSL2561_LUX_M2T;
} else if (ratio <= TSL2561_LUX_K3T) {
b = TSL2561_LUX_B3T; m = TSL2561_LUX_M3T;
} else if (ratio <= TSL2561_LUX_K4T) {
b = TSL2561_LUX_B4T; m = TSL2561_LUX_M4T;
} else if (ratio <= TSL2561_LUX_K5T) {
b = TSL2561_LUX_B5T; m = TSL2561_LUX_M5T;
} else if (ratio <= TSL2561_LUX_K6T) {
b = TSL2561_LUX_B6T; m = TSL2561_LUX_M6T;
} else if (ratio <= TSL2561_LUX_K7T) {
b = TSL2561_LUX_B7T; m = TSL2561_LUX_M7T;
} else if (ratio > TSL2561_LUX_K8T) {
b = TSL2561_LUX_B8T; m = TSL2561_LUX_M8T;
}
#endif
temp = ((channel0 * b) - (channel1 * m));
 
// do not allow negative lux value
if (temp < 0)
temp = 0;
 
// round lsb (2^(LUX_SCALE-1))
temp += (1 << (TSL2561_LUX_LUXSCALE-1));
 
// strip off fractional portion
lux = temp >> TSL2561_LUX_LUXSCALE;
 
return lux;
}
 
unsigned long LUX_Get_Full_Luminosity() {
unsigned long x;
 
// Enable the device by setting the control bit to 0x03
LUX_Enable();
 
// Wait x ms for ADC to complete
switch (tsl2561_data_p->integration) {
case TSL2561_INTEGRATIONTIME_13MS:
Delay10KTCYx(67);
break;
case TSL2561_INTEGRATIONTIME_101MS:
Delay10KTCYx(255);
Delay10KTCYx(230);
break;
default:
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(145);
break;
}
 
x = LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
 
LUX_Disable();
 
return x;
}
 
unsigned int LUX_Get_Luminosity(unsigned char channel) {
unsigned long x = LUX_Get_Full_Luminosity();
 
if (channel == 0) {
// Reads two byte value from channel 0 (visible + infrared)
return (x & 0xFFFF);
} else if (channel == 1) {
// Reads two byte value from channel 1 (infrared)
return (x >> 16);
} else if (channel == 2) {
// Reads all and subtracts out just the visible!
return ( (x & 0xFFFF) - (x >> 16));
}
 
// Unknown channel!
return 0;
}
 
void LUX_Write_2_Bytes(unsigned char reg, unsigned char value) {
unsigned char buffer[2], result;
buffer[0] = reg;
buffer[1] = value;
I2C_Master_Send(tsl2561_data_p->address, 2, buffer);
do {
result = I2C_Get_Status();
} while (!result);
}
 
unsigned int LUX_Read_2_Bytes(unsigned char reg) {
unsigned char result, length, buffer[2];
unsigned int ret;
 
I2C_Master_Restart(tsl2561_data_p->address, reg, 2);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
ret = buffer[1] << 8;
ret |= buffer[0];
 
return ret;
}
/PIC Projects/PIC_27J13/lux_TSL2561.h
0,0 → 1,134
#ifndef LUX_TSL2561_H
#define LUX_TSL2561_H
 
#define TSL2561_VISIBLE 2 // channel 0 - channel 1
#define TSL2561_INFRARED 1 // channel 1
#define TSL2561_FULLSPECTRUM 0 // channel 0
 
// 3 i2c address options!
#define TSL2561_ADDR_LOW 0x29
#define TSL2561_ADDR_FLOAT 0x39
#define TSL2561_ADDR_HIGH 0x49
 
// Lux calculations differ slightly for CS package
//#define TSL2561_PACKAGE_CS
#define TSL2561_PACKAGE_T_FN_CL
 
#define TSL2561_READBIT (0x01)
 
#define TSL2561_COMMAND_BIT (0x80) // Must be 1
#define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
#define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
#define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write
 
#define TSL2561_CONTROL_POWERON (0x03)
#define TSL2561_CONTROL_POWEROFF (0x00)
 
#define TSL2561_LUX_LUXSCALE (14) // Scale by 2^14
#define TSL2561_LUX_RATIOSCALE (9) // Scale ratio by 2^9
#define TSL2561_LUX_CHSCALE (10) // Scale channel values by 2^10
#define TSL2561_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^TSL2561_LUX_CHSCALE
#define TSL2561_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^TSL2561_LUX_CHSCALE
 
// T, FN and CL package values
#define TSL2561_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
#define TSL2561_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
#define TSL2561_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
#define TSL2561_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
#define TSL2561_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
#define TSL2561_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
#define TSL2561_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
#define TSL2561_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
#define TSL2561_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
#define TSL2561_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
#define TSL2561_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
#define TSL2561_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
#define TSL2561_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
#define TSL2561_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
#define TSL2561_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
#define TSL2561_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
#define TSL2561_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
#define TSL2561_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
#define TSL2561_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
#define TSL2561_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
 
// CS package values
#define TSL2561_LUX_K1C (0x0043) // 0.130 * 2^RATIO_SCALE
#define TSL2561_LUX_B1C (0x0204) // 0.0315 * 2^LUX_SCALE
#define TSL2561_LUX_M1C (0x01ad) // 0.0262 * 2^LUX_SCALE
#define TSL2561_LUX_K2C (0x0085) // 0.260 * 2^RATIO_SCALE
#define TSL2561_LUX_B2C (0x0228) // 0.0337 * 2^LUX_SCALE
#define TSL2561_LUX_M2C (0x02c1) // 0.0430 * 2^LUX_SCALE
#define TSL2561_LUX_K3C (0x00c8) // 0.390 * 2^RATIO_SCALE
#define TSL2561_LUX_B3C (0x0253) // 0.0363 * 2^LUX_SCALE
#define TSL2561_LUX_M3C (0x0363) // 0.0529 * 2^LUX_SCALE
#define TSL2561_LUX_K4C (0x010a) // 0.520 * 2^RATIO_SCALE
#define TSL2561_LUX_B4C (0x0282) // 0.0392 * 2^LUX_SCALE
#define TSL2561_LUX_M4C (0x03df) // 0.0605 * 2^LUX_SCALE
#define TSL2561_LUX_K5C (0x014d) // 0.65 * 2^RATIO_SCALE
#define TSL2561_LUX_B5C (0x0177) // 0.0229 * 2^LUX_SCALE
#define TSL2561_LUX_M5C (0x01dd) // 0.0291 * 2^LUX_SCALE
#define TSL2561_LUX_K6C (0x019a) // 0.80 * 2^RATIO_SCALE
#define TSL2561_LUX_B6C (0x0101) // 0.0157 * 2^LUX_SCALE
#define TSL2561_LUX_M6C (0x0127) // 0.0180 * 2^LUX_SCALE
#define TSL2561_LUX_K7C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B7C (0x0037) // 0.00338 * 2^LUX_SCALE
#define TSL2561_LUX_M7C (0x002b) // 0.00260 * 2^LUX_SCALE
#define TSL2561_LUX_K8C (0x029a) // 1.3 * 2^RATIO_SCALE
#define TSL2561_LUX_B8C (0x0000) // 0.000 * 2^LUX_SCALE
#define TSL2561_LUX_M8C (0x0000) // 0.000 * 2^LUX_SCALE
 
enum {
TSL2561_REGISTER_CONTROL = 0x00,
TSL2561_REGISTER_TIMING = 0x01,
TSL2561_REGISTER_THRESHHOLDL_LOW = 0x02,
TSL2561_REGISTER_THRESHHOLDL_HIGH = 0x03,
TSL2561_REGISTER_THRESHHOLDH_LOW = 0x04,
TSL2561_REGISTER_THRESHHOLDH_HIGH = 0x05,
TSL2561_REGISTER_INTERRUPT = 0x06,
TSL2561_REGISTER_CRC = 0x08,
TSL2561_REGISTER_ID = 0x0A,
TSL2561_REGISTER_CHAN0_LOW = 0x0C,
TSL2561_REGISTER_CHAN0_HIGH = 0x0D,
TSL2561_REGISTER_CHAN1_LOW = 0x0E,
TSL2561_REGISTER_CHAN1_HIGH = 0x0F
};
 
typedef enum {
TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms
TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms
TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms
}
tsl2561IntegrationTime_t;
 
typedef enum {
TSL2561_GAIN_0X = 0x00, // No gain
TSL2561_GAIN_16X = 0x10 // 16x gain
}
tsl2561Gain_t;
 
typedef struct __TSL25611_DATA {
unsigned char address;
tsl2561IntegrationTime_t integration;
tsl2561Gain_t gain;
} TSL2561_DATA;
 
void LUX_Init(unsigned char address);
void LUX_Begin(void);
void LUX_Enable(void);
void LUX_Disable(void);
void LUX_Set_Timing(tsl2561IntegrationTime_t integration);
void LUX_Set_Gain(tsl2561Gain_t gain);
unsigned long LUX_Calculate_Lux(unsigned int ch0, unsigned int ch1);
unsigned long LUX_Get_Full_Luminosity(void);
unsigned int LUX_Get_Luminosity(unsigned char channel);
 
void LUX_Write_2_Bytes(unsigned char reg, unsigned char value);
unsigned int LUX_Read_2_Bytes(unsigned char reg);
 
#endif /* LUX_TSL2561_H */
 
/PIC Projects/PIC_27J13/main.c
0,0 → 1,1216
#include "defines.h"
#include "interrupts.h"
#include "uart.h"
#include "i2c.h"
#include "spi.h"
#include "nfc_PN532.h"
#include "led_HT16K33.h"
#include "oled_ssd1306.h"
#include "oled_ssd1331.h"
#include "adc.h"
#include "xbee.h"
#include "timers.h"
#include "lux_TSL2561.h"
#include "oled_NHD-0216KZW-AB5.h"
#include "temp_BMP085.h"
#include <delays.h>
#include <string.h>
 
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
/* --------------------------- Configuration Bits --------------------------- */
/* CONFIG1L @ 0x1FFF8 */
#pragma config CFGPLLEN = ON // Enable PLL on startup
#pragma config PLLDIV = 3 // Set PPL prescaler to 3 (to get 4MHz)
#pragma config WDTEN = OFF // Turn off watchdog timer
#pragma config STVREN = OFF // Stack overflow/underflow reset disabled
#pragma config XINST = OFF // Turn off extended instruction set
 
/* CONFIG1H @ 0x1FFF9 */
#pragma config CP0 = OFF // Program memory is not code-protected
 
/* CONFIG2L @ 0x1FFFA */
#pragma config CLKOEC = OFF // CLKO output disabled on RA6 pin
#pragma config SOSCSEL = LOW // Low Power T1OSC/SOSC circuit selected
#pragma config IESO = ON // Internal external oscillator switch over disabled
#pragma config OSC = HSPLL // Use external oscillator (101)
#pragma config FCMEN = OFF // Fail-safe clock monitor disabled
 
/* CONFIG2H @ 0x1FFFB */
#pragma config WDTPS = 1 // Watchdog postscaler of 1:1
 
/* CONFIG3L @ 0x1FFFC */
#pragma config RTCOSC = T1OSCREF // RTCC uses T1OSC/T1CKI
#pragma config DSBOREN = ON // Deep sleep BOR enabled
#pragma config DSWDTPS = M2 // Deep sleep watchdog postscaler of 1:2 (36m)
#pragma config DSWDTEN = OFF // Deep sleep watchdog timer disabled
#pragma config DSWDTOSC = INTOSCREF // DSWDT clock select uses INTRC
 
/* CONFIG3H @ 0x1FFFD */
#pragma config PLLSEL = PLL96 // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
#pragma config ADCSEL = BIT12 // 12-bit ADC
#pragma config MSSP7B_EN = MSK7 // 7-bit address masking mode
#pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed
 
/* CONFIG4L @ 0x1FFFE */
#pragma config WPCFG = ON // Configuration words page protected
 
/* CONFIG4H @ 0x1FFFF */
#pragma config WPEND = PAGE_WPFP // Pages WPFP<6:0> through Configuration Words erase/write protected
#pragma config WPDIS = OFF // WPFP<6:0>/WPEND region ignored
/* -------------------------------------------------------------------------- */
// </editor-fold>
 
#if defined(_TEST_UART)
void main(void) {
unsigned char length = 0;
unsigned char buffer[100];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
length = UART1_Read_Buffer((unsigned char *) buffer);
if (length != 0) {
UART1_WriteB((char *) buffer, length);
}
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_I2C_MASTER)
void main(void) {
unsigned char i = 0;
unsigned char length = 0;
unsigned char result = 0;
unsigned char buffer[100];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
 
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
buffer[0] = 0x8;
 
I2C_Master_Send(0x24, 1, buffer);
do {
result = I2C_Get_Status();
} while (!result);
DBG_PRINT_MAIN("S:%X ", result);
 
I2C_Master_Recv(0x24, 2);
do {
result = I2C_Get_Status();
} while (!result);
DBG_PRINT_MAIN("S:%X ", result);
length = I2C_Read_Buffer(buffer);
DBG_PRINT_MAIN("L:%d D:", length);
for (i = 0; i < length; i++) {
DBG_PRINT_MAIN("%c ", buffer[i]);
}
 
// I2C_Master_Restart(0x30, 0xBB, 2);
// result = I2C_Get_Status();
// while (!result) {
// result = I2C_Get_Status();
// }
// DBG_PRINT_MAIN("S:%X ", result);
// length = I2C_Read_Buffer(buffer);
// DBG_PRINT_MAIN("L:%d D:", length);
// for (i = 0; i < length; i++) {
// DBG_PRINT_MAIN("%c ", buffer[i]);
// }
 
DBG_PRINT_MAIN("\r\n");
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_I2C_SLAVE)
void main(void) {
unsigned char i = 0;
unsigned char length = 0;
unsigned char result = 0;
unsigned char buffer[100];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
 
I2C_Configure_Slave(0x24);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
DBG_PRINT_MAIN("%X ", result);
length = I2C_Read_Buffer(buffer);
DBG_PRINT_MAIN("%d ", length);
for (i = 0; i < length; i++) {
DBG_PRINT_MAIN("%X ", buffer[i]);
}
DBG_PRINT_MAIN("\r\n");
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_NFC)
void main(void) {
unsigned char i, length = 0;
 
// NFC stuff
NFC_FIRMWARE_VERSION version;
NFC_TargetDataMiFare cardData[2];
NFC_TargetDataMiFare cardData_prev[2];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
NFC_Init(); // Initialize the NFC chip (uses I2C)
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
version = NFC_Get_Firmware_Version();
while (!version.IC) {
DBG_PRINT_MAIN("Waiting for NFC board..\r\n");
Delay10KTCYx(3);
version = NFC_Get_Firmware_Version();
}
DBG_PRINT_MAIN("Found chip PN5%X\r\n", version.IC);
DBG_PRINT_MAIN("Firmware ver. %d.%d\r\n", version.Ver, version.Rev);
NFC_SAMConfig();
 
memset(cardData, 0, 24);
 
while (1) {
 
// // This query will hang until the NFC chip replies (card detected)
// length = NFC_readPassiveTargetID(cardData);
// if (length) {
// DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[0].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// if (length == 2) {
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[1].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// }
// }
 
// // This query will hang until the NFC chip replies (card detected)
// length = NFC_readPassiveTargetID(cardData);
// if (length) {
// DBG_PRINT_MAIN("Cards Found: %u\r\n", length);
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[0].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[0].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// if (length == 2) {
// DBG_PRINT_MAIN("UID Length: %d bytes\r\n", cardData[1].NFCID_LEN);
// DBG_PRINT_MAIN("UID: ");
// for (i = 0; i < cardData[1].NFCID_LEN; i++) {
// DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
// }
// DBG_PRINT_MAIN("\r\n");
// }
// }
 
// This query will not wait for a detection before responding
length = NFC_Poll_Targets(1, 1, cardData);
if (!length) {
memset(cardData_prev, 0, 24);
} else if (length == 1) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
DBG_PRINT_MAIN("UID: ");
for (i = 0; i < cardData[0].NFCID_LEN; i++) {
DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
}
DBG_PRINT_MAIN("\r\n");
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
}
memset(&cardData_prev[1], 0, 12);
} else if (length == 2) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// First card matched
DBG_PRINT_MAIN("UID2: ");
for (i = 0; i < cardData[1].NFCID_LEN; i++) {
DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
}
DBG_PRINT_MAIN("\r\n");
memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Second card matched
DBG_PRINT_MAIN("UID1: ");
for (i = 0; i < cardData[0].NFCID_LEN; i++) {
DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
}
DBG_PRINT_MAIN("\r\n");
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
// No match
DBG_PRINT_MAIN("UID1: ");
for (i = 0; i < cardData[0].NFCID_LEN; i++) {
DBG_PRINT_MAIN("%02X ", cardData[0].NFCID[i]);
}
DBG_PRINT_MAIN("\r\n");
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
DBG_PRINT_MAIN("UID2: ");
for (i = 0; i < cardData[1].NFCID_LEN; i++) {
DBG_PRINT_MAIN("%02X ", cardData[1].NFCID[i]);
}
DBG_PRINT_MAIN("\r\n");
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
}
}
}
}
 
#elif defined(_TEST_LED_BACKPACK)
void main(void) {
unsigned char i = 0;
unsigned int counter = 0;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
LED_Init(); // Initialize the LED backpack (uses I2C);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
LED_Start();
LED_Write_Digit_Num(0, 1, 1);
LED_Write_Digit_Num(1, 2, 0);
LED_Write_Digit_Num(2, 3, 0);
LED_Write_Digit_Num(3, 4, 0);
LED_Write_Display();
for (i = 0; i < 15; i++) {
LED_Set_Brightness(15 - i);
Delay10KTCYx(100);
}
for (i = 0; i < 15; i++) {
LED_Set_Brightness(i);
Delay10KTCYx(100);
}
LED_Blink_Rate(HT16K33_BLINK_OFF);
 
while (1) {
LED_Write_Num(counter);
counter++;
if (counter > 9999)
counter = 0;
 
// Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_SPI)
void main(void) {
unsigned char i = 0;
unsigned char length = 0;
unsigned char result = 0;
unsigned char buffer[100];
unsigned char test[8] = "ASDF123";
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
SPI2_Write(test, 7);
while (result != 7) {
length = SPI2_Buffer_Read(buffer);
if (length) {
result += length;
}
}
result = 0;
 
for (i = 0; i < result; i++) {
DBG_PRINT_MAIN("%X ", buffer[i]);
}
DBG_PRINT_MAIN("\r\n");
 
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_SSD1306_OLED)
void main(void) {
unsigned int i = 0;
unsigned long l = 0;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_4); // Initialize the SPI module
SSD1306_Init(); // Initialize the OLED code
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
 
SSD1306_Display(); // Show splashscreen
 
while (1) {
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawLine();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawCircle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Fill_Circle(SSD1306_LCDWIDTH / 2, SSD1306_LCDHEIGHT / 2, 10, SSD1306_WHITE);
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawRoundRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillRoundRect();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawTriangle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_FillTriangle();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Test_DrawChar();
SSD1306_Display();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1306_Clear_Display();
SSD1306_Set_Text_Size(1);
SSD1306_Set_Text_Color(SSD1306_WHITE);
SSD1306_Set_Cursor(0, 0);
SSD1306_Write_String("Hello World!\n");
// SSD1306_Set_Text_Color_BG(BLACK, WHITE);
i = 65535;
SSD1306_Write_String("%u %d\n", i, i);
// SSD1306_Set_Text_Size(2);
// SSD1306_Set_Text_Color(WHITE);
l = 0xDEADBEEF;
SSD1306_Write_String("0x%lX", (long) l);
SSD1306_Display();
 
// SSD1306_Clear_Display();
// SSD1306_Set_Rotation(0);
// SSD1306_Set_Text_Size(1);
// SSD1306_Set_Text_Color(SSD1306_WHITE);
// SSD1306_Set_Cursor(0, 0);
// SSD1306_Write_String("%u", i);
// i++;
// SSD1306_Display();
 
}
}
 
#elif defined(_TEST_SSD1331_OLED)
void main(void) {
unsigned int i = 0;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_64); // Initialize the SPI module
SSD1331_Init(); // Initialize the OLED code
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
SSD1331_Begin();
while (1) {
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Set_Rotation(0);
SSD1331_Test_Pattern();
 
Delay10KTCYx(255);
Delay10KTCYx(255);
SSD1331_Clear_Display();
SSD1331_Set_Rotation(0);
SSD1331_Set_Cursor(0, 0);
SSD1331_Write_String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabit adipiscing ante sed nibh tincidunt feugiat.");
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Clear_Display();
// SSD1331_Set_Rotation(3);
// SSD1331_Set_Cursor(0, 0);
// SSD1331_Write_String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_DrawLines(SSD1331_YELLOW);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_DrawLines(SSD1331_BLUE);
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_DrawRect(SSD1331_GREEN);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(1);
// SSD1331_Test_DrawRect(SSD1331_RED);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(2);
// SSD1331_Test_DrawRect(SSD1331_BLUE);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_DrawRect(SSD1331_YELLOW);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN);
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Clear_Display();
// SSD1331_Test_FillCircle(10, SSD1331_BLUE);
// SSD1331_Test_DrawCircle(10, SSD1331_WHITE);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Clear_Display();
// SSD1331_Test_FillCircle(10, SSD1331_MAGENTA);
// SSD1331_Test_DrawCircle(10, SSD1331_YELLOW);
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_DrawTria();
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_DrawTria();
 
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_DrawRoundRect();
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_DrawRoundRect();
 
// SSD1331_Clear_Display();
// SSD1331_Set_Rotation(3);
// SSD1331_Set_Cursor(0,0);
// SSD1331_Set_Text_Color_BG(SSD1331_WHITE, SSD1331_BLACK);
// SSD1331_Write_String("%u", i);
// i++;
}
}
 
#elif defined(_TEST_ADC)
void main(void) {
unsigned int x, y, z;
unsigned char buffer[60];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
SSD1306_Init(); // Initialize the SSD1331 OLED display (uses SPI2)
ADC_Init(ADC_TAD_20, ADC_FOSC_64);
 
// I2C_Configure_Master(I2C_400KHZ);
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
memset(buffer, 0, 60);
SSD1306_Clear_Display();
SSD1306_Display();
 
while (1) {
// ADC read from AN0-AN2 and prints to display
ADC_Start(ADC_CHANNEL_AN2);
// SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 0);
while (!ADC_Get_Result(&x));
SSD1306_Write_String("X: %u", x);
SSD1306_Display();
 
ADC_Start(ADC_CHANNEL_AN1);
// SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 8);
while (!ADC_Get_Result(&y));
SSD1306_Write_String("Y: %u", y);
SSD1306_Display();
 
ADC_Start(ADC_CHANNEL_AN0);
// SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK);
SSD1306_Set_Cursor(0, 16);
while (!ADC_Get_Result(&z));
SSD1306_Write_String("Z: %u", z);
SSD1306_Display();
}
}
 
#elif defined(_TEST_XBEE)
void main(void) {
unsigned int i, length = 0;
unsigned char buffer[100];
 
XBEE_RX_AT_COMMAND_RESPONSE_FRAME *rx_at_cmd_response_frame;
XBEE_RX_DATA_PACKET_FRAME *rx_data_frame;
XBEE_RX_DATA_TX_STATUS_FRAME *rx_tx_status_frame;
XBEE_RX_REMOTE_AT_COMMAND_FRAME *rx_remote_at_cmd_frame;
XBEE_RX_NODE_IDENTIFICATION_INDICATOR_FRAME *rx_node_ident_frame;
XBEE_RX_MODEM_STATUS_FRAME *rx_modem_status_frame;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
XBee_Init();
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
//#define _ROUTER
#define _COORDINATOR
 
#ifdef _ROUTER
XBEE_TX_DATA_PACKET_FRAME *tx_data_frame;
tx_data_frame = (void *) buffer;
tx_data_frame->frame_type = XBEE_TX_DATA_PACKET;
tx_data_frame->frame_id = 1;
tx_data_frame->destination_64.UPPER_32.long_value = 0x00000000;
tx_data_frame->destination_64.LOWER_32.long_value = 0x00000000;
tx_data_frame->destination_16.INT_16.int_value = 0xFEFF;
tx_data_frame->broadcast_radius = 0;
tx_data_frame->options = 0;
tx_data_frame->data[0] = 0x54;
tx_data_frame->data[1] = 0x78;
tx_data_frame->data[2] = 0x32;
tx_data_frame->data[3] = 0x43;
tx_data_frame->data[4] = 0x6F;
tx_data_frame->data[5] = 0x6F;
tx_data_frame->data[6] = 0x72;
tx_data_frame->data[7] = 0x11;
XBee_Process_Transmit_Frame(buffer, XBEE_TX_DATA_PACKET_FRAME_SIZE + 8);
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
#endif
 
#ifdef _COORDINATOR
length = XBee_Get_Received_Frame(buffer);
if (length != 0) {
switch (*(unsigned char *) buffer) {
case XBEE_RX_AT_COMMAND_RESPONSE:
DBG_PRINT_MAIN("XBEE: parsing recieved AT command response frame\r\n");
rx_at_cmd_response_frame = (void *) buffer;
DBG_PRINT_MAIN("Frame ID: %u\r\n", rx_at_cmd_response_frame->frame_id);
DBG_PRINT_MAIN("AT Command: %c%c Status: %02X\r\n", rx_at_cmd_response_frame->command[0], \\
rx_at_cmd_response_frame->command[1], rx_at_cmd_response_frame->command_status);
if (length > XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE) {
DBG_PRINT_MAIN("Command Data: ");
for (i = 0; i < length - XBEE_RX_AT_COMMAND_RESPONSE_FRAME_SIZE; i++) {
DBG_PRINT_MAIN("%02X ", rx_at_cmd_response_frame->data[i]);
}
DBG_PRINT_MAIN("\r\n");
}
break;
case XBEE_RX_DATA_PACKET:
DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n");
rx_data_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_data_frame->source_64));
XBee_Convert_Endian_16(&(rx_data_frame->source_16));
DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
rx_data_frame->source_64.UPPER_32.long_value, \\
rx_data_frame->source_64.LOWER_32.long_value, \\
rx_data_frame->source_16.INT_16.int_value, \\
rx_data_frame->recieve_options);
DBG_PRINT_MAIN("Data: ");
for (i = 0; i < length - XBEE_RX_DATA_PACKET_FRAME_SIZE; i++) {
DBG_PRINT_MAIN("%02X ", rx_data_frame->data[i]);
}
DBG_PRINT_MAIN("\r\n");
break;
case XBEE_RX_DATA_TX_STATUS:
DBG_PRINT_MAIN("XBEE: parsing recieved TX status frame\r\n");
rx_tx_status_frame = (void *) buffer;
XBee_Convert_Endian_16(&(rx_tx_status_frame->destination_16));
DBG_PRINT_MAIN("Frame ID: %u Destination 16: %04X\r\n", \\
rx_tx_status_frame->frame_id, rx_tx_status_frame->destination_16.INT_16.int_value);
DBG_PRINT_MAIN("Transmit Retry Count: %02X Delivery Status: %02X Discovery Status: %02X\r\n", \\
rx_tx_status_frame->transmit_retry_count, rx_tx_status_frame->delivery_status, \\
rx_tx_status_frame->discovery_status);
break;
case XBEE_RX_IO_DATA_SAMPLE:
DBG_PRINT_MAIN("XBEE: parsing recieved IO data sample frame\r\n");
break;
case XBEE_RX_EXPLICIT_COMMAND:
DBG_PRINT_MAIN("XBEE: parsing recieved explicit command frame\r\n");
break;
case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
DBG_PRINT_MAIN("XBEE: parsing recieved remote AT command frame\r\n");
rx_remote_at_cmd_frame = (void *) buffer;
break;
case XBEE_RX_ROUTE_RECORD:
DBG_PRINT_MAIN("XBEE: parsing recieved route record frame\r\n");
break;
case XBEE_RX_NODE_IDENTIFICATION:
DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n");
rx_node_ident_frame = (void *) buffer;
XBee_Convert_Endian_64(&(rx_node_ident_frame->source_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->source_16));
XBee_Convert_Endian_64(&(rx_node_ident_frame->remote_64));
XBee_Convert_Endian_16(&(rx_node_ident_frame->remote_16));
XBee_Convert_Endian_16(&(rx_node_ident_frame->parent_16));
DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %02X\r\n", \\
rx_node_ident_frame->source_64.UPPER_32.long_value, \\
rx_node_ident_frame->source_64.LOWER_32.long_value, \\
rx_node_ident_frame->source_16.INT_16.int_value, \\
rx_node_ident_frame->recieve_options);
DBG_PRINT_MAIN("Remote 64: %08lX %08lX Remote 16: %04X Parent 16: %04X\r\n", \\
rx_node_ident_frame->remote_64.UPPER_32.long_value, \\
rx_node_ident_frame->remote_64.LOWER_32.long_value, \\
rx_node_ident_frame->remote_16.INT_16.int_value, \\
rx_node_ident_frame->parent_16.INT_16.int_value);
DBG_PRINT_MAIN("Device Type: %02X Source Event: %02X\r\n", \\
rx_node_ident_frame->device_type, rx_node_ident_frame->source_event);
break;
case XBEE_RX_FRAME_MODEM_STATUS:
DBG_PRINT_MAIN("XBEE: parsing recieved modem status frame\r\n");
rx_modem_status_frame = (void *) buffer;
DBG_PRINT_MAIN("Status: %02X\r\n", rx_modem_status_frame->status);
break;
default:
DBG_PRINT_MAIN("??\r\n");
break;
}
}
#endif
 
}
}
 
#elif defined(_TEST_NFC_TO_SSD1306_OLED)
void main(void) {
unsigned char length = 0;
 
// NFC stuff
NFC_FIRMWARE_VERSION version;
NFC_TargetDataMiFare cardData[2];
NFC_TargetDataMiFare cardData_prev[2];
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART1_Init();
I2C_Init();
NFC_Init();
SPI2_Init(SPI2_FOSC_4);
SSD1306_Init();
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
SSD1306_Begin(SSD1306_SWITCHCAPVCC);
memset(cardData, 0, 24);
memset(cardData_prev, 0, 24);
SSD1306_Clear_Display();
SSD1306_Set_Rotation(0);
SSD1306_Set_Cursor(0, 0);
 
version = NFC_Get_Firmware_Version();
while (!version.IC) {
SSD1306_Write_String("Waiting for NFC board..\r");
SSD1306_Display();
Delay10KTCYx(3);
version = NFC_Get_Firmware_Version();
}
SSD1306_Write_String("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev);
SSD1306_Display();
NFC_SAMConfig();
 
while (1) {
 
// This query will not wait for a detection before responding
length = NFC_Poll_Targets(1, 1, cardData);
if (!length) {
memset(cardData_prev, 0, 24);
} else if (length == 1) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
}
memset(&cardData_prev[1], 0, 12);
} else if (length == 2) {
if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Do nothing
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[1].NFCID, cardData[0].NFCID_LEN) == 0 &&
memcmp(&cardData[1].NFCID, &cardData_prev[0].NFCID, cardData[1].NFCID_LEN) == 0) {
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[0].NFCID, &cardData_prev[0].NFCID, cardData[0].NFCID_LEN) == 0) {
// First card matched
SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Display();
memcpy(&cardData_prev[1], (const char *) &cardData[1], 12);
} else if (memcmp(&cardData[1].NFCID, &cardData_prev[1].NFCID, cardData[1].NFCID_LEN) == 0) {
// Second card matched
SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
} else {
// No match
SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[0].NFCID[0], cardData[0].NFCID[1], cardData[0].NFCID[2], cardData[0].NFCID[3]);
SSD1306_Display();
memcpy((char *) &cardData_prev[0], (const char *) &cardData[0], 12);
SSD1306_Write_String("UID: %02X %02X %02X %02X\n", cardData[1].NFCID[0], cardData[1].NFCID[1], cardData[1].NFCID[2], cardData[1].NFCID[3]);
SSD1306_Display();
memcpy((char *) &cardData_prev[1], (const char *) &cardData[1], 12);
}
}
}
}
 
#elif defined(_TEST_TIMER1_RTC)
void main(void) {
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
Timer1_Init();
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
LED_BLUE_TRIS = 0;
LED_RED_TRIS = 0;
Timer1_Enable();
 
while (1) {
 
}
}
 
#elif defined(_TEST_LUX)
void main(void) {
unsigned int ir, full;
unsigned long lum;
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART1_Init();
I2C_Init();
LUX_Init(TSL2561_ADDR_FLOAT);
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
LUX_Begin();
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
LUX_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
// LUX_SetGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
LUX_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
while (1) {
lum = LUX_Get_Full_Luminosity();
ir = lum >> 16;
full = lum & 0xFFFF;
DBG_PRINT_LUX("IR: %d\r\n", ir);
DBG_PRINT_LUX("Visible: %d\r\n", full - ir);
DBG_PRINT_LUX("Full: %d\r\n", full);
DBG_PRINT_LUX("Lux: %ld\r\n\r\n", LUX_Calculate_Lux(full, ir));
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#elif defined(_TEST_OLED_CHAR)
void main(void) {
int i;
unsigned char *buffer = "Test String";
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xFF;
ANCON1 = 0x1F;
 
// UART1_Init();
NHD_Init();
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
NHD_Begin(16, 2);
NHD_Write_String("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do");
NHD_Set_Cursor(0,1);
NHD_Write_String("eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e");
 
while (1) {
Delay10KTCYx(150);
NHD_Scroll_Display_Left();
}
}
 
#elif defined(_TEST_BMP)
void main(void) {
 
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
UART1_Init();
I2C_Init();
BMP_Init();
I2C_Configure_Master(I2C_100KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
BMP_Begin(BMP085_ULTRAHIGHRES);
 
while (1) {
DBG_PRINT_MAIN("Temp: ");
DBG_PRINT_MAIN_F(BMP_Read_Temperature(), 1);
DBG_PRINT_MAIN(" *C\r\n");
DBG_PRINT_MAIN("Pressure: %ld Pa\r\n", BMP_Read_Pressure());
DBG_PRINT_MAIN("Altitude: ");
DBG_PRINT_MAIN_F(BMP_Read_Altitude(101592), 1);
DBG_PRINT_MAIN(" meters\r\n");
 
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
}
}
 
#else
void main(void) {
unsigned int ir, full;
unsigned long lum;
/* --------------------- Oscillator Configuration --------------------- */
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
/* -------------------------------------------------------------------- */
 
// Set all ports as digial I/O except for AN0-AN2 (pins 2-4)
ANCON0 = 0xF8;
ANCON1 = 0x1F;
 
// UART1_Init();
I2C_Init();
NHD_Init();
LUX_Init(TSL2561_ADDR_FLOAT);
 
I2C_Configure_Master(I2C_400KHZ);
 
Interrupt_Enable(); // Enable high-priority interrupts and low-priority interrupts
Interrupt_Init(); // Initialize the interrupt priorities
 
NHD_Begin(16, 2);
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
// LUX_SetGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
LUX_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
 
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
LUX_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
// LUX_SetTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
 
while (1) {
lum = LUX_Get_Full_Luminosity();
ir = lum >> 16;
full = lum & 0xFFFF;
NHD_Set_Cursor(0, 0);
NHD_Write_String("I: %d ", ir);
NHD_Write_String("V: %d ", full - ir);
NHD_Set_Cursor(0, 1);
NHD_Write_String("Lux: %ld ", LUX_Calculate_Lux(full, ir));
 
Delay10KTCYx(100);
}
}
#endif
/PIC Projects/PIC_27J13/nfc_PN532.c
0,0 → 1,481
#include "defines.h"
#include "nfc_PN532.h"
#include "i2c.h"
#include <string.h>
#include <delays.h>
 
static NFC_DATA nfc_data;
static NFC_DATA *nfc_data_p = &nfc_data;
 
// Const value arrays for comparison use
static char pn532response_firmwarevers[] = {0x01, 0x00, 0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03};
static char pn532ack[] = {0x01, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00};
 
void NFC_Init() {
NFC_IRQ_TRIS = 1; // IRQ Pin is RC5
 
/* NFC reset is disabled due to lack of pins */
// NFC_RESET_TRIS = 0; // Reset Pin is RC2
//
// // Reset the PN532
// NFC_RESET_LAT = 1;
// NFC_RESET_LAT = 0;
// Delay10TCYx(1);
// NFC_RESET_LAT = 1;
}
 
// Configures the SAM (Secure Access Module)
unsigned char NFC_SAMConfig() {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_SAMCONFIGURATION;
nfc_data_p->packetbuffer[1] = 0x01; // Normal mode
nfc_data_p->packetbuffer[2] = 0x14; // Timeout 50ms * 20 = 1s
nfc_data_p->packetbuffer[3] = 0x01; // Use IRQ pin
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
return 0;
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 8);
 
return (nfc_data_p->packetbuffer[7] == 0x15);
}
 
// Checks the firmware version of the PN5xx chip
NFC_FIRMWARE_VERSION NFC_Get_Firmware_Version(void) {
NFC_FIRMWARE_VERSION response = {0, 0, 0, 0};
 
// Create and send command
nfc_data_p->packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 1))
return response;
 
// Read back data from the PN532
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
 
// Compare and check returned values
if (strncmp((char *) nfc_data_p->packetbuffer, (char *) pn532response_firmwarevers, 8) != 0)
return response;
 
// Save and return info
response.IC = nfc_data_p->packetbuffer[8];
response.Ver = nfc_data_p->packetbuffer[9];
response.Rev = nfc_data_p->packetbuffer[10];
response.Support = nfc_data_p->packetbuffer[11];
 
return response;
}
 
// Sends a command and waits a specified period for the ACK
unsigned char NFC_Send_Command_Check_Ack(unsigned char *cmd, unsigned char cmdlen) {
unsigned int timer = 0;
 
// Write the command
NFC_I2C_Write_Cmd(cmd, cmdlen);
 
// Wait for chip to be ready
while (NFC_I2C_Read_Status() != PN532_I2C_READY) {
if (PN532_TIMEOUT != 0) {
timer += 1;
if (timer > PN532_TIMEOUT)
return 0;
}
Delay10TCYx(1);
}
 
// Check ACK
if (!NFC_I2C_Read_ACK()) {
return 0;
}
 
return 1;
}
 
// Passive polling, waits for an ISO14443A target to enter the field
unsigned char NFC_Read_Passive_Target_ID(NFC_TargetDataMiFare *cardData) {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
nfc_data_p->packetbuffer[1] = 2; // Max 2 cards at once
nfc_data_p->packetbuffer[2] = PN532_MIFARE_ISO14443A; // Mifare only
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 3))
return 0;
 
// Wait for IRQ line
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 35);
 
/* InListPassiveTarget response should be in the following format:
* Byte Description
* ---------- ------------------
* b0 Data ACK
* b1..7 Frame header and preamble
* b8 Tags found
* b9..N NFC_TargetDataMiFare[2]
* bN+1..N+2 Checksum + postamble
*/
 
// Check # of tags found
if (!nfc_data_p->packetbuffer[8])
return 0;
// Save data from first card
if (nfc_data_p->packetbuffer[13] == 4) {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[9], 9);
} else {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[9], 12);
}
 
// Save data from second card
if (nfc_data_p->packetbuffer[8] == 2) {
// Offset will vary depending on length of first card
if (nfc_data_p->packetbuffer[13] == 4) {
if (nfc_data_p->packetbuffer[22] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[18], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[18], 12);
}
} else { // Length of first UID is 7
if (nfc_data_p->packetbuffer[25] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[21], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[21], 12);
}
}
}
// Return the number of cards detected
return nfc_data_p->packetbuffer[8];
}
 
// Active polling, returns number of cards in the field
unsigned char NFC_Poll_Targets(unsigned char number, unsigned char period, NFC_TargetDataMiFare *cardData) {
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INAUTOPOLL;
nfc_data_p->packetbuffer[1] = number; // Number of polling
nfc_data_p->packetbuffer[2] = period; // Polling period in units of 150ms
nfc_data_p->packetbuffer[3] = 0x10; // Check for Mifare cards only
 
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
return 0;
 
// Wait for IRQ line
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 37);
 
/* InAutoPoll response should be in the following format:
* Byte Description
* ---------- ------------------
* b0 Data ACK
* b1..7 Frame header and preamble
* b6 Tags found
* b7 Polled target type (should be 0x10 Mifare)
* b8 TargetData length (1/2)
* b9..N NFC_TargetDataMiFare[1/2]
* bN+1..N+2 Checksum + postamble
*/
 
// Check # of tags found
if (!nfc_data_p->packetbuffer[8])
return 0;
 
// Save data from first card
if (nfc_data_p->packetbuffer[15] == 4) {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[11], 9);
} else {
memcpy((char *)&cardData[0], (const char *)&nfc_data_p->packetbuffer[11], 12);
}
 
// Save data from second card
if (nfc_data_p->packetbuffer[8] == 2) {
// Offset will vary depending on length of first card
if (nfc_data_p->packetbuffer[15] == 4) {
if (nfc_data_p->packetbuffer[26] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[22], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[22], 12);
}
} else {
if (nfc_data_p->packetbuffer[29] == 4) {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[25], 9);
} else {
memcpy((char *)&cardData[1], (const char *)&nfc_data_p->packetbuffer[25], 12);
}
}
}
 
// Return the number of cards detected
return nfc_data_p->packetbuffer[8];
}
 
// Indicates whether the specified block number is the first block
// in the sector (block 0 relative to the current sector)
unsigned char NFC_mifareclassic_IsFirstBlock(unsigned long uiBlock) {
// Test if we are in the small or big sectors
if (uiBlock < 128)
return ((uiBlock) % 4 == 0);
else
return ((uiBlock) % 16 == 0);
}
 
// Indicates whether the specified block number is the sector trailer
unsigned char NFC_mifareclassic_IsTrailerBlock(unsigned long uiBlock) {
// Test if we are in the small or big sectors
if (uiBlock < 128)
return ((uiBlock + 1) % 4 == 0);
else
return ((uiBlock + 1) % 16 == 0);
}
 
// Tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command
unsigned char NFC_mifareclassic_AuthenticateBlock(unsigned char *uid, unsigned char uidLen, unsigned long blockNumber, unsigned char keyNumber, unsigned char *keyData) {
// See section 7.3.8 of the PN532 User Manual
// blockNumber = The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards)\
// keyNumber = Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
// keyData = Pointer to a byte array containing the 6 byte key value
 
unsigned char i;
 
// Assemble frame data
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; /* Data Exchange Header */
nfc_data_p->packetbuffer[1] = 1; /* Max card numbers */
nfc_data_p->packetbuffer[2] = (keyNumber) ? MIFARE_CMD_AUTH_A : MIFARE_CMD_AUTH_B;
nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (1K = 0..63, 4K = 0..255 */
for (i = 0; i < 6; i++) {
nfc_data_p->packetbuffer[4 + i] = keyData[i];
}
for (i = 0; i < uidLen; i++) {
nfc_data_p->packetbuffer[10 + i] = uid[i];
}
 
// Send frame and check for ACK
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 10 + uidLen))
return 0;
 
// Read response from PN532
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 12);
 
return 1;
}
 
// Tries to read an entire 16-byte data block at the specified block address
unsigned char NFC_mifareclassic_ReadDataBlock(unsigned char blockNumber, unsigned char *data) {
unsigned char i;
 
// Assemble frame data
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
nfc_data_p->packetbuffer[1] = 1; /* Card number */
nfc_data_p->packetbuffer[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */
nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
 
// Send frame and check for ACK
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 4))
return 0;
 
// Read reponse
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
 
// If byte 9 isnt 0x00 we probably have and error
if (nfc_data_p->packetbuffer[8] != 0x00) {
return 0;
}
 
// Copy the 16 data bytes into the data buffer
// Block contents starts at byte 10 of a valid response
for (i = 0; i < 16; i++) {
data[i] = nfc_data_p->packetbuffer[9 + i];
}
 
return 1;
}
 
// Tries to write an entire 16-byte data block at the specified block address
unsigned char NFC_mifareclassic_WriteDataBlock(unsigned char blockNumber, unsigned char *data) {
unsigned char i;
 
// Assemble frame data
nfc_data_p->packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
nfc_data_p->packetbuffer[1] = 1; /* Card number */
nfc_data_p->packetbuffer[2] = MIFARE_CMD_WRITE; /* Mifare Write command = 0xA0 */
nfc_data_p->packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
for (i = 0; i < 16; i++) { /* Data Payload */
nfc_data_p->packetbuffer[4 + i] = data[i];
}
 
// Send frame and check for ACK
if (!NFC_Send_Command_Check_Ack(nfc_data_p->packetbuffer, 20))
return 0;
 
// Read response
NFC_I2C_Read_Data(nfc_data_p->packetbuffer, 26);
 
return 1;
}
 
// Formats a Mifare Classic card to store NDEF Records
unsigned char NFC_mifareclassic_FormatNDEF(void) {
unsigned char sectorbuffer1[16] = {0x14, 0x01, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
unsigned char sectorbuffer2[16] = {0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
unsigned char sectorbuffer3[16] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0x78, 0x77, 0x88, 0xC1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 
// Write blocks 1 and 2
if (!NFC_mifareclassic_WriteDataBlock(1, sectorbuffer1))
return 0;
if (!NFC_mifareclassic_WriteDataBlock(2, sectorbuffer2))
return 0;
// Write key A and access rights
if (!NFC_mifareclassic_WriteDataBlock(3, sectorbuffer3))
return 0;
 
return 1;
}
 
// Writes an NDEF URI Record to the specified sector (1..15)
/* Note that this function assumes that the Mifare Classic card is
already formatted to work as an "NFC Forum Tag" and uses a MAD1
file system. You can use the NXP TagWriter app on Android to
properly format cards for this. */
unsigned char NFC_mifareclassic_WriteNDEFURI(unsigned char sectorNumber, unsigned char uriIdentifier, const char * url) {
// uriIdentifier = The uri identifier code (0 = none, 0x01 = "http://www.", etc.)
// url = The uri text to write (max 38 characters)
 
// Figure out how long the string is
unsigned char len = strlen(url);
 
unsigned char sectorbuffer1[16] = {0x00, 0x00, 0x03, len + 5, 0xD1, 0x01, len + 1, 0x55, uriIdentifier, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char sectorbuffer2[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char sectorbuffer3[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char sectorbuffer4[16] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7, 0x7F, 0x07, 0x88, 0x40, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 
// Make sure we're within a 1K limit for the sector number
if ((sectorNumber < 1) || (sectorNumber > 15))
return 0;
 
// Make sure the URI payload is between 1 and 38 chars
if ((len < 1) || (len > 38))
return 0;
 
if (len <= 6) {
// Unlikely we'll get a url this short, but why not ...
memcpy(sectorbuffer1 + 9, url, len);
sectorbuffer1[len + 9] = 0xFE;
} else if (len == 7) {
// 0xFE needs to be wrapped around to next block
memcpy(sectorbuffer1 + 9, url, len);
sectorbuffer2[0] = 0xFE;
} else if ((len > 7) || (len <= 22)) {
// Url fits in two blocks
memcpy(sectorbuffer1 + 9, url, 7);
memcpy(sectorbuffer2, url + 7, len - 7);
sectorbuffer2[len - 7] = 0xFE;
} else if (len == 23) {
// 0xFE needs to be wrapped around to final block
memcpy(sectorbuffer1 + 9, url, 7);
memcpy(sectorbuffer2, url + 7, len - 7);
sectorbuffer3[0] = 0xFE;
} else {
// Url fits in three blocks
memcpy(sectorbuffer1 + 9, url, 7);
memcpy(sectorbuffer2, url + 7, 16);
memcpy(sectorbuffer3, url + 23, len - 24);
sectorbuffer3[len - 22] = 0xFE;
}
 
// Now write all three blocks back to the card
if (!(NFC_mifareclassic_WriteDataBlock(sectorNumber * 4, sectorbuffer1)))
return 0;
if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 1, sectorbuffer2)))
return 0;
if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 2, sectorbuffer3)))
return 0;
if (!(NFC_mifareclassic_WriteDataBlock((sectorNumber * 4) + 3, sectorbuffer4)))
return 0;
 
return 1;
}
 
// Reads and checks for the ACK signal
unsigned char NFC_I2C_Read_ACK() {
unsigned char buffer[7];
 
// Check ACK
NFC_I2C_Read_Data(buffer, 6);
 
// Return if the 7 bytes matches the ACK pattern
return (strncmp((char *) buffer, (char *) pn532ack, 7) == 0);
}
 
// Checks the IRQ pin to know if the PN532 is ready
unsigned char NFC_I2C_Read_Status() {
if (NFC_IRQ_PORT == 1) {
return PN532_I2C_BUSY;
} else {
return PN532_I2C_READY;
}
}
 
// Reads n bytes of data from the PN532 via I2C
void NFC_I2C_Read_Data(unsigned char *buffer, unsigned char length) {
unsigned char result;
 
// Wait for IRQ to go low
while (NFC_I2C_Read_Status() != PN532_I2C_READY);
 
// Read bytes from PN532 into buffer
I2C_Master_Recv(PN532_I2C_ADDRESS, length + 2);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
}
I2C_Read_Buffer((char *) buffer);
 
/* Remaining packet byte layout is as follows:
Byte Description
----- ----------------------
* 0 Data ready ACK
* 1 Preamble (0x00)
* 2-3 Start code (0x00,0xFF)
* 4 Length (TFI to N)
* 5 Length Checksum (Length + LCS = 0x00)
* 6 TFI (Frame identifier)
* 0xD4 - Host to PN532
* 0xD5 - PN532 to Host
* 7-N Data (Length - 1 bytes)
* N+1 Data checksum (TFI + Data~N + DCS = 0x00)
* N+2 Postamble (0x00) */
}
 
// Writes a command to the PN532, automatically inserting the preamble and required frame details (checksum, len, etc.)
void NFC_I2C_Write_Cmd(unsigned char* cmd, unsigned char cmdlen) {
int i;
unsigned char checksum;
unsigned char buffer[PN532_PACKBUFFSIZ + 8];
unsigned char buffer_ind = 6;
cmdlen++;
 
checksum = PN532_PREAMBLE + PN532_PREAMBLE + PN532_STARTCODE2 + PN532_HOSTTOPN532;
 
// Fill out required frame fields
buffer[0] = PN532_PREAMBLE;
buffer[1] = PN532_PREAMBLE;
buffer[2] = PN532_STARTCODE2;
buffer[3] = cmdlen;
buffer[4] = ~cmdlen + 1;
buffer[5] = PN532_HOSTTOPN532;
 
 
// Copy cmd to be sent
for (i = 0; i < cmdlen - 1; i++) {
checksum += cmd[i];
buffer[buffer_ind] = cmd[i];
buffer_ind++;
}
 
buffer[buffer_ind] = ~checksum;
buffer_ind++;
buffer[buffer_ind] = PN532_POSTAMBLE;
buffer_ind++;
 
I2C_Master_Send(PN532_I2C_ADDRESS, buffer_ind, buffer);
}
/PIC Projects/PIC_27J13/nfc_PN532.h
0,0 → 1,173
#ifndef NFC_H
#define NFC_H
 
/* PN532 NFC Reader from Adafruit */
 
#define PN532_PREAMBLE (0x00)
#define PN532_STARTCODE1 (0x00)
#define PN532_STARTCODE2 (0xFF)
#define PN532_POSTAMBLE (0x00)
 
#define PN532_HOSTTOPN532 (0xD4)
 
// PN532 Commands
#define PN532_COMMAND_DIAGNOSE (0x00)
#define PN532_COMMAND_GETFIRMWAREVERSION (0x02)
#define PN532_COMMAND_GETGENERALSTATUS (0x04)
#define PN532_COMMAND_READREGISTER (0x06)
#define PN532_COMMAND_WRITEREGISTER (0x08)
#define PN532_COMMAND_READGPIO (0x0C)
#define PN532_COMMAND_WRITEGPIO (0x0E)
#define PN532_COMMAND_SETSERIALBAUDRATE (0x10)
#define PN532_COMMAND_SETPARAMETERS (0x12)
#define PN532_COMMAND_SAMCONFIGURATION (0x14)
#define PN532_COMMAND_POWERDOWN (0x16)
#define PN532_COMMAND_RFCONFIGURATION (0x32)
#define PN532_COMMAND_RFREGULATIONTEST (0x58)
#define PN532_COMMAND_INJUMPFORDEP (0x56)
#define PN532_COMMAND_INJUMPFORPSL (0x46)
#define PN532_COMMAND_INLISTPASSIVETARGET (0x4A)
#define PN532_COMMAND_INATR (0x50)
#define PN532_COMMAND_INPSL (0x4E)
#define PN532_COMMAND_INDATAEXCHANGE (0x40)
#define PN532_COMMAND_INCOMMUNICATETHRU (0x42)
#define PN532_COMMAND_INDESELECT (0x44)
#define PN532_COMMAND_INRELEASE (0x52)
#define PN532_COMMAND_INSELECT (0x54)
#define PN532_COMMAND_INAUTOPOLL (0x60)
#define PN532_COMMAND_TGINITASTARGET (0x8C)
#define PN532_COMMAND_TGSETGENERALBYTES (0x92)
#define PN532_COMMAND_TGGETDATA (0x86)
#define PN532_COMMAND_TGSETDATA (0x8E)
#define PN532_COMMAND_TGSETMETADATA (0x94)
#define PN532_COMMAND_TGGETINITIATORCOMMAND (0x88)
#define PN532_COMMAND_TGRESPONSETOINITIATOR (0x90)
#define PN532_COMMAND_TGGETTARGETSTATUS (0x8A)
 
#define PN532_WAKEUP (0x55)
 
#define PN532_SPI_STATREAD (0x02)
#define PN532_SPI_DATAWRITE (0x01)
#define PN532_SPI_DATAREAD (0x03)
#define PN532_SPI_READY (0x01)
 
#define PN532_I2C_ADDRESS (0x48 >> 1)
#define PN532_I2C_READBIT (0x01)
#define PN532_I2C_BUSY (0x00)
#define PN532_I2C_READY (0x01)
#define PN532_I2C_READYTIMEOUT (20)
 
#define PN532_MIFARE_ISO14443A (0x00)
 
// Mifare Commands
#define MIFARE_CMD_AUTH_A (0x60)
#define MIFARE_CMD_AUTH_B (0x61)
#define MIFARE_CMD_READ (0x30)
#define MIFARE_CMD_WRITE (0xA0)
#define MIFARE_CMD_TRANSFER (0xB0)
#define MIFARE_CMD_DECREMENT (0xC0)
#define MIFARE_CMD_INCREMENT (0xC1)
#define MIFARE_CMD_STORE (0xC2)
 
// Prefixes for NDEF Records (to identify record type)
#define NDEF_URIPREFIX_NONE (0x00)
#define NDEF_URIPREFIX_HTTP_WWWDOT (0x01)
#define NDEF_URIPREFIX_HTTPS_WWWDOT (0x02)
#define NDEF_URIPREFIX_HTTP (0x03)
#define NDEF_URIPREFIX_HTTPS (0x04)
#define NDEF_URIPREFIX_TEL (0x05)
#define NDEF_URIPREFIX_MAILTO (0x06)
#define NDEF_URIPREFIX_FTP_ANONAT (0x07)
#define NDEF_URIPREFIX_FTP_FTPDOT (0x08)
#define NDEF_URIPREFIX_FTPS (0x09)
#define NDEF_URIPREFIX_SFTP (0x0A)
#define NDEF_URIPREFIX_SMB (0x0B)
#define NDEF_URIPREFIX_NFS (0x0C)
#define NDEF_URIPREFIX_FTP (0x0D)
#define NDEF_URIPREFIX_DAV (0x0E)
#define NDEF_URIPREFIX_NEWS (0x0F)
#define NDEF_URIPREFIX_TELNET (0x10)
#define NDEF_URIPREFIX_IMAP (0x11)
#define NDEF_URIPREFIX_RTSP (0x12)
#define NDEF_URIPREFIX_URN (0x13)
#define NDEF_URIPREFIX_POP (0x14)
#define NDEF_URIPREFIX_SIP (0x15)
#define NDEF_URIPREFIX_SIPS (0x16)
#define NDEF_URIPREFIX_TFTP (0x17)
#define NDEF_URIPREFIX_BTSPP (0x18)
#define NDEF_URIPREFIX_BTL2CAP (0x19)
#define NDEF_URIPREFIX_BTGOEP (0x1A)
#define NDEF_URIPREFIX_TCPOBEX (0x1B)
#define NDEF_URIPREFIX_IRDAOBEX (0x1C)
#define NDEF_URIPREFIX_FILE (0x1D)
#define NDEF_URIPREFIX_URN_EPC_ID (0x1E)
#define NDEF_URIPREFIX_URN_EPC_TAG (0x1F)
#define NDEF_URIPREFIX_URN_EPC_PAT (0x20)
#define NDEF_URIPREFIX_URN_EPC_RAW (0x21)
#define NDEF_URIPREFIX_URN_EPC (0x22)
#define NDEF_URIPREFIX_URN_NFC (0x23)
 
#define PN532_GPIO_VALIDATIONBIT (0x80)
#define PN532_GPIO_P30 (0)
#define PN532_GPIO_P31 (1)
#define PN532_GPIO_P32 (2)
#define PN532_GPIO_P33 (3)
#define PN532_GPIO_P34 (4)
#define PN532_GPIO_P35 (5)
 
#define PN532_PACKBUFFSIZ 64
#define PN532_TIMEOUT 1000
 
typedef struct {
unsigned char IC;
unsigned char Ver;
unsigned char Rev;
unsigned char Support;
} NFC_FIRMWARE_VERSION;
 
typedef struct {
unsigned char TG;
unsigned char SENS_RES[2];
unsigned char SEL_RES;
unsigned char NFCID_LEN;
unsigned char NFCID[7];
} NFC_TargetDataMiFare;
// Size can be 9 or 12 bytes
 
typedef struct __NFC_DATA {
unsigned char packetbuffer[PN532_PACKBUFFSIZ];
} NFC_DATA;
 
void NFC_Init(void);
 
// Generic PN532 functions
unsigned char NFC_SAMConfig(void);
NFC_FIRMWARE_VERSION NFC_Get_Firmware_Version(void);
unsigned char NFC_Send_Command_Check_Ack(unsigned char *cmd, unsigned char cmdlen);
//unsigned char NFC_writeGPIO(unsigned char pinstate);
//unsigned char NFC_readGPIO(void);
 
// ISO14443A functions
unsigned char NFC_Read_Passive_Target_ID(NFC_TargetDataMiFare *uidData);
unsigned char NFC_Poll_Targets(unsigned char number, unsigned char period, NFC_TargetDataMiFare *uidData);
 
// Mifare Classic functions
unsigned char NFC_mifareclassic_IsFirstBlock(unsigned long uiBlock);
unsigned char NFC_mifareclassic_IsTrailerBlock(unsigned long uiBlock);
unsigned char NFC_mifareclassic_AuthenticateBlock(unsigned char *uid, unsigned char uidLen, unsigned long blockNumber, unsigned char keyNumber, unsigned char *keyData);
unsigned char NFC_mifareclassic_ReadDataBlock(unsigned char blockNumber, unsigned char *data);
unsigned char NFC_mifareclassic_WriteDataBlock(unsigned char blockNumber, unsigned char *data);
unsigned char NFC_mifareclassic_FormatNDEF(void);
unsigned char NFC_mifareclassic_WriteNDEFURI(unsigned char sectorNumber, unsigned char uriIdentifier, const char * url);
 
// Mifare Ultralight functions
//unsigned char NFC_mifareultralight_ReadPage(unsigned char page, unsigned char * buffer);
 
// Low level SPI functions
unsigned char NFC_I2C_Read_ACK(void);
unsigned char NFC_I2C_Read_Status(void);
void NFC_I2C_Read_Data(unsigned char *buffer, unsigned char length);
void NFC_I2C_Write_Cmd(unsigned char *cmd, unsigned char cmdlen);
 
#endif
 
/PIC Projects/PIC_27J13/xbee.c
0,0 → 1,237
#include "defines.h"
#include "xbee.h"
#include <string.h>
 
#pragma udata XBEE_BUFFER
static XBEE_DATA xbee_data;
#pragma udata
static XBEE_DATA *xbee_data_p = &xbee_data;
static void *xbee_data_frame;
static void *xbee_frame;
 
/* Initialize variables used by this library */
void XBee_Init() {
XBEE_CTS_TRIS = 1; // RB0 is CTS, set by XBee chip
XBEE_RTS_TRIS = 0; // RB1 is RTS, set by PIC
 
XBEE_CTS_LAT = 0; // Pin set high to signal stop sending data to XBee
XBEE_RTS_LAT = 0; // Pin set high to indicate stop sending data to PIC
 
xbee_data_p->dataind = 0;
xbee_data_p->checksum_sum = 0;
xbee_data_p->frame_rdy = 0;
xbee_data_p->escape_flag = 0;
xbee_data_p->read_state = XBEE_STATE_READ_START;
 
// memset(&xbee_data, 0, 32);
// Grab a pointer to where the unique frame array starts
xbee_data_frame = &(xbee_data_p->rcv_frame.FRAME);
xbee_frame = &(xbee_data_p->rcv_frame);
}
 
/* Here we handle the serial input from the UART interrupt */
void XBee_Serial_In(unsigned char c) {
// For some reason writing the length straight to xbee_data doesnt seem to work
// so we work around it by pointing to the length bytes directly
XBEE_ADDRESS_16 *length = xbee_frame + 1;
#ifdef XBEE_USE_ESCAPE_CHAR
if (c == XBEE_ESCAPE_CHAR) {
// Next byte needs is an escaped char
xbee_data_p->escape_flag = 1;
return;
}
 
if (xbee_data_p->escape_flag) {
// XOR byte with 0x20 to get escaped char
c ^= XBEE_ESCAPE_VAL;
xbee_data_p->escape_flag = 0;
}
#endif
// Reset on start bit and start saving data
if (c == XBEE_START_DELIMITER) {
// On detect start delimiter, clear out initial array
xbee_data_p->dataind = 0;
xbee_data_p->checksum_sum = 0;
xbee_data_p->frame_rdy = 0;
xbee_data_p->read_state = XBEE_STATE_READ_LENGTH_HIGH;
*((unsigned char *)xbee_frame) = XBEE_START_DELIMITER;
} else {
switch (xbee_data_p->read_state) {
case XBEE_STATE_READ_START:
// Do nothing and wait till start bit is read
break;
case XBEE_STATE_READ_LENGTH_HIGH:
// Read length (MSB)
length->INT_16.char_value[1] = c;
xbee_data_p->read_state = XBEE_STATE_READ_LENGTH_LOW;
break;
case XBEE_STATE_READ_LENGTH_LOW:
// Read length (LSB)
length->INT_16.char_value[0] = c;
xbee_data_p->read_state = XBEE_STATE_READ_FRAME_DATA;
break;
case XBEE_STATE_READ_FRAME_DATA:
// Read unique frame data
if (xbee_data_p->dataind < xbee_data_p->rcv_frame.length.INT_16.int_value) {
*((char*) xbee_data_frame + xbee_data_p->dataind) = c;
xbee_data_p->checksum_sum += c;
xbee_data_p->dataind++;
}
// If total length is read, the next byte is the expected checksum
if (xbee_data_p->dataind == xbee_data_p->rcv_frame.length.INT_16.int_value) {
xbee_data_p->read_state = XBEE_STATE_READ_CHECKSUM;
}
break;
case XBEE_STATE_READ_CHECKSUM:
// Calculate and compare checksum
if (0xFF - xbee_data_p->checksum_sum == c) {
// Frame was recieved successfully
xbee_data_p->frame_rdy = 1;
// XBee_Process_Received_Frame();
} else {
// If checksum does not match, drop frame
DBG_PRINT_XBEE("XBEE: checksum mismatch\r\n");
}
xbee_data_p->read_state = XBEE_STATE_READ_START;
break;
}
}
}
 
/* This processes the frame data within the interrupt. Dont use this. */
void XBee_Process_Received_Frame() {
// DBG_PRINT_XBEE("Length: %d\r\n", xbee_data_p->rcv_frame.length.INT_16.int_value);
// Here we process the received frame depending on the frame type
switch (*((unsigned char *) xbee_data_frame)) {
case XBEE_RX_AT_COMMAND_RESPONSE:
DBG_PRINT_XBEE("XBEE: parsing recieved AT command response frame\r\n");
break;
case XBEE_RX_DATA_PACKET:
DBG_PRINT_XBEE("XBEE: parsing recieved data frame\r\n");
break;
case XBEE_RX_DATA_TX_STATUS:
DBG_PRINT_XBEE("XBEE: parsing recieved TX status frame\r\n");
break;
case XBEE_RX_IO_DATA_SAMPLE:
DBG_PRINT_XBEE("XBEE: parsing recieved IO data sample frame\r\n");
break;
case XBEE_RX_EXPLICIT_COMMAND:
DBG_PRINT_XBEE("XBEE: parsing recieved explicit command frame\r\n");
break;
case XBEE_RX_REMOTE_AT_COMMAND_RESPONSE:
DBG_PRINT_XBEE("XBEE: parsing recieved remote AT command frame\r\n");
break;
case XBEE_RX_ROUTE_RECORD:
DBG_PRINT_XBEE("XBEE: parsing recieved route record frame\r\n");
break;
case XBEE_RX_NODE_IDENTIFICATION:
DBG_PRINT_XBEE("XBEE: parsing recieved node identification frame\r\n");
break;
case XBEE_RX_FRAME_MODEM_STATUS:
DBG_PRINT_XBEE("XBEE: parsing recieved modem status frame\r\n");
break;
default:
DBG_PRINT_XBEE("XBEE: (ERROR) unrecognized frame type\r\n");
}
}
 
unsigned int XBee_Get_Received_Frame(unsigned char *frame) {
if (!xbee_data_p->frame_rdy) {
return 0;
} else {
memcpy(frame, xbee_data_frame, xbee_data_p->rcv_frame.length.INT_16.int_value);
xbee_data_p->frame_rdy = 0; // Reset frame ready status
return xbee_data_p->rcv_frame.length.INT_16.int_value;
}
}
 
void XBee_Process_Transmit_Frame(unsigned char *data, unsigned char length) {
#ifdef XBEE_USE_ESCAPE_CHAR
unsigned int i = 0;
unsigned char chksum = 0;
 
// Write the start bit and length
UART1_WriteC(XBEE_START_DELIMITER);
UART1_WriteC(0);
UART1_WriteC(length);
 
// Write the frame data
for (i = 0; i < length; i++) {
chksum += data[i];
if (data[i] == XBEE_START_DELIMITER || \
data[i] == XBEE_ESCAPE_CHAR || \
data[i] == XBEE_XON || \
data[i] == XBEE_XOFF) {
UART1_WriteC(XBEE_ESCAPE_CHAR);
UART1_WriteC(data[i] ^ XBEE_ESCAPE_VAL);
} else {
UART1_WriteC(data[i]);
}
}
// Write the checksum
if (chksum == XBEE_START_DELIMITER || \
chksum == XBEE_ESCAPE_CHAR || \
chksum == XBEE_XON || \
chksum == XBEE_XOFF) {
UART1_WriteC(XBEE_ESCAPE_CHAR);
UART1_WriteC(chksum ^ XBEE_ESCAPE_VAL);
} else {
UART1_WriteC(0xFF - chksum);
}
#else
unsigned int i = 0;
unsigned char chksum = 0;
 
UART1_WriteC(XBEE_START_DELIMITER);
UART1_WriteC(0);
UART1_WriteC(length);
for (i = 0; i < length; i++) {
chksum += data[i];
UART1_WriteC(data[i]);
}
UART1_WriteC(0xFF - chksum);
#endif
}
 
void XBee_Set_RTS(unsigned char c) {
if (c) {
XBEE_RTS_LAT = 1; // Set high to stop receiving data
} else {
XBEE_RTS_LAT = 0; // Set low to resume receiving data
}
}
 
unsigned char XBee_Read_CTS() {
unsigned char c = XBEE_CTS_PORT;
if (c) {
return 0x1; // High indicates stop sending data
} else {
return 0x0; // Low indicates ok to send data
}
}
 
void XBee_Convert_Endian_64(XBEE_ADDRESS_64 *src) {
char tmp[2];
tmp[0] = src->UPPER_32.char_value[3];
tmp[1] = src->UPPER_32.char_value[2];
src->UPPER_32.char_value[3] = src->UPPER_32.char_value[0];
src->UPPER_32.char_value[2] = src->UPPER_32.char_value[1];
src->UPPER_32.char_value[1] = tmp[1];
src->UPPER_32.char_value[0] = tmp[0];
 
tmp[0] = src->LOWER_32.char_value[3];
tmp[1] = src->LOWER_32.char_value[2];
src->LOWER_32.char_value[3] = src->LOWER_32.char_value[0];
src->LOWER_32.char_value[2] = src->LOWER_32.char_value[1];
src->LOWER_32.char_value[1] = tmp[1];
src->LOWER_32.char_value[0] = tmp[0];
}
 
void XBee_Convert_Endian_16(XBEE_ADDRESS_16 *src) {
char tmp;
tmp = src->INT_16.char_value[0];
src->INT_16.char_value[0] = src->INT_16.char_value[1];
src->INT_16.char_value[1] = tmp;
}
/PIC Projects/PIC_27J13/interrupts.c
0,0 → 1,204
#include "defines.h"
#include "interrupts.h"
#include "uart.h"
#include "i2c.h"
#include "spi.h"
#include "adc.h"
#include "timers.h"
 
//----------------------------------------------------------------------------
// Note: This code for processing interrupts is configured to allow for high and
// low priority interrupts. The high priority interrupt can interrupt the
// the processing of a low priority interrupt. However, only one of each type
// can be processed at the same time. It is possible to enable nesting of low
// priority interrupts, but this code is not setup for that and this nesting
// is not enabled.
 
void Interrupt_Init() {
// Peripheral interrupts can have their priority set to high or low
// Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
 
// High priority interrupts
IPR1bits.RC1IP = 1; // USART1 RX interrupt
IPR1bits.TX1IP = 1; // USART1 TX interrupt
// IPR3bits.RC2IP = 1; // USART2 RX interrupt
IPR1bits.SSPIP = 1; // I2C interrupt
IPR3bits.SSP2IP = 1; // MSSP2 (SPI2) interrupt
 
// Low priority interrupts
// INTCON2bits.TMR0IP = 0; // Timer0 interrupt
IPR1bits.TMR1IP = 0; // Timer1 interrupt
// IPR2bits.TMR3IP = 0; // Timer 3 interrupt
// IPR1bits.ADIP = 0; // ADC interupt
// INTCON2bits.RBIP = 0; // Port B interrupt
// INTCON3bits.INT1IP = 0; // INT1 interrupt
// Enable Port B interrupt
// INTCONbits.RBIE = 1;
// Enable interrupt for INT1
// INTCON3bits.INT1IE = 1;
}
 
void Interrupt_Enable() {
// Peripheral interrupts can have their priority set to high or low.
// Enable both high-priority interrupts and low-priority interrupts
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
}
 
void Interrupt_Disable() {
RCONbits.IPEN = 0;
INTCONbits.GIEH = 0;
INTCONbits.GIEL = 0;
}
 
// Set up the interrupt vectors
void InterruptHandlerHigh();
void InterruptHandlerLow();
 
#pragma code InterruptVectorLow = 0x18
 
void InterruptVectorLow(void) {
_asm
goto InterruptHandlerLow //jump to interrupt routine
_endasm
}
 
#pragma code InterruptVectorHigh = 0x08
 
void InterruptVectorHigh(void) {
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
 
//----------------------------------------------------------------------------
// High priority interrupt routine
// this parcels out interrupts to individual handlers
 
#pragma code
#pragma interrupt InterruptHandlerHigh
 
void InterruptHandlerHigh() {
// We need to check the interrupt flag of each enabled high-priority interrupt to
// see which device generated this interrupt. Then we can call the correct handler.
 
// // Check to see if we have an SPI2 interrupt
// if (PIR3bits.SSP2IF) {
// // Call the handler
// SPI2_Recv_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR3bits.SSP2IF = 0;
//
// return;
// }
 
// Check to see if we have an I2C interrupt
if (PIR1bits.SSPIF) {
// Call the handler
I2C_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.SSPIF = 0;
 
return;
}
// Check to see if we have an interrupt on USART1 RX
if (PIR1bits.RC1IF) {
// Call the interrupt handler
UART1_Recv_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.RC1IF = 0;
 
return;
}
 
#ifndef _DEBUG // Disable UART1 TX interrupt for debug mode (using printf)
// Check to see if we have an interrupt on USART1 TX
if (PIR1bits.TX1IF) {
// Call the interrupt handler
UART1_Send_Interrupt_Handler();
// Clear the interrupt flag
PIR1bits.TX1IF = 0;
 
return;
}
#endif
// // Check to see if we have an interrupt on USART2 RX
// if (PIR3bits.RC2IF) {
// DBG_PRINT_INT("INT: UART2 RX\r\n");
// // Call the interrupt handler
// uart_2_recv_interrupt_handler();
//
// // Clear the interrupt flag
// PIR3bits.RC2IF = 0;
// }
}
 
//----------------------------------------------------------------------------
// Low priority interrupt routine
// this parcels out interrupts to individual handlers
#pragma code
#pragma interruptlow InterruptHandlerLow
// This works the same way as the "High" interrupt handler
 
void InterruptHandlerLow() {
// // Check to see if we have an interrupt on INT1
// if (INTCON3bits.INT1IF) {
// DBG_PRINT_INT("INT: INT1\r\n");
// int1_interrupt_handler();
//
// INTCON3bits.INT1IF = 0;
// }
 
// // Check to see if we have an interrupt on any port B inputs <4:7>
// if (INTCONbits.RBIF) {
// DBG_PRINT_INT("INT: Port B\r\n");
// port_b_int_interrupt_handler();
//
// INTCONbits.RBIF = 0;
// }
// // Check to see if we have an interrupt on timer 0
// if (INTCONbits.TMR0IF) {
// DBG_PRINT_INT("INT: Timer 0\r\n");
// // Call the handler
// timer0_interrupt_handler();
//
// // Clear this interrupt flag
// INTCONbits.TMR0IF = 0;
// }
 
// Check to see if we have an interrupt on timer 1
if (PIR1bits.TMR1IF) {
// Call the interrupt handler
Timer1_Interrupt_Handler();
 
// Clear the interrupt flag
PIR1bits.TMR1IF = 0;
}
 
// // Check to see if we have an interrupt on timer 3
// if (PIR2bits.TMR3IF) {
// DBG_PRINT_INT("INT: Timer 3\r\n");
// timer3_interrupt_handler();
//
// PIR2bits.TMR3IF = 0;
// }
 
// // Check to see if we have an interrupt on ADC
// if (PIR1bits.ADIF) {
// // Call the interrupt handler
// ADC_Interrupt_Handler();
//
// // Clear the interrupt flag
// PIR1bits.ADIF = 0;
// }
}
 
/PIC Projects/PIC_27J13/temp_BMP085.c
0,0 → 1,190
#include "defines.h"
#include "temp_BMP085.h"
#include "i2c.h"
#include <delays.h>
#include <math.h>
 
static BMP085_DATA bmp085_data;
static BMP085_DATA *bmp085_data_p = &bmp085_data;
 
void BMP_Init() {
 
}
 
void BMP_Begin(unsigned char mode) {
if (mode > BMP085_ULTRAHIGHRES)
mode = BMP085_ULTRAHIGHRES;
bmp085_data_p->oversampling = mode;
 
if (BMP_Read8(0xD0) != 0x55) {
DBG_PRINT_BMP("Error contacting BMP085!\r\n");
return;
}
 
bmp085_data_p->ac1 = BMP_Read16(BMP085_CAL_AC1);
bmp085_data_p->ac2 = BMP_Read16(BMP085_CAL_AC2);
bmp085_data_p->ac3 = BMP_Read16(BMP085_CAL_AC3);
bmp085_data_p->ac4 = BMP_Read16(BMP085_CAL_AC4);
bmp085_data_p->ac5 = BMP_Read16(BMP085_CAL_AC5);
bmp085_data_p->ac6 = BMP_Read16(BMP085_CAL_AC6);
 
bmp085_data_p->b1 = BMP_Read16(BMP085_CAL_B1);
bmp085_data_p->b2 = BMP_Read16(BMP085_CAL_B2);
 
bmp085_data_p->mb = BMP_Read16(BMP085_CAL_MB);
bmp085_data_p->mc = BMP_Read16(BMP085_CAL_MC);
bmp085_data_p->md = BMP_Read16(BMP085_CAL_MD);
 
DBG_PRINT_BMP("AC1 = %d\r\n", bmp085_data_p->ac1);
DBG_PRINT_BMP("AC2 = %d\r\n", bmp085_data_p->ac2);
DBG_PRINT_BMP("AC3 = %d\r\n", bmp085_data_p->ac3);
DBG_PRINT_BMP("AC4 = %u\r\n", bmp085_data_p->ac4);
DBG_PRINT_BMP("AC5 = %u\r\n", bmp085_data_p->ac5);
DBG_PRINT_BMP("AC6 = %u\r\n", bmp085_data_p->ac6);
 
DBG_PRINT_BMP("B1 = %d\r\n", bmp085_data_p->b1);
DBG_PRINT_BMP("B2 = %d\r\n", bmp085_data_p->b2);
 
DBG_PRINT_BMP("MB = %d\r\n", bmp085_data_p->mb);
DBG_PRINT_BMP("MC = %d\r\n", bmp085_data_p->mc);
DBG_PRINT_BMP("MD = %d\r\n", bmp085_data_p->md);
}
 
unsigned int BMP_Read_Raw_Temperature() {
unsigned int ret;
 
BMP_Write8(BMP085_CONTROL, BMP085_READTEMPCMD);
Delay10KTCYx(255);
ret = BMP_Read16(BMP085_TEMPDATA);
DBG_PRINT_BMP("Raw Temp: %d\r\n", ret);
return ret;
}
 
unsigned long BMP_Read_Raw_Pressure() {
unsigned long ret;
 
BMP_Write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (bmp085_data_p->oversampling << 6));
 
if (bmp085_data_p->oversampling == BMP085_ULTRALOWPOWER)
Delay10KTCYx(255);
else if (bmp085_data_p->oversampling == BMP085_STANDARD)
Delay10KTCYx(255);
else if (bmp085_data_p->oversampling == BMP085_HIGHRES)
Delay10KTCYx(255);
else
Delay10KTCYx(255);
 
ret = BMP_Read16(BMP085_PRESSUREDATA);
ret <<= 8;
ret |= BMP_Read8(BMP085_PRESSUREDATA+2);
ret >>= (8 - bmp085_data_p->oversampling);
 
DBG_PRINT_BMP("Raw Pressure: %ld\r\n", ret);
 
return ret;
}
 
long BMP_Read_Pressure() {
long UT, UP, B3, B5, B6, X1, X2, X3, p;
unsigned long B4, B7;
 
UT = BMP_Read_Raw_Temperature();
UP = BMP_Read_Raw_Pressure();
 
// Temperature calculations
X1 = ((UT - (long) bmp085_data_p->ac6) * (long) bmp085_data_p->ac5) >> 15;
X2 = ((long) bmp085_data_p->mc << 11) - (X1 + bmp085_data_p->md) / 2; // round up
X2 /= (X1 + bmp085_data_p->md);
B5 = X1 + X2;
 
// Pressure calcs
B6 = B5 - 4000;
X1 = ((long) bmp085_data_p->b2 * ((B6 * B6) >> 12)) >> 11;
X2 = ((long) bmp085_data_p->ac2 * B6) >> 11;
X3 = X1 + X2;
B3 = ((((long) bmp085_data_p->ac1 * 4 + X3) << bmp085_data_p->oversampling) + 2) / 4;
 
X1 = ((long) bmp085_data_p->ac3 * B6) >> 13;
X2 = ((long) bmp085_data_p->b1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = ((unsigned long) bmp085_data_p->ac4 * (unsigned long) (X3 + 32768)) >> 15;
B7 = ((unsigned long) UP - B3) * (unsigned long) (50000UL >> bmp085_data_p->oversampling);
 
if (B7 < 0x80000000) {
p = (B7 * 2) / B4;
} else {
p = (B7 / B4) * 2;
}
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
 
p = p + ((X1 + X2 + (long)3791)>>4);
 
return p;
}
 
float BMP_Read_Temperature() {
long UT, X1, X2, B5;
float temp;
 
UT = BMP_Read_Raw_Temperature();
 
X1 = ((UT - (long) bmp085_data_p->ac6) * (long) bmp085_data_p->ac5) >> 15;
X2 = ((long) bmp085_data_p->mc << 11) / (X1 + (long) bmp085_data_p->md);
B5 = X1 + X2;
temp = (B5 + 8) >> 4;
temp /= 10;
 
return temp;
}
 
float BMP_Read_Altitude(float seaLevelPressure) {
float altitude;
float pressure = BMP_Read_Pressure();
altitude = 44330 * (1.0 - pow(pressure /seaLevelPressure,0.1903));
return altitude;
}
 
unsigned char BMP_Read8(unsigned char a) {
unsigned char buffer[6], result, length, ret = 0;
I2C_Master_Restart(BMP085_I2CADDR, a, 1);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
ret = buffer[0];
 
return ret;
}
 
unsigned int BMP_Read16(unsigned char a) {
unsigned char buffer[6], result, length;
unsigned int ret;
 
I2C_Master_Restart(BMP085_I2CADDR, a, 2);
do {
result = I2C_Get_Status();
} while (!result);
length = I2C_Read_Buffer((char *)buffer);
ret = buffer[0];
ret <<= 8;
ret |= buffer[1];
 
return ret;
}
 
void BMP_Write8(unsigned char a, unsigned char d) {
unsigned char buffer[2], result;
buffer[0] = a;
buffer[1] = d;
 
I2C_Master_Send(BMP085_I2CADDR, 2, buffer);
do {
result = I2C_Get_Status();
} while (!result);
}
/PIC Projects/PIC_27J13/temp_BMP085.h
0,0 → 1,47
#ifndef TEMP_BMP085_H
#define TEMP_BMP085_H
 
#define BMP085_I2CADDR 0x77
 
#define BMP085_ULTRALOWPOWER 0
#define BMP085_STANDARD 1
#define BMP085_HIGHRES 2
#define BMP085_ULTRAHIGHRES 3
#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
 
#define BMP085_CONTROL 0xF4
#define BMP085_TEMPDATA 0xF6
#define BMP085_PRESSUREDATA 0xF6
#define BMP085_READTEMPCMD 0x2E
#define BMP085_READPRESSURECMD 0x34
 
typedef struct __BMP085_DATA {
int ac1, ac2, ac3, b1, b2, mb, mc, md;
unsigned int ac4, ac5, ac6;
unsigned char oversampling;
} BMP085_DATA;
 
void BMP_Init(void);
void BMP_Begin(unsigned char mode);
unsigned int BMP_Read_Raw_Temperature(void);
unsigned long BMP_Read_Raw_Pressure(void);
float BMP_Read_Temperature(void);
long BMP_Read_Pressure(void);
float BMP_Read_Altitude(float seaLevelPressure);
 
unsigned char BMP_Read8(unsigned char a);
unsigned int BMP_Read16(unsigned char a);
void BMP_Write8(unsigned char a, unsigned char d);
 
#endif /* TEMP_BMP085_H */
 
/PIC Projects/PIC_27J13/uart.c
0,0 → 1,244
#include "defines.h"
#include "uart.h"
#include "xbee.h"
#include <string.h>
#include <stdio.h>
 
#pragma udata UART1_BUFFER
static UART_DATA uart_1_data;
#pragma udata
static UART_DATA *uart_1_data_p = &uart_1_data;
 
void UART1_Init() {
// Configure the hardware USART device
// UART1 TX RC6
// UART1 RX RC7
 
UART1_TX_TRIS = 0; // Tx pin set to output
UART1_RX_TRIS = 1; // Rx pin set to input
 
BAUDCON1bits.BRG16 = 0; // 8-bit baud rate generator
SPBRG1 = 25; // Set UART speed to 115200 baud
TXSTA1bits.BRGH = 1; // High speed mode
TXSTA1bits.SYNC = 0; // Async mode
RCSTA1bits.SPEN = 1; // Serial port enable
TXSTA1bits.TX9 = 0; // 8 bit transmission
RCSTA1bits.RX9 = 0; // 8 bit reception
RCSTA1bits.CREN = 1; // Continuous receive mode
 
#ifdef _DEBUG // In debug mode we want to have TXEN constantly enabled
TXSTA1bits.TXEN = 1; // TX is always enabled
PIE1bits.TX1IE = 0; // Disable TX interrupt
#else
TXSTA1bits.TXEN = 0; // Enable transmission
PIE1bits.TX1IE = 1; // Enable TX interrupt
#endif
 
PIE1bits.RC1IE = 1; // Enable RX interrupt
 
// Initialize the buffer that holds UART messages
uart_1_data_p->buffer_in_read_ind = 0;
uart_1_data_p->buffer_in_write_ind = 0;
uart_1_data_p->buffer_in_len = 0;
uart_1_data_p->buffer_in_len_tmp = 0;
}
 
//void uart_2_init() {
// // Configure the PPS USART ports
//
// // UART2 RX Pin RP5
// RPINR16 = PPS_UART2_RX; // 5 is PPS RP5
// // UART2 TX Pin RP6
// PPS_UART2_TX = 6; // 6 is TX2/CK2 (EUSART2 Asynchronous Transmit/Asynchronous Clock Output)
//
// Open2USART(USART_TX_INT_OFF & // Interrupt on TX off
// USART_RX_INT_ON & // Interrupt on RX on
// USART_ASYNCH_MODE & // Operate in async mode
// USART_EIGHT_BIT & // Operate in 8-bit mode
// USART_CONT_RX & // Continuously recieve messages
// USART_BRGH_HIGH, 25); // Set UART speed to 115200 baud
//}
 
void UART1_Recv_Interrupt_Handler() {
unsigned char c;
if (PIR1bits.RC1IF) { // Check if data receive flag is set
c = RCREG1;
#ifdef UART1_RX_TO_BUFFER
// Save received data into buffer
uart_1_data_p->buffer_in[uart_1_data_p->buffer_in_write_ind] = c;
if (uart_1_data_p->buffer_in_write_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_write_ind = 0;
} else {
uart_1_data_p->buffer_in_write_ind++;
}
 
// Store the last MAXUARTBUF values entered
if (uart_1_data_p->buffer_in_len_tmp < MAXUARTBUF) {
uart_1_data_p->buffer_in_len_tmp++;
} else {
if (uart_1_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_read_ind = 0;
} else {
uart_1_data_p->buffer_in_read_ind++;
}
}
 
// Update buffer size upon receiving newline (0x0D)
if (c == UART1_BREAK_CHAR) {
uart_1_data_p->buffer_in_len = uart_1_data_p->buffer_in_len_tmp;
uart_1_data_p->buffer_in_len_tmp = 0;
}
#endif
#ifdef UART1_RX_TO_XBEE
XBee_Serial_In(c);
#endif
}
 
if (RCSTA1bits.OERR == 1) {
// We've overrun the USART and must reset
RCSTA1bits.CREN = 0; // Reset UART1
RCSTA1bits.CREN = 1;
DBG_PRINT_UART("UART1: (ERROR) overrun\r\n");
TXSTA1bits.TXEN = 0; // Kill anything currently sending
}
}
 
//void uart_2_recv_interrupt_handler() {
// if (DataRdy2USART()) {
//// xbee_read_serial(Read2USART());
// }
//
// if (USART2_Status.OVERRUN_ERROR == 1) {
// // We've overrun the USART and must reset
// RCSTA2bits.CREN = 0; // Reset UART2
// RCSTA2bits.CREN = 1;
// }
//}
 
void UART1_Send_Interrupt_Handler() {
// Put remaining data in TSR for transmit
if (uart_1_data_p->buffer_out_ind != uart_1_data_p->buffer_out_len) {
TXREG1 = uart_1_data_p->buffer_out[uart_1_data_p->buffer_out_ind];
uart_1_data_p->buffer_out_ind++;
} else {
while (!TXSTA1bits.TRMT); // Wait for last byte to finish sending
TXSTA1bits.TXEN = 0; // End transmission and disable TX interrupt
uart_1_data_p->buffer_out_ind = 0;
uart_1_data_p->buffer_out_len = 0;
}
}
 
void UART1_WriteS(const rom char *fmt, ...) {
#ifdef _DEBUG
unsigned char i;
va_list args;
va_start(args, fmt);
vsprintf((char *) uart_1_data_p->buffer_out, fmt, args);
va_end(args);
uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
uart_1_data_p->buffer_out_ind = 1;
for (i = 0; i < uart_1_data_p->buffer_out_len; i++) {
TXREG1 = uart_1_data_p->buffer_out[i];
Nop();
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
}
#else
va_list args;
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
va_start(args, fmt);
vsprintf((char *) uart_1_data_p->buffer_out, fmt, args);
va_end(args);
uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
uart_1_data_p->buffer_out_ind = 1;
TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
void UART1_WriteF(float f, unsigned char m) {
long whole = 0;
unsigned long decimal = 0;
unsigned int multiplier = 1;
unsigned char i;
 
for (i = 0; i < m; i++)
multiplier *= 10;
 
whole = (long)((float)f);
decimal = (long)((float)f*multiplier) - whole*multiplier;
// Round up if necessary
if ((long)((float)f*multiplier*10) % 10 >= 5)
decimal += 1;
#ifdef _DEBUG
sprintf((char *) uart_1_data_p->buffer_out, "%ld.%ld", whole, decimal);
uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
uart_1_data_p->buffer_out_ind = 1;
for (i = 0; i < uart_1_data_p->buffer_out_len; i++) {
TXREG1 = uart_1_data_p->buffer_out[i];
Nop();
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
}
#else
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
sprintf((char *) uart_1_data_p->buffer_out, "%ld.%ld", whole, decimal);
uart_1_data_p->buffer_out_len = strlen((char *) uart_1_data_p->buffer_out);
uart_1_data_p->buffer_out_ind = 1;
TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
void UART1_WriteB(const char *msg, unsigned char length) {
unsigned char i;
#ifdef _DEBUG
for (i = 0; i < length; i++) {
TXREG1 = msg[i];
Nop();
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted
}
#else
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
uart_1_data_p->buffer_out_len = length;
uart_1_data_p->buffer_out_ind = 1;
for (i = 0; i < length; i++) {
uart_1_data_p->buffer_out[i] = msg[i];
}
TXREG1 = uart_1_data_p->buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
void UART1_WriteC(const unsigned char c) {
#ifdef _DEBUG
TXREG1 = c;
Nop();
while (!PIR1bits.TX1IF);
#else
while (TXSTA1bits.TXEN);
uart_1_data_p->buffer_out_len = 1;
uart_1_data_p->buffer_out_ind = 1;
TXREG1 = c;
TXSTA1bits.TXEN = 1;
#endif
 
}
 
unsigned char UART1_Buffer_Len() {
return uart_1_data_p->buffer_in_len;
}
 
/* Reader interface to the UART buffer, returns the number of bytes read */
unsigned char UART1_Read_Buffer(unsigned char *buffer) {
unsigned char i = 0;
while (uart_1_data_p->buffer_in_len != 0) {
buffer[i] = uart_1_data_p->buffer_in[uart_1_data_p->buffer_in_read_ind];
i++;
if (uart_1_data_p->buffer_in_read_ind == MAXUARTBUF - 1) {
uart_1_data_p->buffer_in_read_ind = 0;
} else {
uart_1_data_p->buffer_in_read_ind++;
}
uart_1_data_p->buffer_in_len--;
}
return i;
}
/PIC Projects/PIC_27J13/oled_NHD-0216KZW-AB5.c
0,0 → 1,196
#include "oled_NHD-0216KZW-AB5.h"
#include "defines.h"
#include <delays.h>
#include <string.h>
#include <stdio.h>
 
static OLED_CHAR_DATA oled_char_data;
static OLED_CHAR_DATA *oled_char_data_p = &oled_char_data;
 
void NHD_Init() {
PARALLEL_RS_TRIS = 0;
PARALLEL_RW_TRIS = 0;
PARALLEL_EN_TRIS = 0;
 
PARALLEL_D4_TRIS = 0;
PARALLEL_D5_TRIS = 0;
PARALLEL_D6_TRIS = 0;
PARALLEL_D7_TRIS = 0;
 
oled_char_data_p->display_function = LCD_FUNCTIONSET | LCD_4BITMODE;
}
 
void NHD_Begin(char cols, char rows) {
oled_char_data_p->num_lines = rows;
oled_char_data_p->current_line = 0;
 
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 0;
PARALLEL_EN_LAT = 0;
 
PARALLEL_D4_LAT = 0;
PARALLEL_D5_LAT = 0;
PARALLEL_D6_LAT = 0;
PARALLEL_D7_LAT = 0;
Delay10KTCYx(1); // ~1ms
 
// Initialization sequence
NHD_Write_4_Bits(0x3);
NHD_Write_4_Bits(0x2);
NHD_Write_4_Bits(0x2);
NHD_Write_4_Bits(0x8);
NHD_Wait_For_Ready();
 
NHD_Send_Command(0x08); // Turn Off
NHD_Send_Command(0x01); // Clear Display
NHD_Send_Command(0x06); // Set Entry Mode
NHD_Send_Command(0x02); // Return to Home Position
NHD_Send_Command(0x0C); // Turn On
}
 
void NHD_Clear() {
NHD_Send_Command(LCD_CLEARDISPLAY);
}
 
void NHD_Home() {
NHD_Send_Command(LCD_RETURNHOME);
}
 
void NHD_Set_Cursor(unsigned char col, unsigned char row) {
unsigned char row_offsets[] = {0x00, 0x40, 0x14, 0x54};
if (row >= oled_char_data_p->num_lines) {
row = 0;
}
NHD_Send_Command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
 
void NHD_Display(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_DISPLAYON;
} else {
oled_char_data_p->display_control &= ~LCD_DISPLAYON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Blink(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_BLINKON;
} else {
oled_char_data_p->display_control &= ~LCD_BLINKON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Cursor(char option) {
if (option) {
oled_char_data_p->display_control |= LCD_CURSORON;
} else {
oled_char_data_p->display_control &= ~LCD_CURSORON;
}
NHD_Send_Command(LCD_DISPLAYCONTROL | oled_char_data_p->display_control);
}
 
void NHD_Scroll_Display_Left() {
NHD_Send_Command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
 
void NHD_Scroll_Display_Right() {
NHD_Send_Command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
 
void NHD_Left_To_Rigtht() {
oled_char_data_p->display_mode |= LCD_ENTRYLEFT;
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Right_To_Left() {
oled_char_data_p->display_mode &= ~LCD_ENTRYLEFT;
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Autoscroll(char option) {
if (option) {
oled_char_data_p->display_mode |= LCD_ENTRYSHIFTINCREMENT;
} else {
oled_char_data_p->display_mode &= ~LCD_ENTRYSHIFTINCREMENT;
}
NHD_Send_Command(LCD_ENTRYMODESET | oled_char_data_p->display_mode);
}
 
void NHD_Create_Char(unsigned char location, unsigned char *charmap) {
char i;
location &= 0x7;
NHD_Send_Command(LCD_SETCGRAMADDR | (location << 3));
for (i = 0; i < 8; i++) {
NHD_Send_Data(charmap[i]);
}
}
 
void NHD_Send_Command(unsigned char value) {
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 0;
NHD_Write_4_Bits(value>>4);
NHD_Write_4_Bits(value);
NHD_Wait_For_Ready();
}
 
void NHD_Send_Data(unsigned char value) {
PARALLEL_RS_LAT = 1;
PARALLEL_RW_LAT = 0;
NHD_Write_4_Bits(value>>4);
NHD_Write_4_Bits(value);
NHD_Wait_For_Ready();
}
 
void NHD_Pulse_Enable(void) {
PARALLEL_EN_LAT = 1;
Nop();
Nop();
PARALLEL_EN_LAT = 0;
}
 
void NHD_Write_4_Bits(unsigned char value) {
PARALLEL_D4_LAT = (value) & 0x01;
PARALLEL_D5_LAT = (value>>1) & 0x01;
PARALLEL_D6_LAT = (value>>2) & 0x01;
PARALLEL_D7_LAT = (value>>3) & 0x01;
NHD_Pulse_Enable();
}
 
void NHD_Wait_For_Ready() {
char busy;
PARALLEL_BUSY_TRIS = 1;
PARALLEL_RS_LAT = 0;
PARALLEL_RW_LAT = 1;
do {
NHD_Pulse_Enable();
Nop();
busy = PARALLEL_BUSY_PORT;
NHD_Pulse_Enable();
} while (busy);
PARALLEL_BUSY_TRIS = 0;
PARALLEL_RW_LAT = 0;
}
 
void NHD_Write_String(const rom char *fmt, ...) {
unsigned char i, len;
unsigned char buffer[NHD_STRING_BUFFER_SIZE];
 
// Parse and create string
va_list args;
va_start(args, fmt);
vsprintf((char *) buffer, fmt, args);
va_end(args);
len = strlen((char *) buffer);
 
// Make sure string to insert fits in buffer, truncate if necessary
if (len > NHD_STRING_BUFFER_SIZE)
len = NHD_STRING_BUFFER_SIZE;
 
// Print buffer to string
for (i = 0; i < len; i++) {
NHD_Send_Data(buffer[i]);
}
}
/PIC Projects/PIC_27J13/oled_NHD-0216KZW-AB5.h
0,0 → 1,78
#ifndef OLED_NHD_0216KZW_AB5_H
#define OLED_NHD_0216KZW_AB5_H
 
#define NHD_STRING_BUFFER_SIZE 64
 
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x28
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
 
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
 
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
 
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
 
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_JAPANESE 0x00
#define LCD_EUROPEAN_I 0x01
#define LCD_RUSSIAN 0x02
#define LCD_EUROPEAN_II 0x03
 
typedef struct __OLED_CHAR_DATA {
unsigned char display_function;
unsigned char display_control;
unsigned char display_mode;
unsigned char current_line;
unsigned char num_lines;
} OLED_CHAR_DATA;
 
void NHD_Init(void);
void NHD_Begin(char cols, char rows);
void NHD_Clear(void);
void NHD_Home(void);
void NHD_Display(char option);
void NHD_Blink(char option);
void NHD_Cursor(char option);
void NHD_Autoscroll(char option);
void NHD_Scroll_Display_Left(void);
void NHD_Scroll_Display_Right(void);
void NHD_Left_To_Rigtht(void);
void NHD_Right_To_Left(void);
 
void NHD_Create_Char(unsigned char location, unsigned char *charmap);
void NHD_Set_Cursor(unsigned char col, unsigned char row);
 
void NHD_Send_Data(unsigned char value);
void NHD_Send_Command(unsigned char value);
 
void NHD_Pulse_Enable(void);
void NHD_Write_4_Bits(unsigned char value);
void NHD_Wait_For_Ready(void);
 
void NHD_Write_String(const rom char *fmt, ...);
 
#endif /* OLED_NHD_0216KZW_AB5_H */
 
/PIC Projects/PIC_27J13/oled_ssd1306.c
0,0 → 1,825
#include "defines.h"
#include "oled_ssd1306.h"
#include "spi.h"
#include "glcdfont.c"
#include <delays.h>
#include <string.h>
#include <stdio.h>
 
static SSD1306_DATA ssd1306_data;
static SSD1306_DATA *ssd1306_data_p = &ssd1306_data;
 
#pragma idata LCD_BUFFER
// 512 (128x32) or 1024 (128x64) bytes allocated for LCD buffer
// See linker file for details
static unsigned char LCD_Buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8,
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80,
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF,
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF,
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F,
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00,
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F,
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00,
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E,
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC,
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06,
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8,
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C,
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F,
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07,
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#endif
};
#pragma idata
 
int SSD1306_Abs(int i) {
if (i < 0)
return -i;
else
return i;
}
 
void SSD1306_Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
 
void SSD1306_Init() {
ssd1306_data_p->_width = ssd1306_data_p->WIDTH = SSD1306_LCDWIDTH;
ssd1306_data_p->_height = ssd1306_data_p->HEIGHT = SSD1306_LCDHEIGHT;
ssd1306_data_p->rotation = 0;
ssd1306_data_p->cursor_x = ssd1306_data_p->cursor_y = 0;
ssd1306_data_p->textsize = 1;
ssd1306_data_p->textcolor = SSD1306_WHITE;
ssd1306_data_p->textbgcolor = SSD1306_BLACK;
ssd1306_data_p->wrap = 1;
}
 
void SSD1306_Begin(unsigned char vccstate) {
// Toggle reset pin
SPI_RESET_LAT = 0;
Delay10KTCYx(1);
SPI_RESET_LAT = 1;
 
#if defined SSD1306_128_32
// Init sequence for 128x32 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x1F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x02);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
SSD1306_Command(0x8F);
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
#if defined SSD1306_128_64
// Init sequence for 128x64 OLED module
SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
SSD1306_Command(0x80); // The suggested ratio 0x80
SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
SSD1306_Command(0x3F);
SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
SSD1306_Command(0x0); // No offset
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x10);
} else {
SSD1306_Command(0x14);
}
SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
SSD1306_Command(0x00); // 0x0 act like ks0108
SSD1306_Command(SSD1306_SEGREMAP | 0x1);
SSD1306_Command(SSD1306_COMSCANDEC);
SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
SSD1306_Command(0x12);
SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x9F);
} else {
SSD1306_Command(0xCF);
}
SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
if (vccstate == SSD1306_EXTERNALVCC) {
SSD1306_Command(0x22);
} else {
SSD1306_Command(0xF1);
}
SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
SSD1306_Command(0x40);
SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
#endif
 
SSD1306_Command(SSD1306_DISPLAYON); // Turn on OLED panel
}
 
void SSD1306_Command(unsigned char cmd) {
unsigned char c = cmd;
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(&c, 1);
}
 
void SSD1306_Data(unsigned char data) {
unsigned char c = data;
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(&c, 1);
}
 
void SSD1306_Clear_Display() {
memset(LCD_Buffer, 0, (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8));
}
 
void SSD1306_Invert_Display(unsigned char c) {
if (c) {
SSD1306_Command(SSD1306_INVERTDISPLAY);
} else {
SSD1306_Command((SSD1306_NORMALDISPLAY));
}
}
 
void SSD1306_Display() {
unsigned int i;
unsigned char c = 0;
 
SSD1306_Command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
SSD1306_Command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // line #0
 
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(LCD_Buffer, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
 
// if (SSD1306_LCDHEIGHT == 32) {
// SPI2_Write_Repeat(0, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
// }
}
 
void SSD1306_Draw_Pixel(int x, int y, unsigned int color) {
if ((x < 0) || (x >= ssd1306_data_p->_width) || (y < 0) || (y >= ssd1306_data_p->_height))
return;
 
// check rotation, move pixel around if necessary
switch (ssd1306_data_p->rotation) {
case 1:
SSD1306_Swap(&x, &y);
x = SSD1306_LCDWIDTH - x - 1;
break;
case 2:
x = SSD1306_LCDWIDTH - x - 1;
y = SSD1306_LCDHEIGHT - y - 1;
break;
case 3:
SSD1306_Swap(&x, &y);
y = SSD1306_LCDHEIGHT - y - 1;
break;
}
 
// x is which column
if (color == SSD1306_WHITE)
LCD_Buffer[x + (y / 8) * SSD1306_LCDWIDTH] |= 1<<(y % 8);
else
LCD_Buffer[x + (y / 8) * SSD1306_LCDWIDTH] &= ~(1<<(y % 8));
}
 
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color) {
int dx, dy, err, ystep;
int steep = SSD1306_Abs(y1 - y0) > SSD1306_Abs(x1 - x0);
if (steep) {
SSD1306_Swap(&x0, &y0);
SSD1306_Swap(&x1, &y1);
}
 
if (x0 > x1) {
SSD1306_Swap(&x0, &x1);
SSD1306_Swap(&y0, &y1);
}
 
dx = x1 - x0;
dy = SSD1306_Abs(y1 - y0);
 
err = dx / 2;
 
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
 
for (; x0 <= x1; x0++) {
 
if (steep) {
SSD1306_Draw_Pixel(y0, x0, color);
} else {
SSD1306_Draw_Pixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
 
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color) {
SSD1306_Draw_Line(x, y, x, y + h - 1, color);
}
 
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color) {
SSD1306_Draw_Line(x, y, x + w - 1, y, color);
}
 
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color) {
SSD1306_Draw_Fast_HLine(x, y, w, color);
SSD1306_Draw_Fast_HLine(x, y + h, w, color);
SSD1306_Draw_Fast_VLine(x, y, h, color);
SSD1306_Draw_Fast_VLine(x + w, y, h, color);
}
 
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color) {
int i;
for (i = x; i < x + w; i++) {
SSD1306_Draw_Fast_VLine(i, y, h, color);
}
}
 
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
SSD1306_Draw_Pixel(x0, y0 + r, color);
SSD1306_Draw_Pixel(x0, y0 - r, color);
SSD1306_Draw_Pixel(x0 + r, y0, color);
SSD1306_Draw_Pixel(x0 - r, y0, color);
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
}
}
 
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, unsigned char cornername, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
}
}
}
 
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color) {
SSD1306_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
SSD1306_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
}
 
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, unsigned char cornername, int delta, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
if (cornername & 0x1) {
SSD1306_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
SSD1306_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
SSD1306_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
 
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
SSD1306_Draw_Line(x0, y0, x1, y1, color);
SSD1306_Draw_Line(x1, y1, x2, y2, color);
SSD1306_Draw_Line(x2, y2, x0, y0, color);
}
 
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
int a, b, y, last;
int dx01 = x1 - x0;
int dy01 = y1 - y0;
int dx02 = x2 - x0;
int dy02 = y2 - y0;
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int sa = 0;
int sb = 0;
 
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
if (y1 > y2) {
SSD1306_Swap(&y2, &y1);
SSD1306_Swap(&x2, &x1);
}
if (y0 > y1) {
SSD1306_Swap(&y0, &y1);
SSD1306_Swap(&x0, &x1);
}
 
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
SSD1306_Draw_Fast_HLine(a, y0, b - a + 1, color);
return;
}
 
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
 
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
 
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1306_Swap(&a, &b);
SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
}
}
 
void SSD1306_Draw_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1306_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
SSD1306_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
SSD1306_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
SSD1306_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
 
// draw four corners
SSD1306_Draw_Circle_Helper(x + r, y + r, r, 1, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
SSD1306_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
SSD1306_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
}
 
void SSD1306_Fill_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1306_Fill_Rect(x + r, y, w - 2 * r, h, color);
 
// draw four corners
SSD1306_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
SSD1306_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
 
void SSD1306_Draw_Bitmap(int x, int y, const unsigned char* bitmap, int w, int h, unsigned int color) {
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (bitmap[i + (j / 8) * w] & (j % 8)) {
SSD1306_Draw_Pixel(x + i, y + j, color);
}
}
}
}
 
void SSD1306_Draw_Char(int x, int y, unsigned char c, unsigned int color, unsigned int bg, unsigned char size) {
int i, j;
unsigned int line;
 
if ((x >= ssd1306_data_p->_width) || // Clip right
(y >= ssd1306_data_p->_height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
 
for (i = 0; i < 6; i++) {
if (i == 5)
line = 0x0;
else
line = font[(c * 5) + i];
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) {// default size
SSD1306_Draw_Pixel(x + i, y + j, color);
} else { // big size
SSD1306_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
}
} else if (bg != color) {
if (size == 1) { // default size
SSD1306_Draw_Pixel(x + i, y + j, bg);
} else { // big size
SSD1306_Fill_Rect(x + i*size, y + j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
 
void SSD1306_Write(unsigned char c) {
if (c == '\n' || c == '\r') {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
// } else if (c == '\r') {
// // skip em
} else {
SSD1306_Draw_Char(ssd1306_data_p->cursor_x, ssd1306_data_p->cursor_y, c, ssd1306_data_p->textcolor, ssd1306_data_p->textbgcolor, ssd1306_data_p->textsize);
ssd1306_data_p->cursor_x += ssd1306_data_p->textsize * 6;
if (ssd1306_data_p->wrap && (ssd1306_data_p->cursor_x > (ssd1306_data_p->_width - ssd1306_data_p->textsize * 6))) {
ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
ssd1306_data_p->cursor_x = 0;
}
}
}
 
void SSD1306_Write_String(const rom char *fmt, ...) {
unsigned char i, len;
unsigned char buffer[SSD1306_STRING_BUFFER_SIZE];
// Parse and create string
va_list args;
va_start(args, fmt);
vsprintf((char *) buffer, fmt, args);
va_end(args);
len = strlen((char *) buffer);
 
// Make sure string to insert fits in buffer, truncate if necessary
if (len > SSD1306_STRING_BUFFER_SIZE)
len = SSD1306_STRING_BUFFER_SIZE;
 
// Print buffer to string
for (i = 0; i < len; i++) {
SSD1306_Write(buffer[i]);
}
}
 
//void SSD1306_Append_String(const rom char *fmt, ...) {
// unsigned char i, len;
// unsigned char buffer[SSD1306_STRING_BUFFER_SIZE];
//
// // Parse and create string
// va_list args;
// va_start(args, fmt);
// vsprintf((char *) buffer, fmt, args);
// va_end(args);
//
// // Make sure string to insert fits in buffer, truncate if necessary
// len = strlen((char *) buffer);
//
// if (len == 1) { // This will only occur on "\n"
// // Do nothing?
// return;
// }
//
// if (len > SSD1306_STRING_BUFFER_SIZE)
// len = SSD1306_STRING_BUFFER_SIZE;
//
// // Omit the newline if string fill entire line
// if (((len - 1)%(ssd1306_data_p->_width / 6)) == 0) { // 16 or 10
// len -= 1;
// }
//
// // Shift everything right and insert string at beginning
// for (i = 127; i > len - 1; i--) {
// ssd1306_data_p->lcd_buffer[i] = ssd1306_data_p->lcd_buffer[i - len];
// }
// memcpy((char *)ssd1306_data_p->lcd_buffer, (const char *) buffer, len);
//
// // Print full buffer to screen
// SSD1306_Clear_Display();
// SSD1306_Display();
//
// SSD1306_Set_Cursor(0,0);
// for (i = 0; i < SSD1306_LCD_BUFFER_SIZE-1; i++) {
// SSD1306_Write(ssd1306_data_p->lcd_buffer[i]);
// }
//}
 
void SSD1306_Set_Cursor(int x, int y) {
ssd1306_data_p->cursor_x = x;
ssd1306_data_p->cursor_y = y;
}
 
void SSD1306_Set_Text_Color(unsigned int c) {
// for 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = c;
}
 
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg) {
ssd1306_data_p->textcolor = c;
ssd1306_data_p->textbgcolor = bg;
}
 
void SSD1306_Set_Text_Size(unsigned char s) {
ssd1306_data_p->textsize = (s > 0) ? s : 1;
}
 
void SSD1306_Set_Text_Wrap(unsigned char w) {
ssd1306_data_p->wrap = w;
}
 
void SSD1306_Set_Rotation(unsigned char x) {
x %= 4; // cant be higher than 3
ssd1306_data_p->rotation = x;
switch (x) {
case 0:
case 2:
ssd1306_data_p->_width = ssd1306_data_p->WIDTH;
ssd1306_data_p->_height = ssd1306_data_p->HEIGHT;
break;
case 1:
case 3:
ssd1306_data_p->_width = ssd1306_data_p->HEIGHT;
ssd1306_data_p->_height = ssd1306_data_p->WIDTH;
break;
}
}
 
 
 
void SSD1306_Test_DrawChar() {
unsigned char i;
SSD1306_Set_Text_Size(1);
SSD1306_Set_Text_Color(SSD1306_WHITE);
SSD1306_Set_Cursor(0, 0);
 
for (i = 0; i < 168; i++) {
if (i == '\n') continue;
SSD1306_Write(i);
// if ((i > 0) && (i % 21 == 0))
// SSD1306_write('\n');
}
SSD1306_Display();
}
 
void SSD1306_Test_DrawCircle() {
int i;
for (i = 0; i < ssd1306_data_p->_height; i += 2) {
SSD1306_Draw_Circle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2, i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRect(void) {
int i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 2) {
SSD1306_Draw_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRect(void) {
unsigned char color = 1;
int i;
for (i = 0; i < ssd1306_data_p->_height / 2; i += 3) {
// alternate colors
SSD1306_Fill_Rect(i, i, ssd1306_data_p->_width - i * 2, ssd1306_data_p->_height - i * 2, color % 2);
SSD1306_Display();
color++;
}
}
 
void SSD1306_Test_DrawTriangle(void) {
int i;
int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = 0; i < min / 2; i += 5) {
SSD1306_Draw_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillTriangle(void) {
unsigned char color = SSD1306_WHITE;
int i;
int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
for (i = min / 2; i > 0; i -= 5) {
SSD1306_Fill_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawRoundRect(void) {
int i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Draw_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, SSD1306_WHITE);
SSD1306_Display();
}
}
 
void SSD1306_Test_FillRoundRect(void) {
unsigned char color = SSD1306_WHITE;
int i;
for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
SSD1306_Fill_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, color);
if (color == SSD1306_WHITE) color = SSD1306_BLACK;
else color = SSD1306_WHITE;
SSD1306_Display();
}
}
 
void SSD1306_Test_DrawLine(void) {
int i;
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(0, 0, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = ssd1306_data_p->_width - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
SSD1306_Display();
}
for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
 
SSD1306_Clear_Display();
for (i = 0; i < ssd1306_data_p->_height; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, 0, i, SSD1306_WHITE);
SSD1306_Display();
}
for (i = 0; i < ssd1306_data_p->_width; i += 4) {
SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
SSD1306_Display();
}
Delay10KTCYx(255);
}
/PIC Projects/PIC_27J13/adc.c
0,0 → 1,53
#include "defines.h"
#include "adc.h"
 
static ADC_DATA adc_data;
static ADC_DATA *adc_data_p = &adc_data;
 
void ADC_Init(unsigned char TAD, unsigned char FOSC) {
ADC_AN0_TRIS = 1;
ADC_AN1_TRIS = 1;
ADC_AN2_TRIS = 1;
 
adc_data_p->last_channel = 0;
adc_data_p->result = 0;
 
ADCON0bits.VCFG1 = 0; // VRef- = AVss
ADCON0bits.VCFG0 = 1; // VRef+ != AVdd
ADCON1bits.ADFM = 1; // Right justified result
ADCON1bits.ADCAL = 1; // Calibrate A/D
ADCON1bits.ACQT = TAD;
ADCON1bits.ADCS = FOSC;
ADCON0bits.ADON = 1; // Enable A/D module
 
ADCON0bits.GO_DONE = 1; // Start calibration
while (ADCON0bits.GO_DONE); // Wait for calibration to finish
PIR1bits.ADIF = 0; // Clear the IF flag
ADCON1bits.ADCAL = 0; // Normal A/D operation
 
PIE1bits.ADIE = 1; // Enable A/D interrupt
 
}
 
void ADC_Start(unsigned char channel) {
adc_data_p->last_channel = channel;
ADCON0bits.CHS = channel; // Set A/D channel
ADCON0bits.GO_DONE = 1; // Start A/D conversion
}
 
void ADC_Stop() {
ADCON0bits.ADON = 0; // Disable A/D module
}
 
void ADC_Interrupt_Handler() {
adc_data_p->result = ADRES;
}
 
char ADC_Get_Result(unsigned int* ret) {
if (ADCON0bits.GO_DONE) {
return 0;
} else {
*ret = adc_data_p->result;
return 1;
}
}
/PIC Projects/PIC_27J13/i2c.c
0,0 → 1,554
#include "defines.h"
#include "i2c.h"
 
static I2C_DATA i2c_data;
static I2C_DATA *i2c_data_p = &i2c_data;
 
// Set up the data structures for the i2c code
// Should be called once before any i2c routines are called
void I2C_Init() {
i2c_data_p->buffer_in_len = 0;
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
i2c_data_p->buffer_out_ind = 0;
i2c_data_p->buffer_out_len = 0;
i2c_data_p->operating_mode = 0;
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = 0;
 
i2c_data_p->slave_in_last_byte = 0;
i2c_data_p->slave_sending_data = 0;
 
i2c_data_p->master_dest_addr = 0;
i2c_data_p->master_status = I2C_MASTER_IDLE;
// Enable I2C interrupt
PIE1bits.SSPIE = 1;
}
 
// Setup the PIC to operate as a master.
void I2C_Configure_Master(unsigned char speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0x8; // I2C Master Mode
if (speed) {
SSPADD = 0x74; // Operate at 100KHz (48MHz)
} else {
SSPADD = 0x1A; // Operate at 400KHz (48MHz)
}
SSPSTATbits.SMP = 1; // Disable Slew Rate Control
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C_Master_Send(unsigned char address, unsigned char length, unsigned char *msg) {
unsigned char i;
if (length == 0)
return;
// Copy message to send into buffer and save length/address
for (i = 0; i < length; i++) {
i2c_data_p->buffer_in[i] = msg[i];
}
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_SEND;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C_Master_Recv(unsigned char address, unsigned char length) {
if (length == 0)
return;
 
// Save length and address to get data from
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RECV;
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Writes msg to address then reads length number of bytes from address
void I2C_Master_Restart(unsigned char address, unsigned char msg, unsigned char length) {
unsigned char c;
if (length == 0) {
c = msg;
I2C_Master_Send(address, 1, &c);
return;
}
 
// Save length and address to get data from
i2c_data_p->buffer_in[0] = msg;
i2c_data_p->buffer_in_len = length;
i2c_data_p->master_dest_addr = address;
i2c_data_p->buffer_in_read_ind = 0;
i2c_data_p->buffer_in_write_ind = 0;
 
// Change status to 'next' operation
i2c_data_p->operating_state = I2C_SEND_ADDR;
i2c_data_p->master_status = I2C_MASTER_RESTART;
 
// Generate start condition
SSPCON2bits.SEN = 1;
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C_Configure_Slave(unsigned char addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
I2C_CLK_TRIS = 1;
I2C_DAT_TRIS = 1;
 
SSPADD = addr << 1; // Set the slave address
 
SSPSTAT = 0x0;
SSPCON1 = 0x0;
SSPCON2 = 0x0;
SSPCON1bits.SSPM = 0xE; // Enable Slave 7-bit w/ start/stop interrupts
SSPSTATbits.SMP = 1; // Slew Off
SSPCON2bits.SEN = 1; // Enable clock-stretching
SSPCON1bits.SSPEN = 1; // Enable MSSP Module
}
 
void I2C_Interrupt_Handler() {
// Call interrupt depending on which mode we are operating in
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
I2C_Interrupt_Master();
} else if (i2c_data_p->operating_mode == I2C_MODE_SLAVE) {
I2C_Interrupt_Slave();
}
}
 
// An internal subroutine used in the master version of the i2c_interrupt_handler
void I2C_Interrupt_Master() {
// If we are in the middle of sending data
if (i2c_data_p->master_status == I2C_MASTER_SEND) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send next byte of data
if (i2c_data_p->buffer_in_read_ind < i2c_data_p->buffer_in_len) {
SSPBUF = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i2c_data_p->buffer_in_read_ind++;
} else {
// If no more data is to be sent, send stop bit
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_OK;
}
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
}
// If we are in the middle of receiving data
} else if (i2c_data_p->master_status == I2C_MASTER_RECV) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send address with write bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: handle i2c buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
} else if (i2c_data_p->master_status == I2C_MASTER_RESTART) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
break;
case I2C_SEND_ADDR:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_SEND;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x0;
break;
case I2C_CHECK_ACK_SEND:
// Check if ACK is received or not
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, send first byte of data
SSPBUF = i2c_data_p->buffer_in[0];
i2c_data_p->operating_state = I2C_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_CHECK_ACK_RESTART:
if (!SSPCON2bits.ACKSTAT) {
SSPCON2bits.RSEN = 1;
i2c_data_p->operating_state = I2C_SEND_ADDR_2;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_SEND_FAIL;
}
break;
case I2C_SEND_ADDR_2:
// Send the address with read bit set
i2c_data_p->operating_state = I2C_CHECK_ACK_RECV;
SSPBUF = (i2c_data_p->master_dest_addr << 1) | 0x1;
break;
case I2C_CHECK_ACK_RECV:
// Check if ACK is received
if (!SSPCON2bits.ACKSTAT) {
// If an ACK is received, set module to receive 1 byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
} else {
// If a NACK is received, stop transmission and send error
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_FAIL;
}
break;
case I2C_RCV_DATA:
// On receive, save byte into buffer
// TODO: handle i2c buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = SSPBUF;
i2c_data_p->buffer_in_write_ind++;
if (i2c_data_p->buffer_in_write_ind < i2c_data_p->buffer_in_len) {
// If we still need to read, send an ACK to the slave
i2c_data_p->operating_state = I2C_REQ_DATA;
SSPCON2bits.ACKDT = 0; // ACK
SSPCON2bits.ACKEN = 1;
} else {
// If we are done reading, send an NACK to the slave
i2c_data_p->operating_state = I2C_SEND_STOP;
SSPCON2bits.ACKDT = 1; // NACK
SSPCON2bits.ACKEN = 1;
}
break;
case I2C_REQ_DATA:
// Set module to receive one byte of data
i2c_data_p->operating_state = I2C_RCV_DATA;
SSPCON2bits.RCEN = 1;
break;
case I2C_SEND_STOP:
// Send the stop bit and copy message to send to Main()
i2c_data_p->operating_state = I2C_IDLE;
SSPCON2bits.PEN = 1;
i2c_data_p->master_status = I2C_MASTER_IDLE;
i2c_data_p->return_status = I2C_RECV_OK;
break;
}
}
}
 
void I2C_Interrupt_Slave() {
unsigned char received_data;
unsigned char data_read_from_buffer = 0;
unsigned char data_written_to_buffer = 0;
unsigned char overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSPCON1bits.SSPOV == 1) {
DBG_PRINT_I2C("I2C: (ERROR) overflow detected\r\n");
SSPCON1bits.SSPOV = 0;
// We failed to read the buffer in time, so we know we
// can't properly receive this message, just put us in the
// a state where we are looking for a new message
i2c_data_p->operating_state = I2C_IDLE;
overrun_error = 1;
i2c_data_p->return_status = I2C_ERR_OVERRUN;
}
 
// Read SPPxBUF if it is full
if (SSPSTATbits.BF == 1) {
received_data = SSPBUF;
// DBG_PRINT_I2C("I2C: data read from buffer: %x\r\n", SSPBUF);
data_read_from_buffer = 1;
}
 
if (!overrun_error) {
switch (i2c_data_p->operating_state) {
case I2C_IDLE:
{
// Ignore anything except a start
if (SSPSTATbits.S == 1) {
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->operating_state = I2C_STARTED;
// if (data_read_from_buffer) {
// if (SSPSTATbits.D_A == 1) {
// DBG_PRINT_I2C("I2C Start: (ERROR) no address recieved\r\n");
// // This is bad because we got data and we wanted an address
// i2c_data_p->operating_state = I2C_IDLE;
// i2c_data_p->return_status = I2C_ERR_NOADDR;
// } else {
// // Determine if we are sending or receiving data
// if (SSPSTATbits.R_W == 1) {
// i2c_data_p->operating_state = I2C_SEND_DATA;
// } else {
// i2c_data_p->operating_state = I2C_RCV_DATA;
// }
// }
// } else {
// i2c_data_p->operating_state = I2C_STARTED;
// }
}
break;
}
case I2C_STARTED:
{
// In this case, we expect either an address or a stop bit
if (SSPSTATbits.P == 1) {
// Return to idle mode
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 0) {
// Address received
if (SSPSTATbits.R_W == 0) {
// Slave write mode
i2c_data_p->operating_state = I2C_RCV_DATA;
} else {
// Slave read mode
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
}
} else {
DBG_PRINT_I2C("I2C: (ERROR) no data recieved\r\n");
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
break;
}
send:
case I2C_SEND_DATA:
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C_Process_Send(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSPBUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
i2c_data_p->slave_sending_data = 1;
data_written_to_buffer = 1;
} else {
// Unknown request
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
} else {
// Sending remaining data back to master
if (i2c_data_p->buffer_out_ind < i2c_data_p->buffer_out_len) {
SSPBUF = i2c_data_p->buffer_out[i2c_data_p->buffer_out_ind];
i2c_data_p->buffer_out_ind++;
data_written_to_buffer = 1;
} else {
// Nothing left to send
i2c_data_p->slave_sending_data = 0;
i2c_data_p->operating_state = I2C_IDLE;
}
}
break;
}
case I2C_RCV_DATA:
{
// We expect either data or a stop bit or a (if a restart, an addr)
if (SSPSTATbits.P == 1) {
// Stop bit detected, we need to check to see if we also read data
if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 1) {
// Data received with stop bit
// TODO: handle i2c buffer overflow
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
DBG_PRINT_I2C("I2C: (ERROR) no data recieved\r\n");
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_IDLE;
} else if (data_read_from_buffer) {
if (SSPSTATbits.D_A == 1) {
// Data received
i2c_data_p->buffer_in[i2c_data_p->buffer_in_write_ind] = received_data;
if (i2c_data_p->buffer_in_write_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_write_ind = 0;
} else {
i2c_data_p->buffer_in_write_ind++;
}
i2c_data_p->buffer_in_len_tmp++;
// Save the last byte received
i2c_data_p->slave_in_last_byte = received_data;
i2c_data_p->return_status = I2C_DATA_AVAL;
} else {
// Restart bit detected
if (SSPSTATbits.R_W == 1) {
i2c_data_p->buffer_in_len += i2c_data_p->buffer_in_len_tmp;
i2c_data_p->operating_state = I2C_SEND_DATA;
// Process the first byte immediatly if sending data
goto send;
} else {
// Bad to recv an address again, we aren't ready
DBG_PRINT_I2C("I2C: (ERROR) no data recieved\r\n");
i2c_data_p->operating_state = I2C_IDLE;
i2c_data_p->return_status = I2C_ERR_NODATA;
}
}
}
break;
}
}
}
 
// Release the clock stretching bit (if we should)
if (data_read_from_buffer || data_written_to_buffer) {
// Release the clock
if (SSPCON1bits.CKP == 0) {
SSPCON1bits.CKP = 1;
}
}
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
unsigned char I2C_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
} else if (i2c_data_p->operating_mode = I2C_MODE_SLAVE) {
if (i2c_data_p->operating_state != I2C_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
} else {
return i2c_data_p->return_status;
}
}
}
 
unsigned char I2C_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
unsigned char I2C_Read_Buffer(char *buffer) {
unsigned char i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
if (i2c_data_p->buffer_in_read_ind == MAXI2CBUF-1) {
i2c_data_p->buffer_in_read_ind = 0;
} else {
i2c_data_p->buffer_in_read_ind++;
}
i2c_data_p->buffer_in_len--;
}
return i;
}
 
/* Put data to be returned here */
unsigned char I2C_Process_Send(unsigned char c) {
unsigned char ret = 0;
switch (c) {
case 0xAA:
i2c_data_p->buffer_out[0] = 'A';
i2c_data_p->buffer_out_len = 1;
ret = 1;
break;
case 0xBB:
i2c_data_p->buffer_out[0] = '1';
i2c_data_p->buffer_out[1] = '2';
i2c_data_p->buffer_out_len = 2;
ret = 1;
break;
}
return ret;
}
/PIC Projects/PIC_27J13/oled_ssd1331.c
0,0 → 1,895
#include "defines.h"
#include "oled_ssd1331.h"
#include "spi.h"
#include "string.h"
#include "glcdfont.c"
#include <delays.h>
#include <string.h>
#include <stdio.h>
 
static SSD1331_DATA ssd1331_data;
static SSD1331_DATA *ssd1331_data_p = &ssd1331_data;
 
int SSD1331_Abs(int i) {
if (i < 0)
return -i;
else
return i;
}
 
void SSD1331_Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
 
void SSD1331_Init() {
ssd1331_data_p->_width = ssd1331_data_p->WIDTH = SSD1331_LCDWIDTH;
ssd1331_data_p->_height = ssd1331_data_p->HEIGHT = SSD1331_LCDHEIGHT;
ssd1331_data_p->rotation = 0;
ssd1331_data_p->cursor_x = ssd1331_data_p->cursor_y = 0;
ssd1331_data_p->textsize = 1;
ssd1331_data_p->textcolor = ssd1331_data_p->textbgcolor = 0xFFFF;
ssd1331_data_p->wrap = 1;
}
 
void SSD1331_Begin() {
unsigned char buffer[37];
 
// Toggle reset pin
SPI_RESET_LAT = 0;
Delay10KTCYx(1);
SPI_RESET_LAT = 1;
 
// Initialization Sequence
buffer[0] = SSD1331_CMD_DISPLAYOFF; // 0xAE
buffer[1] = SSD1331_CMD_SETREMAP; // 0xA0
#if defined SSD1331_COLORORDER_RGB
buffer[2] = 0x72; // RGB Color
#else
buffer[2] = 0x76; // BGR Color
#endif
buffer[3] = SSD1331_CMD_STARTLINE; // 0xA1
buffer[4] = 0x0;
buffer[5] = SSD1331_CMD_DISPLAYOFFSET; // 0xA2
buffer[6] = 0x0;
buffer[7] = SSD1331_CMD_NORMALDISPLAY; // 0xA4
buffer[8] = SSD1331_CMD_SETMULTIPLEX; // 0xA8
buffer[9] = 0x3F; // 0x3F 1/64 duty
buffer[10] = SSD1331_CMD_SETMASTER; // 0xAD
buffer[11] = 0x8E;
buffer[12] = SSD1331_CMD_POWERMODE; // 0xB0
buffer[13] = 0x0B;
buffer[14] = SSD1331_CMD_PRECHARGE; // 0xB1
buffer[15] = 0x31;
buffer[16] = SSD1331_CMD_CLOCKDIV; // 0xB3
buffer[17] = 0xF0; // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
buffer[18] = SSD1331_CMD_PRECHARGEA; // 0x8A
buffer[19] = 0x64;
buffer[20] = SSD1331_CMD_PRECHARGEB; // 0x8B
buffer[21] = 0x78;
buffer[22] = SSD1331_CMD_PRECHARGEA; // 0x8C
buffer[23] = 0x64;
buffer[24] = SSD1331_CMD_PRECHARGELEVEL; // 0xBB
buffer[25] = 0x3A;
buffer[26] = SSD1331_CMD_VCOMH; // 0xBE
buffer[27] = 0x3E;
buffer[28] = SSD1331_CMD_MASTERCURRENT; // 0x87
buffer[29] = 0x06;
buffer[30] = SSD1331_CMD_CONTRASTA; // 0x81
buffer[31] = 0x91;
buffer[32] = SSD1331_CMD_CONTRASTB; // 0x82
buffer[33] = 0x50;
buffer[34] = SSD1331_CMD_CONTRASTC; // 0x83
buffer[35] = 0x7D;
buffer[36] = SSD1331_CMD_DISPLAYON; //--turn on oled panel
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 37);
}
 
void SSD1331_GoTo(int x, int y) {
unsigned char buffer[6];
if ((x >= SSD1331_LCDWIDTH) || (y >= SSD1331_LCDHEIGHT)) return;
 
// set x and y coordinate
buffer[0] = (SSD1331_CMD_SETCOLUMN);
buffer[1] = (x); // Start x address
buffer[2] = (SSD1331_LCDWIDTH - 1); // End x address
 
buffer[3] = (SSD1331_CMD_SETROW);
buffer[4] = (y); // Start y address
buffer[5] = (SSD1331_LCDHEIGHT - 1); // End y address
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 6);
}
 
void SSD1331_Command(unsigned char cmd) {
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(&cmd, 1);
}
 
void SSD1331_Data(unsigned char data) {
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(&data, 1);
}
 
void SSD1331_Clear_Display() {
unsigned char buffer[5];
 
buffer[0] = SSD1331_CMD_CLEARWINDOW;
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = SSD1331_LCDWIDTH-1;
buffer[4] = SSD1331_LCDHEIGHT-1;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 5);
 
Delay1KTCYx(4);
}
 
void SSD1331_Draw_Pixel(int x, int y, unsigned int color) {
unsigned char buffer[2];
buffer[0] = color >> 8;
buffer[1] = color;
if ((x < 0) || (x >= ssd1331_data_p->_width) || (y < 0) || (y >= ssd1331_data_p->_height)) return;
 
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 1:
SSD1331_Swap(&x, &y);
x = SSD1331_LCDWIDTH - x - 1;
break;
case 2:
x = SSD1331_LCDWIDTH - x - 1;
y = SSD1331_LCDHEIGHT - y - 1;
break;
case 3:
SSD1331_Swap(&x, &y);
y = SSD1331_LCDHEIGHT - y - 1;
break;
}
 
SSD1331_GoTo(x, y);
 
// setup for data
SPI_DC_SELECT_LAT = 1; // D/C high (data)
 
SPI2_Write(buffer, 2);
}
 
void SSD1331_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color) {
unsigned char buffer[8];
 
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 1:
SSD1331_Swap(&x0, &y0);
SSD1331_Swap(&x1, &y1);
x0 = SSD1331_LCDWIDTH - x0 - 1;
x1 = SSD1331_LCDWIDTH - x1 - 1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - x0 - 1;
y0 = SSD1331_LCDHEIGHT - y0 - 1;
x1 = SSD1331_LCDWIDTH - x1 - 1;
y1 = SSD1331_LCDHEIGHT - y1 - 1;
break;
case 3:
SSD1331_Swap(&x0, &y0);
SSD1331_Swap(&x1, &y1);
y0 = SSD1331_LCDHEIGHT - y0 - 1;
y1 = SSD1331_LCDHEIGHT - y1 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_DRAWLINE;
buffer[1] = x0;
buffer[2] = y0;
buffer[3] = x1;
buffer[4] = y1;
buffer[5] = (color >> 11) << 1;
buffer[6] = (color >> 5) & 0x3F;
buffer[7] = (color << 1) & 0x3F;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 8);
}
 
void SSD1331_Draw_Fast_VLine(int x, int y, int h, unsigned int color) {
SSD1331_Draw_Line(x, y, x, y + h - 1, color);
}
 
void SSD1331_Draw_Fast_HLine(int x, int y, int w, unsigned int color) {
SSD1331_Draw_Line(x, y, x + w - 1, y, color);
}
 
void SSD1331_Draw_Rect(int tx0, int ty0, int tx1, int ty1, unsigned int color) {
unsigned char buffer[13];
int x0,y0,x1,y1;
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 0:
x0 = tx0;
y0 = ty0;
x1 = tx1;
y1 = ty1;
break;
case 1:
x0 = SSD1331_LCDWIDTH - ty1 - 1;
y0 = tx0;
x1 = SSD1331_LCDWIDTH - ty0 - 1;
y1 = tx1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - tx1 - 1;
y0 = SSD1331_LCDHEIGHT - ty1 - 1;
x1 = SSD1331_LCDWIDTH - tx0 - 1;
y1 = SSD1331_LCDHEIGHT - ty0 - 1;
break;
case 3:
x0 = ty0;
y0 = SSD1331_LCDHEIGHT - tx1 - 1;
x1 = ty1;
y1 = SSD1331_LCDHEIGHT - tx0 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_FILL;
buffer[1] = 0;
buffer[2] = SSD1331_CMD_DRAWRECT;
buffer[3] = x0;
buffer[4] = y0;
buffer[5] = x1;
buffer[6] = y1;
buffer[7] = (color >> 11) << 1;
buffer[8] = (color >> 5) & 0x3F;
buffer[9] = (color << 1) & 0x3F;
buffer[10] = 0;
buffer[11] = 0;
buffer[12] = 0;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 13);
}
 
void SSD1331_Fill_Rect(int tx0, int ty0, int tx1, int ty1, unsigned int color) {
unsigned char buffer[13];
int x0,y0,x1,y1;
// check rotation, move pixel around if necessary
switch (ssd1331_data_p->rotation) {
case 0:
x0 = tx0;
y0 = ty0;
x1 = tx1;
y1 = ty1;
break;
case 1:
x0 = SSD1331_LCDWIDTH - ty1 - 1;
y0 = tx0;
x1 = SSD1331_LCDWIDTH - ty0 - 1;
y1 = tx1;
break;
case 2:
x0 = SSD1331_LCDWIDTH - tx1 - 1;
y0 = SSD1331_LCDHEIGHT - ty1 - 1;
x1 = SSD1331_LCDWIDTH - tx0 - 1;
y1 = SSD1331_LCDHEIGHT - ty0 - 1;
break;
case 3:
x0 = ty0;
y0 = SSD1331_LCDHEIGHT - tx1 - 1;
x1 = ty1;
y1 = SSD1331_LCDHEIGHT - tx0 - 1;
break;
}
 
// Boundary check
if ((y0 >= SSD1331_LCDHEIGHT) && (y1 >= SSD1331_LCDHEIGHT))
return;
if ((x0 >= SSD1331_LCDWIDTH) && (x1 >= SSD1331_LCDWIDTH))
return;
if (x0 >= SSD1331_LCDWIDTH)
x0 = SSD1331_LCDWIDTH - 1;
if (y0 >= SSD1331_LCDHEIGHT)
y0 = SSD1331_LCDHEIGHT - 1;
if (x1 >= SSD1331_LCDWIDTH)
x1 = SSD1331_LCDWIDTH - 1;
if (y1 >= SSD1331_LCDHEIGHT)
y1 = SSD1331_LCDHEIGHT - 1;
if (x0 < 0)
x0 = 0;
if (y0 < 0)
y0 = 0;
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
 
buffer[0] = SSD1331_CMD_FILL;
buffer[1] = 1;
buffer[2] = SSD1331_CMD_DRAWRECT;
buffer[3] = x0;
buffer[4] = y0;
buffer[5] = x1;
buffer[6] = y1;
buffer[7] = (color >> 11) << 1;
buffer[8] = (color >> 5) & 0x3F;
buffer[9] = (color << 1) & 0x3F;
buffer[10] = (color >> 11) << 1;
buffer[11] = (color >> 5) & 0x3F;
buffer[12] = (color << 1) & 0x3F;
 
SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
SPI2_Write(buffer, 13);
 
Delay1KTCYx(4);
}
 
void SSD1331_Draw_Circle(int x0, int y0, int r, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
SSD1331_Draw_Pixel(x0, y0 + r, color);
SSD1331_Draw_Pixel(x0, y0 - r, color);
SSD1331_Draw_Pixel(x0 + r, y0, color);
SSD1331_Draw_Pixel(x0 - r, y0, color);
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
SSD1331_Draw_Pixel(x0 + x, y0 + y, color);
SSD1331_Draw_Pixel(x0 - x, y0 + y, color);
SSD1331_Draw_Pixel(x0 + x, y0 - y, color);
SSD1331_Draw_Pixel(x0 - x, y0 - y, color);
SSD1331_Draw_Pixel(x0 + y, y0 + x, color);
SSD1331_Draw_Pixel(x0 - y, y0 + x, color);
SSD1331_Draw_Pixel(x0 + y, y0 - x, color);
SSD1331_Draw_Pixel(x0 - y, y0 - x, color);
}
}
 
void SSD1331_Draw_Circle_Helper(int x0, int y0, int r, unsigned char cornername, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
SSD1331_Draw_Pixel(x0 + x, y0 + y, color);
SSD1331_Draw_Pixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
SSD1331_Draw_Pixel(x0 + x, y0 - y, color);
SSD1331_Draw_Pixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
SSD1331_Draw_Pixel(x0 - y, y0 + x, color);
SSD1331_Draw_Pixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
SSD1331_Draw_Pixel(x0 - y, y0 - x, color);
SSD1331_Draw_Pixel(x0 - x, y0 - y, color);
}
}
}
 
void SSD1331_Fill_Circle(int x0, int y0, int r, unsigned int color) {
SSD1331_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
SSD1331_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
}
 
void SSD1331_Fill_Circle_Helper(int x0, int y0, int r, unsigned char cornername, int delta, unsigned int color) {
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
 
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
 
if (cornername & 0x1) {
SSD1331_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
SSD1331_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
SSD1331_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
SSD1331_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
void SSD1331_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
SSD1331_Draw_Line(x0, y0, x1, y1, color);
SSD1331_Draw_Line(x1, y1, x2, y2, color);
SSD1331_Draw_Line(x2, y2, x0, y0, color);
}
 
void SSD1331_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
int a, b, y, last;
int dx01 = x1 - x0;
int dy01 = y1 - y0;
int dx02 = x2 - x0;
int dy02 = y2 - y0;
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int sa = 0;
int sb = 0;
 
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
SSD1331_Swap(&y0, &y1);
SSD1331_Swap(&x0, &x1);
}
if (y1 > y2) {
SSD1331_Swap(&y2, &y1);
SSD1331_Swap(&x2, &x1);
}
if (y0 > y1) {
SSD1331_Swap(&y0, &y1);
SSD1331_Swap(&x0, &x1);
}
 
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
SSD1331_Draw_Fast_HLine(a, y0, b - a + 1, color);
return;
}
 
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
 
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1331_Swap(&a, &b);
SSD1331_Draw_Fast_HLine(a, y, b - a + 1, color);
}
 
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) SSD1331_Swap(&a, &b);
SSD1331_Draw_Fast_HLine(a, y, b - a + 1, color);
}
}
 
void SSD1331_Draw_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1331_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
SSD1331_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
SSD1331_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
SSD1331_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
 
// draw four corners
SSD1331_Draw_Circle_Helper(x + r, y + r, r, 1, color);
SSD1331_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
SSD1331_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
SSD1331_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
}
 
void SSD1331_Fill_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
// smarter version
SSD1331_Fill_Rect(x + r, y, w - 2 * r, h, color);
 
// draw four corners
SSD1331_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
SSD1331_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
 
void SSD1331_Draw_Bitmap(int x, int y, const unsigned char* bitmap, int w, int h, unsigned int color) {
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (bitmap[i + (j / 8) * w] & (j % 8)) {
SSD1331_Draw_Pixel(x + i, y + j, color);
}
}
}
}
 
void SSD1331_Draw_Char(int x, int y, unsigned char c, unsigned int color, unsigned int bg, unsigned char size) {
int i, j;
unsigned int line;
 
if ((x >= ssd1331_data_p->_width) || // Clip right
(y >= ssd1331_data_p->_height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
 
for (i = 0; i < 6; i++) {
if (i == 5)
line = 0x0;
else
line = font[(c * 5) + i];
for (j = 0; j < 8; j++) {
if (line & 0x1) {
if (size == 1) {// default size
SSD1331_Draw_Pixel(x + i, y + j, color);
} else { // big size
SSD1331_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
}
} else if (bg != color) {
if (size == 1) { // default size
SSD1331_Draw_Pixel(x + i, y + j, bg);
} else { // big size
SSD1331_Fill_Rect(x + i*size, y + j*size, size, size, bg);
}
}
line >>= 1;
}
}
}
 
void SSD1331_Write(unsigned char c) {
if (c == '\n' || c == '\r') {
ssd1331_data_p->cursor_y += ssd1331_data_p->textsize * 8;
ssd1331_data_p->cursor_x = 0;
// } else if (c == '\r') {
// // skip em
} else {
SSD1331_Draw_Char(ssd1331_data_p->cursor_x, ssd1331_data_p->cursor_y, c, ssd1331_data_p->textcolor, ssd1331_data_p->textbgcolor, ssd1331_data_p->textsize);
ssd1331_data_p->cursor_x += ssd1331_data_p->textsize * 6;
if (ssd1331_data_p->wrap && (ssd1331_data_p->cursor_x > (ssd1331_data_p->_width - ssd1331_data_p->textsize * 6))) {
ssd1331_data_p->cursor_y += ssd1331_data_p->textsize * 8;
ssd1331_data_p->cursor_x = 0;
}
}
}
 
void SSD1331_Write_String(const rom char *fmt, ...) {
unsigned char i, len;
unsigned char buffer[SSD1331_STRING_BUFFER_SIZE];
// Parse and create string
va_list args;
va_start(args, fmt);
vsprintf((char *) buffer, fmt, args);
va_end(args);
len = strlen((char *) buffer);
 
// Make sure string to insert fits in buffer, truncate if necessary
if (len > SSD1331_STRING_BUFFER_SIZE)
len = SSD1331_STRING_BUFFER_SIZE;
 
// Print buffer to string
for (i = 0; i < len; i++) {
SSD1331_Write(buffer[i]);
}
}
 
void SSD1331_Set_Cursor(int x, int y) {
ssd1331_data_p->cursor_x = x;
ssd1331_data_p->cursor_y = y;
}
 
void SSD1331_Set_Text_Color(unsigned int c) {
// for 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
ssd1331_data_p->textcolor = c;
ssd1331_data_p->textbgcolor = c;
}
 
void SSD1331_Set_Text_Color_BG(unsigned int c, unsigned int bg) {
ssd1331_data_p->textcolor = c;
ssd1331_data_p->textbgcolor = bg;
}
 
void SSD1331_Set_Text_Size(unsigned char s) {
ssd1331_data_p->textsize = (s > 0) ? s : 1;
}
 
void SSD1331_Set_Text_Wrap(unsigned char w) {
ssd1331_data_p->wrap = w;
}
 
void SSD1331_Set_Rotation(unsigned char x) {
x %= 4; // cant be higher than 3
ssd1331_data_p->rotation = x;
switch (x) {
case 0:
case 2:
ssd1331_data_p->_width = ssd1331_data_p->WIDTH;
ssd1331_data_p->_height = ssd1331_data_p->HEIGHT;
break;
case 1:
case 3:
ssd1331_data_p->_width = ssd1331_data_p->HEIGHT;
ssd1331_data_p->_height = ssd1331_data_p->WIDTH;
break;
}
}
 
unsigned int SSD1331_Color565(unsigned char r, unsigned char g, unsigned char b) {
unsigned int c;
c = r >> 3;
c <<= 6;
c |= g >> 2;
c <<= 5;
c |= b >> 3;
 
return c;
}
 
void SSD1331_Test_DrawLines(unsigned int color) {
int x, y;
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(0, 0, x, ssd1331_data_p->_height - 1, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(0, 0, ssd1331_data_p->_width - 1, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, 0, x, ssd1331_data_p->_height - 1, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, 0, 0, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(0, ssd1331_data_p->_height - 1, x, 0, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(0, ssd1331_data_p->_height - 1, ssd1331_data_p->_width - 1, y, color);
}
 
SSD1331_Clear_Display();
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, ssd1331_data_p->_height - 1, x, 0, color);
}
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) {
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, ssd1331_data_p->_height - 1, 0, y, color);
}
}
 
void SSD1331_Test_DrawRect(unsigned int color) {
int x;
SSD1331_Clear_Display();
if (ssd1331_data_p->_height < ssd1331_data_p->_width) {
for (x = 0; x < ssd1331_data_p->_height - 1; x += 6) {
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color);
}
} else {
for (x = 0; x < ssd1331_data_p->_width - 1; x += 6) {
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color);
}
}
}
 
void SSD1331_Test_FillRect(unsigned int color1, unsigned int color2) {
int x;
SSD1331_Clear_Display();
if (ssd1331_data_p->_height < ssd1331_data_p->_width) {
for (x = ssd1331_data_p->_height - 1; x > 6; x -= 6) {
SSD1331_Fill_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color1);
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color2);
}
} else {
for (x = ssd1331_data_p->_width - 1; x > 6; x -= 6) {
SSD1331_Fill_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color1);
SSD1331_Draw_Rect((ssd1331_data_p->_width - 1) / 2 - x / 2, (ssd1331_data_p->_height - 1) / 2 - x / 2, x, x, color2);
}
}
}
 
void SSD1331_Test_DrawCircle(unsigned int radius, unsigned int color) {
int x, y;
for (x = 0; x < ssd1331_data_p->_width - 1 + radius; x += radius * 2) {
for (y = 0; y < ssd1331_data_p->_height - 1 + radius; y += radius * 2) {
SSD1331_Draw_Circle(x, y, radius, color);
}
}
}
 
void SSD1331_Test_FillCircle(unsigned int radius, unsigned int color) {
unsigned char x, y;
for (x = radius; x < ssd1331_data_p->_width - 1; x += radius * 2) {
for (y = radius; y < ssd1331_data_p->_height - 1; y += radius * 2) {
SSD1331_Fill_Circle(x, y, radius, color);
}
}
}
 
void SSD1331_Test_DrawTria(void) {
int color = 0xF800;
int t;
int w = ssd1331_data_p->_width / 2;
int x = ssd1331_data_p->_height;
int y = 0;
int z = ssd1331_data_p->_width;
SSD1331_Clear_Display();
for (t = 0; t <= 15; t += 1) {
SSD1331_Draw_Triangle(w, y, y, x, z, x, color);
x -= 4;
y += 4;
z -= 4;
color += 100;
}
}
 
void SSD1331_Test_DrawRoundRect(void) {
int color = 100;
int i, t, x, y, w, h;
SSD1331_Clear_Display();
for (t = 0; t <= 4; t += 1) {
x = 0;
y = 0;
w = ssd1331_data_p->_width;
h = ssd1331_data_p->_height;
for (i = 0; i <= 24; i += 1) {
SSD1331_Draw_Round_Rect(x, y, w, h, 5, color);
x += 2;
y += 3;
w -= 4;
h -= 6;
color += 1100;
}
color += 100;
}
}
 
void SSD1331_Test_MediaButtons(void) {
// play
SSD1331_Clear_Display();
SSD1331_Fill_Round_Rect(25, 10, 78, 60, 8, SSD1331_WHITE);
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_RED);
Delay10KTCYx(100);
// pause
SSD1331_Fill_Round_Rect(25, 90, 78, 60, 8, SSD1331_WHITE);
SSD1331_Fill_Round_Rect(39, 98, 20, 45, 5, SSD1331_GREEN);
SSD1331_Fill_Round_Rect(69, 98, 20, 45, 5, SSD1331_GREEN);
Delay10KTCYx(100);
// play color
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_BLUE);
Delay10KTCYx(100);
// pause color
SSD1331_Fill_Round_Rect(39, 98, 20, 45, 5, SSD1331_RED);
SSD1331_Fill_Round_Rect(69, 98, 20, 45, 5, SSD1331_RED);
// play color
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_GREEN);
}
 
void SSD1331_Test_Pattern(void) {
unsigned char buffer[2];
unsigned int i, j;
SSD1331_GoTo(0, 0);
 
for (i = 0; i < 64; i++) {
for (j = 0; j < 96; j++) {
if (i > 55) {
buffer[0] = (SSD1331_WHITE >> 8);
buffer[1] = (SSD1331_WHITE);
} else if (i > 47) {
buffer[0] = (SSD1331_BLUE >> 8);
buffer[1] = (SSD1331_BLUE);
} else if (i > 39) {
buffer[0] = (SSD1331_GREEN >> 8);
buffer[1] = (SSD1331_GREEN);
} else if (i > 31) {
buffer[0] = (SSD1331_CYAN >> 8);
buffer[1] = (SSD1331_CYAN);
} else if (i > 23) {
buffer[0] = (SSD1331_RED >> 8);
buffer[1] = (SSD1331_RED);
} else if (i > 15) {
buffer[0] = (SSD1331_MAGENTA >> 8);
buffer[1] = (SSD1331_MAGENTA);
} else if (i > 7) {
buffer[0] = (SSD1331_YELLOW >> 8);
buffer[1] = (SSD1331_YELLOW);
} else {
buffer[0] = (SSD1331_BLACK >> 8);
buffer[1] = (SSD1331_BLACK);
}
SPI_DC_SELECT_LAT = 1; // D/C high (data)
SPI2_Write(buffer, 2);
}
}
}
/PIC Projects/PIC_27J13/oled_ssd1331.h
0,0 → 1,122
#ifndef OLED_SSD1331_H
#define OLED_SSD1331_H
 
#define SSD1331_LCDWIDTH 96
#define SSD1331_LCDHEIGHT 64
#define SSD1331_STRING_BUFFER_SIZE 64
 
// Select one of these defines to set the pixel color order
#define SSD1331_COLORORDER_RGB
// #define SSD1331_COLORORDER_BGR
 
// SSD1331 Commands
#define SSD1331_CMD_DRAWLINE 0x21
#define SSD1331_CMD_DRAWRECT 0x22
#define SSD1331_CMD_CLEARWINDOW 0x25
#define SSD1331_CMD_FILL 0x26
#define SSD1331_CMD_SETCOLUMN 0x15
#define SSD1331_CMD_SETROW 0x75
#define SSD1331_CMD_CONTRASTA 0x81
#define SSD1331_CMD_CONTRASTB 0x82
#define SSD1331_CMD_CONTRASTC 0x83
#define SSD1331_CMD_MASTERCURRENT 0x87
#define SSD1331_CMD_SETREMAP 0xA0
#define SSD1331_CMD_STARTLINE 0xA1
#define SSD1331_CMD_DISPLAYOFFSET 0xA2
#define SSD1331_CMD_NORMALDISPLAY 0xA4
#define SSD1331_CMD_DISPLAYALLON 0xA5
#define SSD1331_CMD_DISPLAYALLOFF 0xA6
#define SSD1331_CMD_INVERTDISPLAY 0xA7
#define SSD1331_CMD_SETMULTIPLEX 0xA8
#define SSD1331_CMD_SETMASTER 0xAD
#define SSD1331_CMD_DISPLAYOFF 0xAE
#define SSD1331_CMD_DISPLAYON 0xAF
#define SSD1331_CMD_POWERMODE 0xB0
#define SSD1331_CMD_PRECHARGE 0xB1
#define SSD1331_CMD_CLOCKDIV 0xB3
#define SSD1331_CMD_PRECHARGEA 0x8A
#define SSD1331_CMD_PRECHARGEB 0x8B
#define SSD1331_CMD_PRECHARGEC 0x8C
#define SSD1331_CMD_PRECHARGELEVEL 0xBB
#define SSD1331_CMD_VCOMH 0xBE
 
// Color definitions
#define SSD1331_BLACK 0x0000
#define SSD1331_BLUE 0x001F
#define SSD1331_RED 0xF800
#define SSD1331_GREEN 0x07E0
#define SSD1331_CYAN 0x07FF
#define SSD1331_MAGENTA 0xF81F
#define SSD1331_YELLOW 0xFFE0
#define SSD1331_WHITE 0xFFFF
 
typedef struct __SSD1331_DATA {
int WIDTH, HEIGHT; // raw display size
int _width, _height; // size depending on rotation
int cursor_x, cursor_y;
unsigned int textcolor, textbgcolor;
unsigned char textsize;
unsigned char rotation;
unsigned char wrap; // If set, wrap text at right side
} SSD1331_DATA;
 
// Misc functions
int SSD1331_Abs(int i);
void SSD1331_Swap(int *a, int *b);
unsigned int SSD1331_Color565(unsigned char r, unsigned char g, unsigned char b);
 
// Core functions
void SSD1331_Init(void);
void SSD1331_Begin(void);
void SSD1331_GoTo(int x, int y);
 
void SSD1331_Command(unsigned char c);
void SSD1331_Data(unsigned char d);
 
// Display functions
void SSD1331_Clear_Display(void);
 
void SSD1331_Draw_Pixel(int x, int y, unsigned int color);
void SSD1331_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1331_Draw_Fast_VLine(int x, int y, int h, unsigned int color);
void SSD1331_Draw_Fast_HLine(int x, int y, int w, unsigned int color);
void SSD1331_Draw_Rect(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1331_Fill_Rect(int x0, int y0, int x1, int y1, unsigned int color);
 
void SSD1331_Draw_Circle(int x0, int y0, int r, unsigned int color);
void SSD1331_Draw_Circle_Helper(int x0, int y0, int r, unsigned char cornername, unsigned int color);
void SSD1331_Fill_Circle(int x0, int y0, int r, unsigned int color);
void SSD1331_Fill_Circle_Helper(int x0, int y0, int r, unsigned char cornername, int delta, unsigned int color);
 
void SSD1331_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1331_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1331_Draw_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
void SSD1331_Fill_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
 
void SSD1331_Draw_Bitmap(int x, int y, const unsigned char *bitmap, int w, int h, unsigned int color);
void SSD1331_Draw_Char(int x, int y, unsigned char c, unsigned int color, unsigned int bg, unsigned char size);
 
void SSD1331_Write(unsigned char c);
void SSD1331_Write_String(const rom char *fmt, ...);
//void SSD1331_Append_String(const rom char *fmt, ...);
 
void SSD1331_Set_Cursor(int x, int y);
void SSD1331_Set_Text_Color(unsigned int c);
void SSD1331_Set_Text_Color_BG(unsigned int c, unsigned int bg);
void SSD1331_Set_Text_Size(unsigned char s);
void SSD1331_Set_Text_Wrap(unsigned char w);
void SSD1331_Set_Rotation(unsigned char r);
 
// Test functions
void SSD1331_Test_DrawLines(unsigned int color);
void SSD1331_Test_DrawRect(unsigned int color);
void SSD1331_Test_FillRect(unsigned int color1, unsigned int color2);
void SSD1331_Test_DrawCircle(unsigned int radius, unsigned int color);
void SSD1331_Test_FillCircle(unsigned int radius, unsigned int color);
void SSD1331_Test_DrawTria(void);
void SSD1331_Test_DrawRoundRect(void);
void SSD1331_Test_MediaButtons(void);
void SSD1331_Test_Pattern(void);
 
#endif /* OLED_SSD1331_H */
 
/PIC Projects/PIC_27J13/spi.c
0,0 → 1,197
#include "defines.h"
#include "spi.h"
 
static SPI_DATA spi_data;
static SPI_DATA *spi_data_p = &spi_data;
 
void SPI2_Init(unsigned char speed) {
// Set up SPI2 with specified pins
RPINR22 = PPS_SPI2_CLK_IN; // SPI2 CLK Input
PPS_SPI2_CLK_OUT = 11; // SPI2 CLK Output
 
#ifndef SPI2_WRITE_ONLY
RPINR21 = PPS_SPI2_MISO; // SPI2 Data Input
SPI_MISO_TRIS = 1; // SPI2 data in pin (MISO)
#endif
SPI_CLK_TRIS = 0; // SPI2 clock pin
PPS_SPI2_MOSI = 10; // SPI2 Data Output (MOSI)
SPI_MOSI_TRIS = 0; // SPI2 data out pin (MOSI)
 
SPI_SLAVE_SELECT_TRIS = 0; // SPI2 slave select
SPI_SLAVE_SELECT_LAT = 1; // SPI2 SS high (Idle)
 
SPI_RESET_TRIS = 0; // SPI2 reset
SPI_RESET_LAT = 1; // SPI2 reset active low
 
SPI_DC_SELECT_TRIS = 0; // SPI2 D/C select
SPI_DC_SELECT_LAT = 0;
 
SSP2STATbits.SMP = 0; // Input is sampled in the middle of data output time
SSP2STATbits.CKE = 0; // Transmit occurs on transition from Idle to active clock state
 
SSP2CON1bits.SSPM = speed;
 
SSP2CON1bits.CKP = 1; // Idle state for clock is a high level
SSP2CON1bits.SSPEN = 1; // Enable MSSP module
 
#ifdef SPI2_USE_INTERRUPT
PIE3bits.SSP2IE = 1; // Enable MSSP2 interrupt
#else
PIE3bits.SSP2IE = 0;
#endif
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in_len = 0;
spi_data_p->buffer_in_read_ind = 0;
spi_data_p->buffer_in_write_ind = 0;
#endif
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
 
void SPI2_Write(unsigned char *msg, unsigned int length) {
#ifdef SPI2_USE_INTERRUPT
unsigned char i;
spi_data_p->buffer_out_len = length;
spi_data_p->buffer_out_ind = 1;
for (i = 0; i < length; i++) {
spi_data_p->buffer_out[i] = msg[i];
}
SPI_SLAVE_SELECT_LAT = 0; // Bring SS line low
SSP2BUF = spi_data_p->buffer_out[0]; // Transmit first byte
#else
unsigned int i = 0;
unsigned char tmp = 0;
SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP2BUF = msg[i];
i++;
while (!SSP2STATbits.BF);
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
tmp = SSP2BUF;
#endif
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
void SPI2_Write_Repeat(unsigned char c, unsigned int length) {
#ifdef SPI2_USE_INTERRUPT
// TODO Implement interrupts for SPI2
#else
unsigned int i = 0;
unsigned char tmp = 0;
SPI_SLAVE_SELECT_LAT = 0;
while (i != length) {
SSP2BUF = c;
i++;
while (!SSP2STATbits.BF);
 
#ifndef SPI2_WRITE_ONLY
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
#else
// Read data in buffer to clear it
tmp = SSP2BUF;
#endif
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
#ifndef SPI2_WRITE_ONLY
void SPI2_Recv_Interrupt_Handler() {
unsigned char c;
 
if (SSP2STATbits.BF) { // Check if data receive flag is set
if (spi_data_p->buffer_in_len == MAXSPIBUF - 1) {
DBG_PRINT_SPI("SPI2: (ERROR) buffer overflow\r\n");
c = SSP2BUF; // Read SSP2BUF to clear it
} else {
// Save received data into buffer
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
 
// Put next byte in SSP2BUF for transmit
if (spi_data_p->buffer_out_ind != spi_data_p->buffer_out_len) {
SSP2BUF = spi_data_p->buffer_out[spi_data_p->buffer_out_ind];
spi_data_p->buffer_out_ind++;
} else {
SPI_SLAVE_SELECT_LAT = 1; // Bring SS line high
spi_data_p->buffer_out_ind = 0;
spi_data_p->buffer_out_len = 0;
}
}
}
}
 
void SPI2_Read(unsigned char length) {
#ifdef SPI2_USE_INTERRUPT
unsigned char i;
spi_data_p->buffer_out_len = length;
spi_data_p->buffer_out_ind = 1;
for (i = 0; i < length; i++) {
spi_data_p->buffer_out[i] = 0x0;
}
SPI_SLAVE_SELECT_LAT = 0; // Bring SS line low
SSP2BUF = spi_data_p->buffer_out[0]; // Transmit first byte
#else
unsigned char i = 0;
SPI_SLAVE_SELECT_LAT = 0;
 
for (i = 0; i < length; i++) {
SSP2BUF = 0x0;
while (!SSP2STATbits.BF);
 
spi_data_p->buffer_in[spi_data_p->buffer_in_write_ind] = SSP2BUF;
if (spi_data_p->buffer_in_write_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_write_ind = 0;
} else {
spi_data_p->buffer_in_write_ind++;
}
spi_data_p->buffer_in_len++;
}
SPI_SLAVE_SELECT_LAT = 1;
#endif
}
 
unsigned char SPI2_Buffer_Len() {
return spi_data_p->buffer_in_len;
}
 
unsigned char SPI2_Buffer_Read(unsigned char* buffer) {
unsigned char i = 0;
while (spi_data_p->buffer_in_len != 0) {
buffer[i] = spi_data_p->buffer_in[spi_data_p->buffer_in_read_ind];
i++;
if (spi_data_p->buffer_in_read_ind == MAXSPIBUF - 1) {
spi_data_p->buffer_in_read_ind = 0;
} else {
spi_data_p->buffer_in_read_ind++;
}
spi_data_p->buffer_in_len--;
}
return i;
}
#endif
/PIC Projects/PIC_27J13/spi.h
0,0 → 1,42
#ifndef SPI_H
#define SPI_H
 
#include "defines.h"
 
#define MAXSPIBUF 64
 
// Option to use interrupt. If interrupt are used, SPI write does not block but
// there is a longer delay between reading/writing data
//#define SPI2_USE_INTERRUPT
 
// SPI speed selection
#define SPI2_FOSC_64 0b0010
#define SPI2_FOSC_16 0b0001
#define SPI2_FOSC_8 0b1010
#define SPI2_FOSC_4 0b0000
 
typedef struct __SPI_DATA {
#ifndef SPI2_WRITE_ONLY
unsigned char buffer_in[MAXSPIBUF];
unsigned char buffer_in_read_ind;
unsigned char buffer_in_write_ind;
unsigned char buffer_in_len;
#endif
 
unsigned char buffer_out[MAXSPIBUF];
unsigned char buffer_out_ind;
unsigned char buffer_out_len;
} SPI_DATA;
 
void SPI2_Init(unsigned char speed);
void SPI2_Write(unsigned char *msg, unsigned int length);
void SPI2_Write_Repeat(unsigned char c, unsigned int length);
#ifndef SPI2_WRITE_ONLY
void SPI2_Recv_Interrupt_Handler(void);
void SPI2_Read(unsigned char length);
unsigned char SPI2_Buffer_Len(void);
unsigned char SPI2_Read_Buffer(unsigned char *buffer);
#endif
 
#endif /* SPI_H */
 
/PIC Projects/PIC_27J13/timers.c
0,0 → 1,35
/* The processor calls these handlers when an interrupt is triggered */
#include "defines.h"
#include "timers.h"
 
void Timer1_Init(void) {
T1CONbits.TMR1CS = 0x2; // Clock source using T1OSC and T1CLK pins
T1CONbits.RD16 = 0x1; // Configure for 16-bit read/writes
T1CONbits.T1OSCEN = 0x1; // Enable crystal driver
PIE1bits.TMR1IE = 0x1; // Enable interrupt
 
// Non-applicable settings
T1CONbits.T1CKPS = 0x0; // 1:1 prescale value
T1CONbits.NOT_T1SYNC = 0x1; // No external sync
T1GCONbits.TMR1GE = 0x0; // Disable gate control
}
 
void Timer1_Enable(void) {
T1CONbits.TMR1ON = 1;
}
 
void Timer1_Disable(void) {
T1CONbits.TMR1ON = 0;
}
 
void Timer1_Interrupt_Handler(void) {
#ifdef _TEST_TIMER1_RTC
TMR1H = 0x7F;
TMR1L = 0xFF;
LED_BLUE_LAT = 1;
LED_RED_LAT = 1;
Delay10KTCYx(255);
LED_BLUE_LAT = 0;
LED_RED_LAT = 0;
#endif
}
/PIC Projects/PIC_27J13/18f27j13.lkr
0,0 → 1,87
// File: 18f27j13_g.lkr
// Generic linker script for the PIC18F27J13 processor
 
#DEFINE _CODEEND _DEBUGCODESTART - 1
#DEFINE _CEND _CODEEND + _DEBUGCODELEN
#DEFINE _DATAEND _DEBUGDATASTART - 1
#DEFINE _DEND _DATAEND + _DEBUGDATALEN
 
LIBPATH .
 
#IFDEF _CRUNTIME
#IFDEF _EXTENDEDMODE
FILES c018i_e.o
FILES clib_e.lib
FILES p18f27j13_e.lib
 
#ELSE
FILES c018i.o
FILES clib.lib
FILES p18f27j13.lib
#FI
 
#FI
 
#IFDEF _DEBUGCODESTART
CODEPAGE NAME=page START=0x0 END=_CODEEND
CODEPAGE NAME=debug START=_DEBUGCODESTART END=_CEND PROTECTED
#ELSE
CODEPAGE NAME=page START=0x0 END=0x1FFF7
#FI
 
CODEPAGE NAME=config START=0x1FFF8 END=0x1FFFF PROTECTED
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
 
#IFDEF _EXTENDEDMODE
DATABANK NAME=gpre START=0x0 END=0x5F
#ELSE
ACCESSBANK NAME=accessram START=0x0 END=0x5F
#FI
 
DATABANK NAME=gpr0 START=0x60 END=0xFF
DATABANK NAME=gpr1 START=0x100 END=0x1FF
DATABANK NAME=gpr2 START=0x200 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=gpr4 START=0x400 END=0x4FF
DATABANK NAME=gpr5 START=0x500 END=0x5FF
DATABANK NAME=gpr6 START=0x600 END=0x6FF
 
//DATABANK NAME=gpr7 START=0x700 END=0x7FF
//DATABANK NAME=gpr8 START=0x800 END=0x8FF
//DATABANK NAME=gpr9 START=0x900 END=0x9FF
//DATABANK NAME=gpr10 START=0xA00 END=0xAFF
//DATABANK NAME=gpr11 START=0xB00 END=0xBFF
//DATABANK NAME=gpr12 START=0xC00 END=0xCFF
 
// Large (256b) buffer allocated in RAM for UART1 (replaces gpr7)
DATABANK NAME=UART1_BUFFER START=0x700 END=0x7FF
SECTION NAME=UART1_BUFFER RAM=UART1_BUFFER
 
// Large (256b) buffer allocated in RAM for XBee (replaces gpr8)
DATABANK NAME=XBEE_BUFFER START=0x800 END=0x8FF
SECTION NAME=XBEE_BUFFER RAM=XBEE_BUFFER
 
// Large (1024b) buffer allocated in RAM for LCD (replaces gpr9-12)
DATABANK NAME=LCD_BUFFER START=0x900 END=0xCFF
SECTION NAME=LCD_BUFFER RAM=LCD_BUFFER
 
#IFDEF _DEBUGDATASTART
DATABANK NAME=gpr13 START=0xD00 END=_DATAEND
DATABANK NAME=dbgspr START=_DEBUGDATASTART END=_DEND PROTECTED
#ELSE //no debug
DATABANK NAME=gpr13 START=0xD00 END=0xDFF
#FI
 
DATABANK NAME=gpr14 START=0xE00 END=0xEAF
DATABANK NAME=sfr14 START=0xEB0 END=0xEFF PROTECTED
DATABANK NAME=sfr15 START=0xF00 END=0xF5F PROTECTED
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
 
#IFDEF _CRUNTIME
SECTION NAME=CONFIG ROM=config
#IFDEF _DEBUGDATASTART
STACK SIZE=0x100 RAM=gpr12
#ELSE
STACK SIZE=0x100 RAM=gpr13
#FI
#FI
/PIC Projects/PIC_27J13/oled_ssd1306.h
0,0 → 1,131
#ifndef OLED_SSD1306_H
#define OLED_SSD1306_H
 
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
 
SSD1306_128_64 128x64 pixel display
 
SSD1306_128_32 128x32 pixel display
 
You also need to set the LCDWIDTH and LCDHEIGHT defines to an
appropriate size
 
-----------------------------------------------------------------------*/
#define SSD1306_128_64
// #define SSD1306_128_32
/*=========================================================================*/
 
#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 32
#endif
 
#define SSD1306_STRING_BUFFER_SIZE 32
 
#define SSD1306_BLACK 0
#define SSD1306_WHITE 1
 
#define SSD1306_I2C_ADDRESS 0x3D // 011110+SA0+RW
 
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
 
typedef struct __SSD1306_DATA {
int WIDTH, HEIGHT; // raw display size
int _width, _height; // size depending on rotation
int cursor_x, cursor_y;
unsigned int textcolor, textbgcolor;
unsigned char textsize;
unsigned char rotation;
unsigned char wrap; // If set, wrap text at right side
} SSD1306_DATA;
 
// Misc functions
int SSD1306_Abs(int i);
void SSD1306_Swap(int *a, int *b);
 
// Core functions
void SSD1306_Init(void);
void SSD1306_Begin(unsigned char vcc);
void SSD1306_Command(unsigned char cmd);
void SSD1306_Data(unsigned char data);
 
void SSD1306_Clear_Display(void);
void SSD1306_Invert_Display(unsigned char);
void SSD1306_Display(void);
 
// Drawing functions
void SSD1306_Draw_Pixel(int x, int y, unsigned int color);
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color);
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color);
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color);
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color);
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color);
 
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color);
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, unsigned char cornername, unsigned int color);
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color);
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, unsigned char cornername, int delta, unsigned int color);
 
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
void SSD1306_Draw_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
void SSD1306_Fill_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
 
void SSD1306_Draw_Bitmap(int x, int y, const unsigned char *bitmap, int w, int h, unsigned int color);
void SSD1306_Draw_Char(int x, int y, unsigned char c, unsigned int color, unsigned int bg, unsigned char size);
 
void SSD1306_Write(unsigned char c);
void SSD1306_Write_String(const rom char *fmt, ...);
//void SSD1306_Append_String(const rom char *fmt, ...);
 
void SSD1306_Set_Cursor(int x, int y);
void SSD1306_Set_Text_Color(unsigned int c);
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg);
void SSD1306_Set_Text_Size(unsigned char s);
void SSD1306_Set_Text_Wrap(unsigned char w);
void SSD1306_Set_Rotation(unsigned char r);
 
// Test functions
void SSD1306_Test_DrawChar(void);
void SSD1306_Test_DrawCircle(void);
void SSD1306_Test_DrawRect(void);
void SSD1306_Test_FillRect(void);
void SSD1306_Test_DrawTriangle(void);
void SSD1306_Test_FillTriangle(void);
void SSD1306_Test_DrawRoundRect(void);
void SSD1306_Test_FillRoundRect(void);
void SSD1306_Test_DrawLine(void);
 
#endif /* OLED_SSD1306_H */
 
/PIC Projects/PIC_27J13/glcdfont.c
0,0 → 1,263
#ifndef FONT5X7_H
#define FONT5X7_H
 
// standard ascii 5x7 font
 
static rom unsigned char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x21, 0x54, 0x54, 0x78, 0x41,
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0xF0, 0x29, 0x24, 0x29, 0xF0,
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x32, 0x48, 0x48, 0x48, 0x32,
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x39, 0x44, 0x44, 0x44, 0x39,
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0xAA, 0x00, 0x55, 0x00, 0xAA,
0xAA, 0x55, 0xAA, 0x55, 0xAA,
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
/PIC Projects/PIC_27J13/Makefile
0,0 → 1,108
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
 
 
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
 
 
# build
build: .build-post
 
.build-pre:
# Add your pre 'build' code here...
 
.build-post: .build-impl
# Add your post 'build' code here...
 
 
# clean
clean: .clean-post
 
.clean-pre:
# Add your pre 'clean' code here...
 
.clean-post: .clean-impl
# Add your post 'clean' code here...
 
 
# clobber
clobber: .clobber-post
 
.clobber-pre:
# Add your pre 'clobber' code here...
 
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
 
 
# all
all: .all-post
 
.all-pre:
# Add your pre 'all' code here...
 
.all-post: .all-impl
# Add your post 'all' code here...
 
 
# help
help: .help-post
 
.help-pre:
# Add your pre 'help' code here...
 
.help-post: .help-impl
# Add your post 'help' code here...
 
 
 
# include project implementation makefile
include nbproject/Makefile-impl.mk
 
# include project make variables
include nbproject/Makefile-variables.mk
/PIC Projects/PIC_27J13/pin_interrupts.c
0,0 → 1,101
#include "maindefs.h"
#include "pin_interrupts.h"
#include "pwm.h"
#include "msg_queues.h"
#include <delays.h>
 
static unsigned char port_b_prev_state;
 
void intx_init() {
TRISAbits.TRISA5 = 1;
TRISCbits.TRISC2 = 0;
LATCbits.LATC2 = 0;
 
RPINR1 = 2; // Bind INT1 interrupt to RP2
 
INTCON2bits.INTEDG1 = 0; // Trigger on falling edge
}
 
void int1_interrupt_handler() {
LATCbits.LATC2 = 1;
Delay10TCYx(255);
LATCbits.LATC2 = 0;
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_INT1, (void *) 0);
}
 
void port_b_int_init() {
port_b_prev_state = 0x0F;
 
INTCON2bits.RBPU = 0;
// Set pins as inputs
TRISBbits.TRISB4 = 1;
TRISBbits.TRISB5 = 1;
TRISBbits.TRISB6 = 1;
TRISBbits.TRISB7 = 1;
 
// Turn on internal voltage pull-up
PORTBbits.RB4 = 1;
PORTBbits.RB5 = 1;
PORTBbits.RB6 = 1;
PORTBbits.RB7 = 1;
LATBbits.LATB4 = 1;
LATBbits.LATB5 = 1;
LATBbits.LATB6 = 1;
LATBbits.LATB7 = 1;
}
 
void port_b_int_interrupt_handler() {
// Pull the new pin values
unsigned char new_state = (PORTB & 0xF0) >> 4;
 
// Query which pin input value changed and send value to main()
if ((new_state ^ port_b_prev_state) & 0x01) {
if (port_b_prev_state & 0x01) {
// Pin transitioned HIGH -> LOW (button pressed)
DBG_PRINT_PORTB_INT("Port B4 HIGH->LOW\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_DOWN, (void *) 0);
} else {
// Pin transitioned LOW -> HIGH (button released)
DBG_PRINT_PORTB_INT("Port B4 LOW->HIGH\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_4_UP, (void *) 0);
}
}
if ((new_state ^ port_b_prev_state) & 0x02) {
if (port_b_prev_state & 0x02) {
// Pin transitioned HIGH -> LOW (button pressed)
DBG_PRINT_PORTB_INT("Port B5 HIGH->LOW\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_DOWN, (void *) 0);
} else {
// Pin transitioned LOW -> HIGH (button released)
DBG_PRINT_PORTB_INT("Port B5 LOW->HIGH\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_5_UP, (void *) 0);
}
}
if ((new_state ^ port_b_prev_state) & 0x04) {
if (port_b_prev_state & 0x04) {
// Pin transitioned HIGH -> LOW (button pressed)
DBG_PRINT_PORTB_INT("Port B6 HIGH->LOW\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_DOWN, (void *) 0);
} else {
// Pin transitioned LOW -> HIGH (button released)
DBG_PRINT_PORTB_INT("Port B6 LOW->HIGH\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_6_UP, (void *) 0);
}
}
if ((new_state ^ port_b_prev_state) & 0x08) {
if (port_b_prev_state & 0x08) {
// Pin transitioned HIGH -> LOW (button pressed)
DBG_PRINT_PORTB_INT("Port B7 HIGH->LOW\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_DOWN, (void *) 0);
} else {
// Pin transitioned LOW -> HIGH (button released)
DBG_PRINT_PORTB_INT("Port B7 LOW->HIGH\r\n");
MQ_sendmsg_ToMainFromLow(0, MSGTYPE_PORTB_7_UP, (void *) 0);
}
}
// Save the new state of pins
port_b_prev_state = new_state;
}
/PIC Projects/PIC_27J13/pwm.c
0,0 → 1,31
#include "maindefs.h"
#include "pwm.h"
#include <pwm.h>
 
void pwm_init() {
// Configure pins RC5 and RC7 as outputs
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
LATCbits.LATC0 = 0;
LATCbits.LATC1 = 0;
 
RPOR11 = 14; // Set RP11 to ECCP1 PWM Output Channel A
RPOR12 = 15; // Set RP12 to ECCP1 PWM Output Channel B
}
 
void pwm_start() {
OpenEPWM1(0xFF, ECCP_1_SEL_TMR12); // 38kHz Frequency
SetDCEPWM1(512); // 50% Duty Cycle
 
// Wait for completion of a full PWM cycle before enabling output mode
while(!PIR1bits.TMR2IF);
SetOutputEPWM1(SINGLE_OUT, PWM_MODE_1);
 
// Enable ECCP1 output channels A and B
PSTR1CONbits.STRA = 1;
PSTR1CONbits.STRB = 1;
}
 
void pwm_stop() {
CloseEPWM1();
}