#include
#include "delay.h"
// Clock Speed for delay function
#define XTAL_FREQ 4MHZ
// Manual SPI control for MAX3100
#define CS RD2 // Chip Select
#define SPI_OUT RC5 // SPI Data Out
#define SPI_IN RC4 // SPI Data In
#define SPI_CLK RC3 // SPI Clock
// Burn Configuration word
__CONFIG(XT & WDTDIS & PWRTEN & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT);
/*--------------------------------------------------------------------*
Function: main
Inputs: None (void)
Outputs: None (void)
*---------------------------------------------------------------------*/
void main(void)
{
// Local variables
char int_array[16] = {1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1}; // MAX3100 Initiate sequence 9600 baud
char cmd_array[16] = {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; // MAX3100 Command sequence: TEST MODE
int i=0; // Integer used for loop counting
// Set Clock to 0
SPI_CLK = 0;
// Setup SPI direction bits
TRISD2 = 0; // Set Chip Select as output
TRISC5 = 0; // Set SPI data out as output
TRISC4 = 1; // Set SPI data in as input
TRISC3 = 0; // Set SPI clock as output
// Send MAX3100 Initiation command
CS = 0; // Take Chip Select low
for(i=0; i<16; i++)
{
SPI_OUT = int_array[i]; // Send Array bit by bit
DelayMs(100); // Wait a bit
SPI_CLK ^= 0x0F; // Toggle clock
DelayMs(100); // Wait a bit
}
CS = 1; // Take Chip Select high
DelayMs(500); // Wait before next write
// Send MAX3100 TEST command
CS = 0; // Take Chip Select low
for(i=0; i<16; i++)
{
SPI_OUT = cmd_array[i]; // Send Array bit by bit
DelayMs(100); // Wait a bit
SPI_CLK ^= 0x0F; // Toggle clock
DelayMs(100); // Wait a bit
}
//CS = 1; // Take Chip Select high
// Loop forever
while(1);
}