Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 129 → Rev 147

/PIC Stuff/PIC_27J13/main.c
1,19 → 1,18
#include "maindefs.h"
#include "defines.h"
#include "interrupts.h"
#include "uart.h"
#include "i2c.h"
#include "spi.h"
#include "nfc.h"
#include "led_backpack.h"
#include "led_HT16K33.h"
#include "oled_ssd1306.h"
#include "oled_ssd1331.h"
#include "adc.h"
#include "xbee.h"
#include "timers.h"
#include <delays.h>
#include <string.h>
 
#pragma config WDTEN = OFF // Turn off watchdog timer
#pragma config XINST = OFF // Turn off extended instruction set
#ifdef USE_EXT_OSC
#pragma config OSC = HSPLL // Use external oscillator (101)
#pragma config PLLDIV = 3 // Set PPL prescaler to 3 (to get 4MHz)
21,9 → 20,12
#pragma config OSC = INTOSCPLL // Use internal oscillator
#pragma config PLLDIV = 2 // Set PPL prescaler to 2 (to get 4MHz)
#endif
 
#pragma config WDTEN = OFF // Turn off watchdog timer
#pragma config XINST = OFF // Turn off extended instruction set
#pragma config CFGPLLEN = ON // Enable PLL on startup
#pragma config PLLSEL = PLL96 // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
//#pragma config SOSCSEL = HIGH // High Power T1OSC/SOSC circuit selected
#pragma config SOSCSEL = LOW // Low Power T1OSC/SOSC circuit selected
//#pragma config ADCSEL = BIT12 // 12-bit ADrC
//#pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed
 
84,7 → 86,7
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
 
I2C_Configure_Master();
I2C_Configure_Master(I2C_100KHZ);
 
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
interrupt_init(); // Initialize the interrupt priorities
93,9 → 95,9
 
while (1) {
 
buffer[0] = 0xBB;
buffer[0] = 0x8;
 
I2C_Master_Send(0x30, 1, buffer);
I2C_Master_Send(0x24, 1, buffer);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
102,7 → 104,7
}
DBG_PRINT_MAIN("S:%X ", result);
 
I2C_Master_Recv(0x30, 2);
I2C_Master_Recv(0x24, 2);
result = I2C_Get_Status();
while (!result) {
result = I2C_Get_Status();
114,17 → 116,17
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]);
}
// 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");
 
155,7 → 157,7
UART1_Init(); // Initialize the UART handler code
I2C_Init(); // Initialize the I2C handler code
 
I2C_Configure_Slave(0x30);
I2C_Configure_Slave(0x24);
 
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
interrupt_init(); // Initialize the interrupt priorities
333,8 → 335,6
 
void main(void) {
unsigned char i = 0;
unsigned char length = 0;
unsigned char buffer[100];
unsigned int counter = 0;
 
/* --------------------- Oscillator Configuration --------------------- */
451,7 → 451,7
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
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
569,7 → 569,7
ANCON1 = 0x1F;
 
UART1_Init(); // Initialize the UART handler code
SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module
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
578,7 → 578,7
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
SSD1331_Begin();
 
while (1) {
 
Delay10KTCYx(255);
591,89 → 591,89
SSD1331_Clear_Display();
SSD1331_Set_Rotation(0);
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");
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_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_DrawLines(SSD1331_YELLOW);
// 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(3);
SSD1331_Test_DrawLines(SSD1331_BLUE);
// 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_DrawRect(SSD1331_GREEN);
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(0);
// SSD1331_Test_DrawRoundRect();
//
// Delay10KTCYx(255);
// Delay10KTCYx(255);
// SSD1331_Set_Rotation(3);
// SSD1331_Test_DrawRoundRect();
 
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);
904,11 → 904,7
}
#endif
 
#if !defined(_TEST_UART) && !defined(_TEST_I2C_MASTER) && \
!defined(_TEST_I2C_SLAVE) && !defined(_TEST_SPI) && \
!defined(_TEST_NFC) && !defined(_TEST_LED_BACKPACK) && \
!defined(_TEST_SSD1306_OLED) && !defined(_TEST_SSD1331_OLED) && \
!defined(_TEST_ADC) && !defined(_TEST_XBEE)
#ifdef _TEST_NFC_TO_SSD1306_OLED
 
void main(void) {
unsigned char length = 0;
931,7 → 927,7
UART1_Init();
I2C_Init();
NFC_Init();
SPI2_Init(SPI2_FOSC_8);
SPI2_Init(SPI2_FOSC_4);
SSD1306_Init();
 
I2C_Configure_Master(I2C_400KHZ);
1007,3 → 1003,100
}
}
#endif
 
#ifdef _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) {
 
}
}
#endif
 
#ifdef _TEST_LUX
 
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();
I2C_Configure_Master(I2C_100KHZ);
 
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
interrupt_init(); // Initialize the interrupt priorities
 
while (1) {
 
}
}
#endif
 
#if !defined(_TEST_UART) && !defined(_TEST_I2C_MASTER) && \
!defined(_TEST_I2C_SLAVE) && !defined(_TEST_SPI) && \
!defined(_TEST_NFC) && !defined(_TEST_LED_BACKPACK) && \
!defined(_TEST_SSD1306_OLED) && !defined(_TEST_SSD1331_OLED) && \
!defined(_TEST_ADC) && !defined(_TEST_XBEE) && \
!defined(_TEST_NFC_TO_SSD1306_OLED) && !defined(_TEST_TIMER1_RTC) && \
!defined(_TEST_LUX)
 
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();
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();
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
 
while (1) {
 
}
}
#endif