/PIC Stuff/PIC_27J13/Adafruit_GFX.c |
---|
File deleted |
\ No newline at end of file |
/PIC Stuff/PIC_27J13/Adafruit_GFX.h |
---|
File deleted |
/PIC Stuff/PIC_27J13/adc.c |
---|
5,9 → 5,9 |
static ADC_DATA *adc_data_p = &adc_data; |
void ADC_Init(unsigned char TAD, unsigned char FOSC) { |
TRISAbits.TRISA0 = 1; |
TRISAbits.TRISA1 = 1; |
TRISAbits.TRISA2 = 1; |
ADC_AN0_TRIS = 1; |
ADC_AN1_TRIS = 1; |
ADC_AN2_TRIS = 1; |
adc_data_p->last_channel = 0; |
adc_data_p->result = 0; |
/PIC Stuff/PIC_27J13/i2c.c |
---|
33,8 → 33,8 |
void I2C_Configure_Master(unsigned char speed) { |
i2c_data_p->operating_mode = I2C_MODE_MASTER; |
TRISCbits.TRISC3 = 1; |
TRISCbits.TRISC4 = 1; |
I2C_CLK_TRIS = 1; |
I2C_DAT_TRIS = 1; |
SSPSTAT = 0x0; |
SSPCON1 = 0x0; |
120,8 → 120,8 |
i2c_data_p->operating_mode = I2C_MODE_SLAVE; |
// Ensure the two lines are set for input (we are a slave) |
TRISCbits.TRISC3 = 1; |
TRISCbits.TRISC4 = 1; |
I2C_CLK_TRIS = 1; |
I2C_DAT_TRIS = 1; |
SSPADD = addr << 1; // Set the slave address |
/PIC Stuff/PIC_27J13/main.c |
---|
1,5 → 1,4 |
#include "maindefs.h" |
#include "Adafruit_GFX.h" |
#include "interrupts.h" |
#include "uart.h" |
#include "i2c.h" |
28,35 → 27,6 |
//#pragma config ADCSEL = BIT12 // 12-bit ADrC |
//#pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed |
/* ----------- IO Pins ----------- |
* RA0 - A/D X |
* RA1 - A/D Y |
* RA2 - A/D Z |
* RA3 - |
* RA4 - [CANNOT BE USED (VDDCORE/VCAP)] |
* RA5 - |
* RA6 - Oscillator |
* RA7 - Oscillator |
* |
* RB0 - UART2 Tx |
* RB1 - UART2 Rx |
* RB2 - SPI2 MOSI |
* RB3 - SPI2 MISO |
* RB4 - SPI2 CLK |
* RB5 - SPI2 D/C |
* RB6 - SPI2 RESET |
* RB7 - SPI2 CS |
* |
* RC0 - |
* RC1 - IRQ |
* RC2 - Reset |
* RC3 - I2C CLK |
* RC4 - I2C DATA |
* RC5 - |
* RC6 - UART1 Tx |
* RC7 - UART1 Rx |
* ---------------------------- */ |
#ifdef _TEST_UART |
void main(void) { |
256,26 → 226,6 |
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); |
297,6 → 247,26 |
// } |
// } |
// // 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_pollTargets(1, 1, cardData); |
if (!length) { |
494,99 → 464,91 |
SSD1306_Display(); // Show splashscreen |
while (1) { |
// Delay10KTCYx(255); |
// Delay10KTCYx(255); |
// SSD1306_Clear_Display(); |
// for (i = 0; i < 32; i++) { |
// SSD1306_Draw_Pixel(i, i, WHITE); |
// } |
// SSD1306_Display(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
SSD1306_Clear_Display(); |
SSD1306_Test_DrawLine(); |
SSD1306_Display(); |
// 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(); |
// GFX_fillCircle(GFX_width() / 2, GFX_height() / 2, 10, 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_DrawRect(); |
SSD1306_Display(); |
// Delay10KTCYx(255); |
// Delay10KTCYx(255); |
// SSD1306_Clear_Display(); |
// SSD1306_Test_DrawChar(); |
// SSD1306_Display(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
SSD1306_Clear_Display(); |
SSD1306_Test_FillRect(); |
SSD1306_Display(); |
// Delay10KTCYx(255); |
// Delay10KTCYx(255); |
// SSD1306_Clear_Display(); |
// GFX_setTextSize(1); |
// GFX_setTextColor(WHITE); |
// GFX_setCursor(0,0); |
// GFX_writeString("Hello World!\n"); |
//// GFX_setTextColorBG(BLACK, WHITE); |
// i = 65535; |
// GFX_writeString("%u %d\n", i, i); |
//// GFX_setTextSize(2); |
//// GFX_setTextColor(WHITE); |
// l = 0xDEADBEEF; |
// GFX_writeString("0x%X", (long)l); |
// SSD1306_Display(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
SSD1306_Clear_Display(); |
SSD1306_Test_DrawCircle(); |
SSD1306_Display(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
SSD1306_Clear_Display(); |
GFX_setRotation(0); |
GFX_setTextSize(1); |
GFX_setTextColor(SSD1306_WHITE); |
GFX_setCursor(0, 0); |
GFX_writeString("%u", i); |
i++; |
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(); |
} |
} |
#endif |
621,102 → 583,102 |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_Pattern(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_clearScreen(); |
GFX_setRotation(0); |
GFX_setCursor(0, 0); |
GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); |
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"); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_clearScreen(); |
GFX_setRotation(3); |
GFX_setCursor(0, 0); |
GFX_writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); |
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); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_DrawLines(SSD1331_YELLOW); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
SSD1331_Set_Rotation(3); |
SSD1331_Test_DrawLines(SSD1331_BLUE); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_DrawRect(SSD1331_GREEN); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(1); |
SSD1331_Set_Rotation(1); |
SSD1331_Test_DrawRect(SSD1331_RED); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(2); |
SSD1331_Set_Rotation(2); |
SSD1331_Test_DrawRect(SSD1331_BLUE); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
SSD1331_Set_Rotation(3); |
SSD1331_Test_DrawRect(SSD1331_YELLOW); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_FillRect(SSD1331_YELLOW, SSD1331_MAGENTA); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
SSD1331_Set_Rotation(3); |
SSD1331_Test_FillRect(SSD1331_BLUE, SSD1331_GREEN); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
GFX_clearScreen(); |
SSD1331_Set_Rotation(0); |
SSD1331_Clear_Display(); |
SSD1331_Test_FillCircle(10, SSD1331_BLUE); |
SSD1331_Test_DrawCircle(10, SSD1331_WHITE); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
GFX_clearScreen(); |
SSD1331_Set_Rotation(3); |
SSD1331_Clear_Display(); |
SSD1331_Test_FillCircle(10, SSD1331_MAGENTA); |
SSD1331_Test_DrawCircle(10, SSD1331_YELLOW); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_DrawTria(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
SSD1331_Set_Rotation(3); |
SSD1331_Test_DrawTria(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(0); |
SSD1331_Set_Rotation(0); |
SSD1331_Test_DrawRoundRect(); |
Delay10KTCYx(255); |
Delay10KTCYx(255); |
GFX_setRotation(3); |
SSD1331_Set_Rotation(3); |
SSD1331_Test_DrawRoundRect(); |
// GFX_clearScreen(); |
// GFX_setRotation(3); |
// GFX_setCursor(0,0); |
// GFX_setTextColorBG(SSD1331_WHITE, SSD1331_BLACK); |
// GFX_writeString("%u", i); |
// 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++; |
} |
} |
740,11 → 702,11 |
UART1_Init(); // Initialize the UART handler code |
SPI2_Init(SPI2_FOSC_8); // Initialize the SPI module |
SSD1331_Init(); // Initialize the SSD1331 OLED display (uses SPI2) |
SSD1306_Init(); // Initialize the SSD1331 OLED display (uses SPI2) |
ADC_Init(ADC_TAD_20, ADC_FOSC_64); |
// I2C_Configure_Master(I2C_400KHZ); |
SSD1331_Begin(); |
SSD1306_Begin(SSD1306_SWITCHCAPVCC); |
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts |
interrupt_init(); // Initialize the interrupt priorities |
752,28 → 714,31 |
DBG_PRINT_MAIN("\r\nBegin Program\r\n"); |
memset(buffer, 0, 60); |
GFX_clearScreen(); |
GFX_setRotation(3); |
SSD1306_Clear_Display(); |
SSD1306_Display(); |
while (1) { |
// ADC read from AN0-AN2 and prints to display |
ADC_Start(ADC_CHANNEL_AN2); |
GFX_fillRect(0, 0, GFX_width(), 8, SSD1331_BLACK); |
GFX_setCursor(0, 0); |
// SSD1306_Fill_Rect(0, 0, SSD1306_LCDWIDTH, 8, SSD1331_BLACK); |
SSD1306_Set_Cursor(0, 0); |
while (!ADC_Get_Result(&x)); |
GFX_writeString("X: %u", x); |
SSD1306_Write_String("X: %u", x); |
SSD1306_Display(); |
ADC_Start(ADC_CHANNEL_AN1); |
GFX_fillRect(0, 8, GFX_width(), 8, SSD1331_BLACK); |
GFX_setCursor(0, 8); |
// SSD1306_Fill_Rect(0, 8, SSD1306_LCDWIDTH, 8, SSD1331_BLACK); |
SSD1306_Set_Cursor(0, 8); |
while (!ADC_Get_Result(&y)); |
GFX_writeString("Y: %u", y); |
SSD1306_Write_String("Y: %u", y); |
SSD1306_Display(); |
ADC_Start(ADC_CHANNEL_AN0); |
GFX_fillRect(0, 16, GFX_width(), 8, SSD1331_BLACK); |
GFX_setCursor(0, 16); |
// SSD1306_Fill_Rect(0, 16, SSD1306_LCDWIDTH, 8, SSD1331_BLACK); |
SSD1306_Set_Cursor(0, 16); |
while (!ADC_Get_Result(&z)); |
GFX_writeString("Z: %u", z); |
SSD1306_Write_String("Z: %u", z); |
SSD1306_Display(); |
} |
} |
785,7 → 750,12 |
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 |
829,7 → 799,7 |
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); |
846,13 → 816,24 |
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: |
rx_data_frame = (void *)buffer; |
DBG_PRINT_MAIN("XBEE: parsing recieved data recieved frame\r\n"); |
rx_data_frame = (void *) buffer; |
XBee_ConvertEndian64(&(rx_data_frame->source_64)); |
XBee_ConvertEndian16(&(rx_data_frame->source_16)); |
DBG_PRINT_MAIN("Source 64: %08lX %08lX Source 16: %04X Options: %X\r\n", \\ |
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, \\ |
865,6 → 846,13 |
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_ConvertEndian16(&(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"); |
874,6 → 862,7 |
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"); |
880,9 → 869,29 |
break; |
case XBEE_RX_NODE_IDENTIFICATION: |
DBG_PRINT_MAIN("XBEE: parsing recieved node identification frame\r\n"); |
rx_node_ident_frame = (void *) buffer; |
XBee_ConvertEndian64(&(rx_node_ident_frame->source_64)); |
XBee_ConvertEndian16(&(rx_node_ident_frame->source_16)); |
XBee_ConvertEndian64(&(rx_node_ident_frame->remote_64)); |
XBee_ConvertEndian16(&(rx_node_ident_frame->remote_16)); |
XBee_ConvertEndian16(&(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"); |
923,7 → 932,7 |
I2C_Init(); |
NFC_Init(); |
SPI2_Init(SPI2_FOSC_8); |
SSD1331_Init(); |
SSD1306_Init(); |
I2C_Configure_Master(I2C_400KHZ); |
932,20 → 941,22 |
DBG_PRINT_MAIN("\r\nBegin Program\r\n"); |
SSD1331_Begin(); |
SSD1306_Begin(SSD1306_SWITCHCAPVCC); |
memset(cardData, 0, 24); |
memset(cardData_prev, 0, 24); |
GFX_clearScreen(); |
GFX_setRotation(0); |
GFX_setCursor(0, 0); |
SSD1306_Clear_Display(); |
SSD1306_Set_Rotation(0); |
SSD1306_Set_Cursor(0, 0); |
version = NFC_getFirmwareVersion(); |
while (!version.IC) { |
GFX_appendString("Waiting for NFC board..\r"); |
SSD1306_Write_String("Waiting for NFC board..\r"); |
SSD1306_Display(); |
Delay10KTCYx(3); |
version = NFC_getFirmwareVersion(); |
} |
GFX_appendString("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev); |
SSD1306_Write_String("PN5%X Ver. %d.%d\r", version.IC, version.Ver, version.Rev); |
SSD1306_Display(); |
NFC_SAMConfig(); |
while (1) { |
960,7 → 971,8 |
} 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 { |
GFX_appendString("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("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); |
974,17 → 986,21 |
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 |
GFX_appendString("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("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 |
GFX_appendString("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("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 |
GFX_appendString("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("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); |
GFX_appendString("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("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); |
} |
} |
/PIC Stuff/PIC_27J13/maindefs.h |
---|
22,10 → 22,6 |
//#define _TEST_ADC |
#define _TEST_XBEE |
// Option to choose between active OLED displays |
//#define GFX_SSD1306 |
#define GFX_SSD1331 |
// Enable or disable debug prints depending on project preprocessor (_DEBUG) |
#ifdef _DEBUG |
#define DBG_PRINT_MAIN(x) UART1_WriteS(x) |
47,5 → 43,43 |
#define DBG_PRINT_BUFFER(x) |
#endif |
// Pin allocations |
#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.TRISB2 |
#define SPI_MISO_TRIS TRISBbits.TRISB3 |
#define SPI_CLK_TRIS TRISBbits.TRISB4 |
#define SPI_DC_SELECT_TRIS TRISBbits.TRISB5 |
#define SPI_DC_SELECT_LAT LATBbits.LATB5 |
#define SPI_RESET_TRIS TRISBbits.TRISB6 |
#define SPI_RESET_LAT LATBbits.LATB6 |
#define SPI_SLAVE_SELECT_TRIS TRISBbits.TRISB7 |
#define SPI_SLAVE_SELECT_LAT LATBbits.LATB7 |
#define NFC_IRQ_TRIS TRISCbits.TRISC1 |
#define NFC_IRQ_PORT PORTCbits.RC1 |
#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 |
#define PPS_SPI2_CLK_IN 7 |
#define PPS_SPI2_CLK_OUT RPOR7 |
#define PPS_SPI2_MISO 6 |
#define PPS_SPI2_MOSI RPOR5 |
#endif |
/PIC Stuff/PIC_27J13/nbproject/Makefile-default.mk |
---|
41,11 → 41,11 |
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}/led_backpack.o ${OBJECTDIR}/nfc.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/Adafruit_GFX.o ${OBJECTDIR}/oled_ssd1331.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o |
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/i2c.o.d ${OBJECTDIR}/interrupts.o.d ${OBJECTDIR}/led_backpack.o.d ${OBJECTDIR}/nfc.o.d ${OBJECTDIR}/spi.o.d ${OBJECTDIR}/uart.o.d ${OBJECTDIR}/oled_ssd1306.o.d ${OBJECTDIR}/glcdfont.o.d ${OBJECTDIR}/Adafruit_GFX.o.d ${OBJECTDIR}/oled_ssd1331.o.d ${OBJECTDIR}/adc.o.d ${OBJECTDIR}/xbee.o.d |
OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/i2c.o ${OBJECTDIR}/interrupts.o ${OBJECTDIR}/led_backpack.o ${OBJECTDIR}/nfc.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o ${OBJECTDIR}/oled_ssd1331.o |
POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/i2c.o.d ${OBJECTDIR}/interrupts.o.d ${OBJECTDIR}/led_backpack.o.d ${OBJECTDIR}/nfc.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 |
# Object Files |
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/i2c.o ${OBJECTDIR}/interrupts.o ${OBJECTDIR}/led_backpack.o ${OBJECTDIR}/nfc.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/Adafruit_GFX.o ${OBJECTDIR}/oled_ssd1331.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o |
OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/i2c.o ${OBJECTDIR}/interrupts.o ${OBJECTDIR}/led_backpack.o ${OBJECTDIR}/nfc.o ${OBJECTDIR}/spi.o ${OBJECTDIR}/uart.o ${OBJECTDIR}/oled_ssd1306.o ${OBJECTDIR}/glcdfont.o ${OBJECTDIR}/adc.o ${OBJECTDIR}/xbee.o ${OBJECTDIR}/oled_ssd1331.o |
CFLAGS= |
62,7 → 62,7 |
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} |
${MAKE} -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 |
130,18 → 130,6 |
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/glcdfont.o glcdfont.c |
@${DEP_GEN} -d ${OBJECTDIR}/glcdfont.o |
${OBJECTDIR}/Adafruit_GFX.o: Adafruit_GFX.c nbproject/Makefile-${CND_CONF}.mk |
@${MKDIR} ${OBJECTDIR} |
@${RM} ${OBJECTDIR}/Adafruit_GFX.o.d |
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/Adafruit_GFX.o Adafruit_GFX.c |
@${DEP_GEN} -d ${OBJECTDIR}/Adafruit_GFX.o |
${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 -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c |
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o |
${OBJECTDIR}/adc.o: adc.c nbproject/Makefile-${CND_CONF}.mk |
@${MKDIR} ${OBJECTDIR} |
@${RM} ${OBJECTDIR}/adc.o.d |
154,6 → 142,12 |
${MP_CC} $(MP_EXTRA_CC_PRE) -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/xbee.o xbee.c |
@${DEP_GEN} -d ${OBJECTDIR}/xbee.o |
${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 -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c |
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o |
else |
${OBJECTDIR}/main.o: main.c nbproject/Makefile-${CND_CONF}.mk |
@${MKDIR} ${OBJECTDIR} |
209,18 → 203,6 |
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/glcdfont.o glcdfont.c |
@${DEP_GEN} -d ${OBJECTDIR}/glcdfont.o |
${OBJECTDIR}/Adafruit_GFX.o: Adafruit_GFX.c nbproject/Makefile-${CND_CONF}.mk |
@${MKDIR} ${OBJECTDIR} |
@${RM} ${OBJECTDIR}/Adafruit_GFX.o.d |
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/Adafruit_GFX.o Adafruit_GFX.c |
@${DEP_GEN} -d ${OBJECTDIR}/Adafruit_GFX.o |
${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 -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c |
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o |
${OBJECTDIR}/adc.o: adc.c nbproject/Makefile-${CND_CONF}.mk |
@${MKDIR} ${OBJECTDIR} |
@${RM} ${OBJECTDIR}/adc.o.d |
233,6 → 215,12 |
${MP_CC} $(MP_EXTRA_CC_PRE) -p$(MP_PROCESSOR_OPTION) -oi -mL -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/xbee.o xbee.c |
@${DEP_GEN} -d ${OBJECTDIR}/xbee.o |
${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 -I ${MP_CC_DIR}\\..\\h -fo ${OBJECTDIR}/oled_ssd1331.o oled_ssd1331.c |
@${DEP_GEN} -d ${OBJECTDIR}/oled_ssd1331.o |
endif |
# ------------------------------------------------------------------------------------ |
/PIC Stuff/PIC_27J13/nbproject/Makefile-genesis.properties |
---|
1,8 → 1,8 |
# |
#Mon Jul 23 10:59:08 EDT 2012 |
default.com-microchip-mplab-nbide-toolchainC18-C18LanguageToolchain.md5=db1c0674398f590b65c1c1c4fb1e2b92 |
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\mplabc18\\v3.40\\bin |
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=485c926ba2cd86275d1848ca44c226c5 |
default.languagetoolchain.version=3.40 |
#Sun Aug 05 15:34:42 EDT 2012 |
default.com-microchip-mplab-nbide-toolchainC18-C18LanguageToolchain.md5=fd3c294f650afc344cfb0579847b1618 |
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\mplabc18\\v3.42\\bin |
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=39edbdd4b2849b7912992109f4b86781 |
default.languagetoolchain.version=3.42 |
host.platform=windows |
conf.ids=default |
/PIC Stuff/PIC_27J13/nbproject/Makefile-local-default.mk |
---|
21,17 → 21,15 |
# 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.40\bin\mcc18.exe" |
# MP_CPPC is not defined |
MP_CC="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\mcc18.exe" |
# MP_BC is not defined |
MP_AS="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\..\mpasm\MPASMWIN.exe" |
MP_LD="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\mplink.exe" |
MP_AR="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\mplib.exe" |
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.40\bin" |
# MP_CPPC_DIR is not defined |
MP_CC_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin" |
# MP_BC_DIR is not defined |
MP_AS_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\..\mpasm" |
MP_LD_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin" |
MP_AR_DIR="C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin" |
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 Stuff/PIC_27J13/nbproject/configurations.xml |
---|
12,10 → 12,9 |
<itemPath>spi.h</itemPath> |
<itemPath>uart.h</itemPath> |
<itemPath>oled_ssd1306.h</itemPath> |
<itemPath>Adafruit_GFX.h</itemPath> |
<itemPath>oled_ssd1331.h</itemPath> |
<itemPath>adc.h</itemPath> |
<itemPath>xbee.h</itemPath> |
<itemPath>oled_ssd1331.h</itemPath> |
</logicalFolder> |
<logicalFolder name="LibraryFiles" |
displayName="Library Files" |
42,10 → 41,9 |
<itemPath>uart.c</itemPath> |
<itemPath>oled_ssd1306.c</itemPath> |
<itemPath>glcdfont.c</itemPath> |
<itemPath>Adafruit_GFX.c</itemPath> |
<itemPath>oled_ssd1331.c</itemPath> |
<itemPath>adc.c</itemPath> |
<itemPath>xbee.c</itemPath> |
<itemPath>oled_ssd1331.c</itemPath> |
</logicalFolder> |
<logicalFolder name="ExternalFiles" |
displayName="Important Files" |
/PIC Stuff/PIC_27J13/nfc.c |
---|
12,14 → 12,14 |
static char pn532ack[] = {0x01, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00}; |
void NFC_Init() { |
TRISCbits.TRISC1 = 1; // IRQ Pin is RC5 |
TRISCbits.TRISC2 = 0; // Reset Pin is RC2 |
NFC_IRQ_TRIS = 1; // IRQ Pin is RC5 |
NFC_RESET_TRIS = 0; // Reset Pin is RC2 |
// Reset the PN532 |
LATCbits.LATC2 = 1; |
LATCbits.LATC2 = 0; |
NFC_RESET_LAT = 1; |
NFC_RESET_LAT = 0; |
Delay10TCYx(1); |
LATCbits.LATC2 = 1; |
NFC_RESET_LAT = 1; |
} |
// Configures the SAM (Secure Access Module) |
406,7 → 406,7 |
// Checks the IRQ pin to know if the PN532 is ready |
unsigned char NFC_I2C_Read_Status() { |
if (PORTCbits.RC1 == 1) { |
if (NFC_IRQ_PORT == 1) { |
return PN532_I2C_BUSY; |
} else { |
return PN532_I2C_READY; |
/PIC Stuff/PIC_27J13/oled_ssd1306.c |
---|
2,12 → 2,17 |
#include "oled_ssd1306.h" |
#include "spi.h" |
#include "string.h" |
#include "Adafruit_GFX.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 |
#ifdef GFX_SSD1306 |
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, |
76,19 → 81,37 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
#endif |
}; |
#else |
static unsigned char *LCD_Buffer; |
#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() { |
GFX_Init(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT); |
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 |
LATBbits.LATB6 = 0; |
SPI_RESET_LAT = 0; |
Delay10KTCYx(1); |
LATBbits.LATB6 = 1; |
SPI_RESET_LAT = 1; |
#if defined SSD1306_128_32 |
// Init sequence for 128x32 OLED module |
171,13 → 194,13 |
void SSD1306_Command(unsigned char cmd) { |
unsigned char c = cmd; |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(&c, 1); |
} |
void SSD1306_Data(unsigned char data) { |
unsigned char c = data; |
LATBbits.LATB5 = 1; // D/C high (data) |
SPI_DC_SELECT_LAT = 1; // D/C high (data) |
SPI2_Write(&c, 1); |
} |
201,7 → 224,7 |
SSD1306_Command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 |
SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // line #0 |
LATBbits.LATB5 = 1; // D/C high (data) |
SPI_DC_SELECT_LAT = 1; // D/C high (data) |
SPI2_Write(LCD_Buffer, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8); |
// if (SSD1306_LCDHEIGHT == 32) { |
210,13 → 233,13 |
} |
void SSD1306_Draw_Pixel(int x, int y, unsigned int color) { |
if ((x < 0) || (x >= GFX_width()) || (y < 0) || (y >= GFX_height())) |
if ((x < 0) || (x >= ssd1306_data_p->_width) || (y < 0) || (y >= ssd1306_data_p->_height)) |
return; |
// check rotation, move pixel around if necessary |
switch (GFX_getRotation()) { |
switch (ssd1306_data_p->rotation) { |
case 1: |
GFX_Swap(&x, &y); |
SSD1306_Swap(&x, &y); |
x = SSD1306_LCDWIDTH - x - 1; |
break; |
case 2: |
224,7 → 247,7 |
y = SSD1306_LCDHEIGHT - y - 1; |
break; |
case 3: |
GFX_Swap(&x, &y); |
SSD1306_Swap(&x, &y); |
y = SSD1306_LCDHEIGHT - y - 1; |
break; |
} |
236,17 → 259,451 |
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; |
GFX_setTextSize(1); |
GFX_setTextColor(SSD1306_WHITE); |
GFX_setCursor(0, 0); |
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; |
GFX_write(i); |
SSD1306_Write(i); |
// if ((i > 0) && (i % 21 == 0)) |
// GFX_write('\n'); |
// SSD1306_write('\n'); |
} |
SSD1306_Display(); |
} |
253,8 → 710,8 |
void SSD1306_Test_DrawCircle() { |
int i; |
for (i = 0; i < GFX_height(); i += 2) { |
GFX_drawCircle(GFX_width() / 2, GFX_height() / 2, i, SSD1306_WHITE); |
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(); |
} |
} |
261,8 → 718,8 |
void SSD1306_Test_DrawRect(void) { |
int i; |
for (i = 0; i < GFX_height() / 2; i += 2) { |
GFX_drawRect(i, i, GFX_width() - 2 * i, GFX_height() - 2 * i, SSD1306_WHITE); |
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(); |
} |
} |
270,9 → 727,9 |
void SSD1306_Test_FillRect(void) { |
unsigned char color = 1; |
int i; |
for (i = 0; i < GFX_height() / 2; i += 3) { |
for (i = 0; i < ssd1306_data_p->_height / 2; i += 3) { |
// alternate colors |
GFX_fillRect(i, i, GFX_width() - i * 2, GFX_height() - i * 2, color % 2); |
SSD1306_Fill_Rect(i, i, ssd1306_data_p->_width - i * 2, ssd1306_data_p->_height - i * 2, color % 2); |
SSD1306_Display(); |
color++; |
} |
280,11 → 737,11 |
void SSD1306_Test_DrawTriangle(void) { |
int i; |
int min = GFX_width() < GFX_height() ? GFX_width() : GFX_height(); |
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) { |
GFX_drawTriangle(GFX_width() / 2, GFX_height() / 2 - i, |
GFX_width() / 2 - i, GFX_height() / 2 + i, |
GFX_width() / 2 + i, GFX_height() / 2 + i, SSD1306_WHITE); |
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(); |
} |
} |
292,11 → 749,11 |
void SSD1306_Test_FillTriangle(void) { |
unsigned char color = SSD1306_WHITE; |
int i; |
int min = GFX_width() < GFX_height() ? GFX_width() : GFX_height(); |
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) { |
GFX_fillTriangle(GFX_width() / 2, GFX_height() / 2 - i, |
GFX_width() / 2 - i, GFX_height() / 2 + i, |
GFX_width() / 2 + i, GFX_height() / 2 + i, SSD1306_WHITE); |
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(); |
305,8 → 762,8 |
void SSD1306_Test_DrawRoundRect(void) { |
int i; |
for (i = 0; i < GFX_height() / 2 - 2; i += 2) { |
GFX_drawRoundRect(i, i, GFX_width() - 2 * i, GFX_height() - 2 * i, GFX_height() / 4, SSD1306_WHITE); |
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(); |
} |
} |
314,8 → 771,8 |
void SSD1306_Test_FillRoundRect(void) { |
unsigned char color = SSD1306_WHITE; |
int i; |
for (i = 0; i < GFX_height() / 2 - 2; i += 2) { |
GFX_fillRoundRect(i, i, GFX_width() - 2 * i, GFX_height() - 2 * i, GFX_height() / 4, color); |
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(); |
324,45 → 781,45 |
void SSD1306_Test_DrawLine(void) { |
int i; |
for (i = 0; i < GFX_width(); i += 4) { |
GFX_drawLine(0, 0, i, GFX_height() - 1, SSD1306_WHITE); |
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 < GFX_height(); i += 4) { |
GFX_drawLine(0, 0, GFX_width() - 1, i, SSD1306_WHITE); |
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 < GFX_width(); i += 4) { |
GFX_drawLine(0, GFX_height() - 1, i, 0, SSD1306_WHITE); |
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 = GFX_height() - 1; i >= 0; i -= 4) { |
GFX_drawLine(0, GFX_height() - 1, GFX_width() - 1, i, SSD1306_WHITE); |
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 = GFX_width() - 1; i >= 0; i -= 4) { |
GFX_drawLine(GFX_width() - 1, GFX_height() - 1, i, 0, SSD1306_WHITE); |
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 = GFX_height() - 1; i >= 0; i -= 4) { |
GFX_drawLine(GFX_width() - 1, GFX_height() - 1, 0, i, SSD1306_WHITE); |
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 < GFX_height(); i += 4) { |
GFX_drawLine(GFX_width() - 1, 0, 0, i, SSD1306_WHITE); |
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 < GFX_width(); i += 4) { |
GFX_drawLine(GFX_width() - 1, 0, i, GFX_height() - 1, SSD1306_WHITE); |
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 Stuff/PIC_27J13/oled_ssd1306.h |
---|
16,8 → 16,8 |
appropriate size |
-----------------------------------------------------------------------*/ |
// #define SSD1306_128_64 |
#define SSD1306_128_32 |
#define SSD1306_128_64 |
// #define SSD1306_128_32 |
/*=========================================================================*/ |
#if defined SSD1306_128_64 |
29,6 → 29,8 |
#define SSD1306_LCDHEIGHT 32 |
#endif |
#define SSD1306_STRING_BUFFER_SIZE 32 |
#define SSD1306_BLACK 0 |
#define SSD1306_WHITE 1 |
58,6 → 60,21 |
#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); |
67,8 → 84,39 |
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); |
/PIC Stuff/PIC_27J13/oled_ssd1331.c |
---|
2,11 → 2,35 |
#include "oled_ssd1331.h" |
#include "spi.h" |
#include "string.h" |
#include "Adafruit_GFX.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() { |
GFX_Init(SSD1331_LCDWIDTH, SSD1331_LCDHEIGHT); |
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() { |
13,9 → 37,9 |
unsigned char buffer[37]; |
// Toggle reset pin |
LATBbits.LATB6 = 0; |
SPI_RESET_LAT = 0; |
Delay10KTCYx(1); |
LATBbits.LATB6 = 1; |
SPI_RESET_LAT = 1; |
// Initialization Sequence |
buffer[0] = SSD1331_CMD_DISPLAYOFF; // 0xAE |
60,7 → 84,7 |
buffer[35] = 0x7D; |
buffer[36] = SSD1331_CMD_DISPLAYON; //--turn on oled panel |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(buffer, 37); |
} |
77,34 → 101,45 |
buffer[4] = (y); // Start y address |
buffer[5] = (SSD1331_LCDHEIGHT - 1); // End y address |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(buffer, 6); |
} |
void SSD1331_Reset() { |
} |
void SSD1331_Command(unsigned char cmd) { |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(&cmd, 1); |
} |
void SSD1331_Data(unsigned char data) { |
LATBbits.LATB5 = 1; // D/C high (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 >= GFX_width()) || (y < 0) || (y >= GFX_height())) return; |
if ((x < 0) || (x >= ssd1331_data_p->_width) || (y < 0) || (y >= ssd1331_data_p->_height)) return; |
// check rotation, move pixel around if necessary |
switch (GFX_getRotation()) { |
switch (ssd1331_data_p->rotation) { |
case 1: |
GFX_Swap(&x, &y); |
SSD1331_Swap(&x, &y); |
x = SSD1331_LCDWIDTH - x - 1; |
break; |
case 2: |
112,7 → 147,7 |
y = SSD1331_LCDHEIGHT - y - 1; |
break; |
case 3: |
GFX_Swap(&x, &y); |
SSD1331_Swap(&x, &y); |
y = SSD1331_LCDHEIGHT - y - 1; |
break; |
} |
120,7 → 155,7 |
SSD1331_GoTo(x, y); |
// setup for data |
LATBbits.LATB5 = 1; // D/C high (data) |
SPI_DC_SELECT_LAT = 1; // D/C high (data) |
SPI2_Write(buffer, 2); |
} |
129,10 → 164,10 |
unsigned char buffer[8]; |
// check rotation, move pixel around if necessary |
switch (GFX_getRotation()) { |
switch (ssd1331_data_p->rotation) { |
case 1: |
GFX_Swap(&x0, &y0); |
GFX_Swap(&x1, &y1); |
SSD1331_Swap(&x0, &y0); |
SSD1331_Swap(&x1, &y1); |
x0 = SSD1331_LCDWIDTH - x0 - 1; |
x1 = SSD1331_LCDWIDTH - x1 - 1; |
break; |
143,8 → 178,8 |
y1 = SSD1331_LCDHEIGHT - y1 - 1; |
break; |
case 3: |
GFX_Swap(&x0, &y0); |
GFX_Swap(&x1, &y1); |
SSD1331_Swap(&x0, &y0); |
SSD1331_Swap(&x1, &y1); |
y0 = SSD1331_LCDHEIGHT - y0 - 1; |
y1 = SSD1331_LCDHEIGHT - y1 - 1; |
break; |
181,16 → 216,24 |
buffer[6] = (color >> 5) & 0x3F; |
buffer[7] = (color << 1) & 0x3F; |
LATBbits.LATB5 = 0; // D/C low (cmd) |
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 (GFX_getRotation()) { |
switch (ssd1331_data_p->rotation) { |
case 0: |
x0 = tx0; |
y0 = ty0; |
253,7 → 296,7 |
buffer[11] = 0; |
buffer[12] = 0; |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(buffer, 13); |
} |
262,7 → 305,7 |
int x0,y0,x1,y1; |
// check rotation, move pixel around if necessary |
switch (GFX_getRotation()) { |
switch (ssd1331_data_p->rotation) { |
case 0: |
x0 = tx0; |
y0 = ty0; |
325,27 → 368,341 |
buffer[11] = (color >> 5) & 0x3F; |
buffer[12] = (color << 1) & 0x3F; |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI_DC_SELECT_LAT = 0; // D/C low (cmd) |
SPI2_Write(buffer, 13); |
Delay1KTCYx(4); |
} |
void SSD1331_Clear_Display() { |
unsigned char buffer[5]; |
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; |
buffer[0] = SSD1331_CMD_CLEARWINDOW; |
buffer[1] = 0; |
buffer[2] = 0; |
buffer[3] = SSD1331_LCDWIDTH-1; |
buffer[4] = SSD1331_LCDHEIGHT-1; |
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); |
LATBbits.LATB5 = 0; // D/C low (cmd) |
SPI2_Write(buffer, 5); |
while (x < y) { |
if (f >= 0) { |
y--; |
ddF_y += 2; |
f += ddF_y; |
} |
x++; |
ddF_x += 2; |
f += ddF_x; |
Delay1KTCYx(4); |
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; |
359,49 → 716,49 |
void SSD1331_Test_DrawLines(unsigned int color) { |
int x, y; |
GFX_clearScreen(); |
for (x = 0; x < GFX_width() - 1; x += 6) { |
GFX_drawLine(0, 0, x, GFX_height() - 1, color); |
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 < GFX_height() - 1; y += 6) { |
GFX_drawLine(0, 0, GFX_width() - 1, y, color); |
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) { |
SSD1331_Draw_Line(0, 0, ssd1331_data_p->_width - 1, y, color); |
} |
GFX_clearScreen(); |
for (x = 0; x < GFX_width() - 1; x += 6) { |
GFX_drawLine(GFX_width() - 1, 0, x, GFX_height() - 1, 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 < GFX_height() - 1; y += 6) { |
GFX_drawLine(GFX_width() - 1, 0, 0, y, color); |
for (y = 0; y < ssd1331_data_p->_height - 1; y += 6) { |
SSD1331_Draw_Line(ssd1331_data_p->_width - 1, 0, 0, y, color); |
} |
GFX_clearScreen(); |
for (x = 0; x < GFX_width() - 1; x += 6) { |
GFX_drawLine(0, GFX_height() - 1, x, 0, 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 < GFX_height() - 1; y += 6) { |
GFX_drawLine(0, GFX_height() - 1, GFX_width() - 1, y, 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); |
} |
GFX_clearScreen(); |
for (x = 0; x < GFX_width() - 1; x += 6) { |
GFX_drawLine(GFX_width() - 1, GFX_height() - 1, x, 0, 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 < GFX_height() - 1; y += 6) { |
GFX_drawLine(GFX_width() - 1, GFX_height() - 1, 0, y, 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; |
GFX_clearScreen(); |
if (GFX_height() < GFX_width()) { |
for (x = 0; x < GFX_height() - 1; x += 6) { |
GFX_drawRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color); |
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 < GFX_width() - 1; x += 6) { |
GFX_drawRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color); |
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); |
} |
} |
} |
408,16 → 765,16 |
void SSD1331_Test_FillRect(unsigned int color1, unsigned int color2) { |
int x; |
GFX_clearScreen(); |
if (GFX_height() < GFX_width()) { |
for (x = GFX_height() - 1; x > 6; x -= 6) { |
GFX_fillRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color1); |
GFX_drawRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color2); |
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 = GFX_width() - 1; x > 6; x -= 6) { |
GFX_fillRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color1); |
GFX_drawRect((GFX_width() - 1) / 2 - x / 2, (GFX_height() - 1) / 2 - x / 2, x, x, color2); |
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); |
} |
} |
} |
424,9 → 781,9 |
void SSD1331_Test_DrawCircle(unsigned int radius, unsigned int color) { |
int x, y; |
for (x = 0; x < GFX_width() - 1 + radius; x += radius * 2) { |
for (y = 0; y < GFX_height() - 1 + radius; y += radius * 2) { |
GFX_drawCircle(x, y, radius, color); |
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); |
} |
} |
} |
433,9 → 790,9 |
void SSD1331_Test_FillCircle(unsigned int radius, unsigned int color) { |
unsigned char x, y; |
for (x = radius; x < GFX_width() - 1; x += radius * 2) { |
for (y = radius; y < GFX_height() - 1; y += radius * 2) { |
GFX_fillCircle(x, y, radius, color); |
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); |
} |
} |
} |
443,13 → 800,13 |
void SSD1331_Test_DrawTria(void) { |
int color = 0xF800; |
int t; |
int w = GFX_width() / 2; |
int x = GFX_height(); |
int w = ssd1331_data_p->_width / 2; |
int x = ssd1331_data_p->_height; |
int y = 0; |
int z = GFX_width(); |
GFX_clearScreen(); |
int z = ssd1331_data_p->_width; |
SSD1331_Clear_Display(); |
for (t = 0; t <= 15; t += 1) { |
GFX_drawTriangle(w, y, y, x, z, x, color); |
SSD1331_Draw_Triangle(w, y, y, x, z, x, color); |
x -= 4; |
y += 4; |
z -= 4; |
460,14 → 817,14 |
void SSD1331_Test_DrawRoundRect(void) { |
int color = 100; |
int i, t, x, y, w, h; |
GFX_clearScreen(); |
SSD1331_Clear_Display(); |
for (t = 0; t <= 4; t += 1) { |
x = 0; |
y = 0; |
w = GFX_width(); |
h = GFX_height(); |
w = ssd1331_data_p->_width; |
h = ssd1331_data_p->_height; |
for (i = 0; i <= 24; i += 1) { |
GFX_drawRoundRect(x, y, w, h, 5, color); |
SSD1331_Draw_Round_Rect(x, y, w, h, 5, color); |
x += 2; |
y += 3; |
w -= 4; |
480,23 → 837,23 |
void SSD1331_Test_MediaButtons(void) { |
// play |
GFX_clearScreen(); |
GFX_fillRoundRect(25, 10, 78, 60, 8, SSD1331_WHITE); |
GFX_fillTriangle(42, 20, 42, 60, 90, 40, SSD1331_RED); |
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 |
GFX_fillRoundRect(25, 90, 78, 60, 8, SSD1331_WHITE); |
GFX_fillRoundRect(39, 98, 20, 45, 5, SSD1331_GREEN); |
GFX_fillRoundRect(69, 98, 20, 45, 5, SSD1331_GREEN); |
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 |
GFX_fillTriangle(42, 20, 42, 60, 90, 40, SSD1331_BLUE); |
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_BLUE); |
Delay10KTCYx(100); |
// pause color |
GFX_fillRoundRect(39, 98, 20, 45, 5, SSD1331_RED); |
GFX_fillRoundRect(69, 98, 20, 45, 5, SSD1331_RED); |
SSD1331_Fill_Round_Rect(39, 98, 20, 45, 5, SSD1331_RED); |
SSD1331_Fill_Round_Rect(69, 98, 20, 45, 5, SSD1331_RED); |
// play color |
GFX_fillTriangle(42, 20, 42, 60, 90, 40, SSD1331_GREEN); |
SSD1331_Fill_Triangle(42, 20, 42, 60, 90, 40, SSD1331_GREEN); |
} |
void SSD1331_Test_Pattern(void) { |
531,7 → 888,7 |
buffer[0] = (SSD1331_BLACK >> 8); |
buffer[1] = (SSD1331_BLACK); |
} |
LATBbits.LATB5 = 1; // D/C high (data) |
SPI_DC_SELECT_LAT = 1; // D/C high (data) |
SPI2_Write(buffer, 2); |
} |
} |
/PIC Stuff/PIC_27J13/oled_ssd1331.h |
---|
3,6 → 3,7 |
#define SSD1331_LCDWIDTH 96 |
#define SSD1331_LCDHEIGHT 64 |
#define SSD1331_STRING_BUFFER_SIZE 32 |
// Select one of these defines to set the pixel color order |
#define SSD1331_COLORORDER_RGB |
49,6 → 50,22 |
#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); |
56,14 → 73,41 |
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_Clear_Display(void); |
unsigned int SSD1331_Color565(unsigned char r, unsigned char g, unsigned char b); |
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); |
/PIC Stuff/PIC_27J13/spi.c |
---|
6,40 → 6,32 |
void SPI2_Init(unsigned char speed) { |
// Set up SPI2 with specified pins |
RPINR22 = 7; // SPI2 CLK Input (Pin RB4) |
RPOR7 = 11; // SPI2 CLK Output (Pin RB4) |
RPINR22 = PPS_SPI2_CLK_IN; // SPI2 CLK Input (Pin RB4) |
PPS_SPI2_CLK_OUT = 11; // SPI2 CLK Output (Pin RB4) |
#ifndef SPI2_WRITE_ONLY |
RPINR21 = 6; // SPI2 Data Input (Pin RB3) |
RPINR21 = PPS_SPI2_MISO; // SPI2 Data Input (Pin RB3) |
#endif |
RPOR5 = 10; // SPI2 Data Output (MOSI) (Pin RB2) |
PPS_SPI2_MOSI = 10; // SPI2 Data Output (MOSI) (Pin RB2) |
TRISBbits.TRISB4 = 0; // SPI2 clock pin (Pin RB4) |
SPI_CLK_TRIS = 0; // SPI2 clock pin (Pin RB4) |
#ifndef SPI2_WRITE_ONLY |
TRISBbits.TRISB3 = 1; // SPI2 data in pin (Pin RB3)(MISO) |
SPI_MISO_TRIS = 1; // SPI2 data in pin (Pin RB3)(MISO) |
#endif |
TRISBbits.TRISB2 = 0; // SPI2 data out pin (Pin RB2)(MOSI) |
SPI_MOSI_TRIS = 0; // SPI2 data out pin (Pin RB2)(MOSI) |
TRISBbits.TRISB7 = 0; // SPI2 slave select (Pin RB7) |
LATBbits.LATB7 = 1; // SPI2 SS high (Idle) |
SPI_SLAVE_SELECT_TRIS = 0; // SPI2 slave select (Pin RB7) |
SPI_SLAVE_SELECT_LAT = 1; // SPI2 SS high (Idle) |
TRISBbits.TRISB6 = 0; // SPI2 reset (Pin RB6) |
LATBbits.LATB6 = 1; // SPI2 reset active low |
SPI_RESET_TRIS = 0; // SPI2 reset (Pin RB6) |
SPI_RESET_LAT = 1; // SPI2 reset active low |
TRISBbits.TRISB5 = 0; // SPI2 D/C select (Pin RB5) |
LATBbits.LATB5 = 0; |
SPI_DC_SELECT_TRIS = 0; // SPI2 D/C select (Pin RB5) |
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; |
// if (speed == SPI2_FOSC_4) |
// SSP2CON1bits.SSPM = 0b0000; // Clock = FOSC/4 |
// else if (speed == SPI2_FOSC_8) |
// SSP2CON1bits.SSPM = 0b1010; // Clock = FOSC/8 |
// else if (speed == SPI2_FOSC_16) |
// SSP2CON1bits.SSPM = 0b0001; // Clock = FOSC/16 |
// else |
// SSP2CON1bits.SSPM = 0b0010; // Clock = FOSC/64 |
SSP2CON1bits.CKP = 1; // Idle state for clock is a high level |
SSP2CON1bits.SSPEN = 1; // Enable MSSP module |
79,7 → 71,7 |
SSP2BUF = spi_data_p->buffer_out[spi_data_p->buffer_out_ind]; |
spi_data_p->buffer_out_ind++; |
} else { |
LATBbits.LATB2 = 1; // Bring SS line high |
SPI_SLAVE_SELECT_LAT = 1; // Bring SS line high |
spi_data_p->buffer_out_ind = 0; |
spi_data_p->buffer_out_len = 0; |
} |
95,12 → 87,12 |
for (i = 0; i < length; i++) { |
spi_data_p->buffer_out[i] = msg[i]; |
} |
LATBbits.LATB7 = 0; // Bring SS line low |
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; |
LATBbits.LATB7 = 0; |
SPI_SLAVE_SELECT_LAT = 0; |
while (i != length) { |
SSP2BUF = msg[i]; |
i++; |
119,7 → 111,7 |
tmp = SSP2BUF; |
#endif |
} |
LATBbits.LATB7 = 1; |
SPI_SLAVE_SELECT_LAT = 1; |
#endif |
} |
129,7 → 121,7 |
#else |
unsigned int i = 0; |
unsigned char tmp = 0; |
LATBbits.LATB7 = 0; |
SPI_SLAVE_SELECT_LAT = 0; |
while (i != length) { |
SSP2BUF = c; |
i++; |
148,7 → 140,7 |
tmp = SSP2BUF; |
#endif |
} |
LATBbits.LATB7 = 1; |
SPI_SLAVE_SELECT_LAT = 1; |
#endif |
} |
160,11 → 152,11 |
for (i = 0; i < length; i++) { |
spi_data_p->buffer_out[i] = 0x0; |
} |
LATBbits.LATB7 = 0; // Bring SS line low |
SPI_SLAVE_SELECT_LAT = 0; // Bring SS line low |
SSP2BUF = spi_data_p->buffer_out[0]; // Transmit first byte |
#else |
unsigned char i = 0; |
LATBbits.LATB7 = 0; |
SPI_SLAVE_SELECT_LAT = 0; |
for (i = 0; i < length; i++) { |
SSP2BUF = 0x0; |
178,7 → 170,7 |
} |
spi_data_p->buffer_in_len++; |
} |
LATBbits.LATB7 = 1; |
SPI_SLAVE_SELECT_LAT = 1; |
#endif |
} |
/PIC Stuff/PIC_27J13/uart.c |
---|
12,8 → 12,8 |
// UART1 TX RC6 |
// UART1 RX RC7 |
TRISCbits.TRISC6 = 0; // Tx pin set to output |
TRISCbits.TRISC7 = 1; // Rx pin set to input |
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 |
/PIC Stuff/PIC_27J13/uart.h |
---|
1,7 → 1,7 |
#ifndef __uart_h |
#define __uart_h |
#define MAXUARTBUF 128 |
#define MAXUARTBUF 64 |
#define UART1_BREAK_CHAR 0x0D //(CR) |
/PIC Stuff/PIC_27J13/xbee.h |
---|
1,14 → 1,8 |
#ifndef __xbee_h |
#define __xbee_h |
#define XBEE_BUFFER_SIZE 256 |
#define XBEE_BUFFER_SIZE 32 |
#define XBEE_CTS_TRIS TRISBbits.TRISB0 |
#define XBEE_RTS_TRIS TRISBbits.TRISB1 |
#define XBEE_CTS_LAT LATBbits.LATB0 |
#define XBEE_RTS_LAT LATBbits.LATB1 |
#define XBEE_CTS_PORT PORTBbits.RB0 |
// If API mode = 2 is enabled |
#define XBEE_USE_ESCAPE_CHAR |