5,6 → 5,8 |
#include "INTERRUPT.h" |
#include "UART.h" |
#include "I2C.h" |
#include "L3G.h" |
#include "LSM303.h" |
|
// <editor-fold defaultstate="collapsed" desc="Configuration Bits"> |
// CONFIG1 |
33,6 → 35,7 |
char LED_R_ON = 0; |
char LED_G_ON = 0; |
char LED_B_ON = 0; |
char timer_2_pwm = 0; |
|
void Error(char ID) { |
while(1) { |
120,6 → 123,39 |
} |
} |
|
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 |
142,13 → 178,13 |
UART_RTS_LAT = 0; |
|
// Initialize all peripherals |
// TIMER_1_Init(); |
TIMER_2_Init(); |
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_100KHZ); |
I2C_Configure_Master(I2C_400KHZ); |
INTERRUPT_Enable(); |
// TIMER_1_Start(); |
TIMER_2_Start(); |
156,22 → 192,37 |
// A small delay is needed for the sensors to start up |
__delay_ms(10); |
|
// Run a check to ensure that all sensors are properly connected |
Startup_Check(); |
|
// LED_R_ON = 1; |
// LED_G_ON = 1; |
// LED_B_ON = 1; |
// Initialze the sensors |
L3G_Init(); |
LSM303_Init(); |
|
char output[19] = {0}; |
output[18] = '\n'; |
|
LED_B_ON = 1; |
|
__delay_ms(3000); |
|
while(1) { |
UART_Write("Hello World \r\n", 14); |
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); |
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]); |
|
UART_Write((char *)&output[0], 19); |
|
__delay_ms(10); |
|
// 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); |
} |
} |