//MCP3004 4-chanell SPI 10bit ADC...(only 8bits used) void SPIADCworker(void) { unsigned char token, instruction, chanel, fInst=0,fb=0,bf=0; initSPI(); SSP2BUF = 0xFD; enableTS; while (1) { while(PORTCbits.RC0 ==0)//CS LOW { if(SSP2STATbits.BF) // we received something :) { SSP2STATbits.BF=0; bf=1; if(fb==0) { if(SSP2BUF==1)fb=1; SSP2BUF=0; } else if(fb==1) { chanel = SSP2BUF &0b00110000; chanel = chanel>>4; SSP2BUF = getADC(chanel); } } }
int main(void) { uint8_t *val; USART_INIT(51); USART_SENDSTRING("PROGRAM STARTED"); initSPI(); receive_init(); DDRD |= (1<<LEDPin); //Set LEDPin as Output while(1) { USART_TRANSMIT(GetReg(CONFIG)); USART_TRANSMIT(GetReg(STATUS)); receive_data(); if(((GetReg(STATUS) & (1<<6)) != 0 )) { PORTD |= (1<<LEDPin); _delay_ms(100); PORTD &= ~(1<<LEDPin); val = WriteToNrf(R,R_RX_PAYLOAD,val,5); for(int i=0;i<5;i++) { USART_TRANSMIT(val[i]); } } reset(); } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //initialize LCD initSPI(); LCDinit(); LCDclear(); //Write to LCD while(1) { write(Message1, 8); Line2(); write(Message2,8); _delay_cycles(100000); scroll(Message1, MessageSize1); scroll(Message2, MessageSize2); LCDclear(); } return 0; }
/* ************************************************************************** */ uint16_t LSM9DS0_begin_adv( stLSM9DS0_t * stThis, gyro_scale gScl, accel_scale aScl, mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR ) { // Default to 0xFF to indicate status is not OK uint8_t gTest = 0xFF; uint8_t xmTest = 0xFF; byte byDatas; byte byAddress = 0x1D; byte bySubAddress = 0x0F; // Wiat for a few millis at the beginning for the chip to boot WAIT1_Waitms( 200 ); // Store the given scales in class variables. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. stThis->gScale = gScl; stThis->aScale = aScl; stThis->mScale = mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(stThis); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(stThis); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(stThis); // Calculate g / ADC tick, stored in aRes variable // Now, initialize our hardware interface. if (stThis->interfaceMode == MODE_I2C) // If we're using I2C initI2C(stThis); // Initialize I2C else if (stThis->interfaceMode == MODE_SPI) // else, if we're using SPI initSPI(stThis); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. gTest = gReadByte( stThis, WHO_AM_I_G ); // Read the gyro WHO_AM_I xmTest = xmReadByte( stThis, WHO_AM_I_XM ); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(stThis); // This will "turn on" the gyro. Setting up interrupts, etc. LSM9DS0_setGyroODR(stThis, gODR); // Set the gyro output data rate and bandwidth. LSM9DS0_setGyroScale(stThis, stThis->gScale); // Set the gyro range // Accelerometer initialization stuff: initAccel(stThis); // "Turn on" all axes of the accel. Set up interrupts, etc. LSM9DS0_setAccelODR(stThis, aODR); // Set the accel data rate. LSM9DS0_setAccelScale(stThis, stThis->aScale); // Set the accel range. // Magnetometer initialization stuff: initMag(stThis); // "Turn on" all axes of the mag. Set up interrupts, etc. LSM9DS0_setMagODR(stThis, mODR); // Set the magnetometer output data rate. LSM9DS0_setMagScale(stThis, stThis->mScale); // Set the magnetometer's range. // Once everything is initialized, return the WHO_AM_I registers we read: return (xmTest << 8) | gTest; }
//MCP4801 SPI DAC.. void SPIDACworker(void) { unsigned char token, instruction, fInst=0,fb=0,bf=0; initSPI(); SSP2BUF = 0xFD; enableDAC(); //DACOE =0; while (1) { while(PORTCbits.RC0 ==0)//CS LOW { if(SSP2STATbits.BF) // we received something :) { bf=1; if(fb) { setDAC(SSP2BUF); } else { fb=1; if(SSP2BUF&0b00010000)DACOE =1;//DAC on else DACOE =0; //DACoff } SSP2BUF = DACCON1&0x1F; } } if(bf) //CS HIGH { fb=0; bf=0; } } }
//Initialize the green led pin as output void swdInit() { if(isInit) return; initSPI(); isInit = true; }
/* * all board type specific initializations done here. * */ initBrdSpecific(int bringup_mode) { XYZshims[0] = XYZshims[1] = XYZshims[2]; initSPI(); /* initialize SPI to proper configuration */ startGradParser(GRADPARSER_TASK_PRIORITY, STD_TASKOPTIONS, STD_STACKSIZE); set_register(GRADIENT,FIFOECCCalcSelect,3); gradCmdPubPatternSub(); startShimRestorer(200,STD_TASKOPTIONS, STD_STACKSIZE); }
void SPIPWMworker(void) { unsigned char token, instruction, fInst=0,fb=0,bf=0; initSPI(); SSP2BUF = 0xFD; enablePWM(); while (1) { while(PORTCbits.RC0 ==0)//CS LOW { if(SSP2STATbits.BF) // we received something :) { bf=1; if(fb==0) { token = SSP2BUF; instruction = token & SPIEEMASK; } fb=1; switch (instruction) { case 0: if(fInst) { if(fInst==1)setPeriod(SSP2BUF); fInst++; } else { fInst=1; } SSP2BUF = PWMperiod; break; case 1: if(fInst) { if(fInst==1)setDuty(SSP2BUF); fInst++; } else { fInst=1; } SSP2BUF = PWMduty; break; } } } if(bf) //CS HIGH { fb=0; bf=0; fInst = 0; } } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); LCDinit(); LCDclear(); unsigned char player = initPlayer(); init_timer(); init_buttons(); __enable_interrupt(); printPlayer(player); while(1) { player = movementCheck(player); if(LOSE == 1){ LCDclear(); print("GAME"); secondLine(); print("OVER"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(didPlayerWin(player)){ LCDclear(); print("YOU"); secondLine(); print("WON"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(GAMEOVER){ char buttonsToPoll[4] = {BIT1, BIT2, BIT3, BIT4}; while(!pollP1Buttons(buttonsToPoll, 4)){ //poll until something is pressed } TAR = 0; LOSE = 0; TIMER = 0; GAMEOVER = 0; LCDclear(); player = initPlayer(); printPlayer(player); } } return 0; }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); // same as asm lab LCDinit(); LCDCLR(); doWork(); // put the bulk of the main work in lcd.c to keep main.c concise return 0; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; player = initPlayer(); initSPI(); LCDinit(); LCDclear(); RenewGame(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if (player==0xC7) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gamedone = 1; _delay_cycles(1000000); } if (CountTimer >=4) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over"); gamedone = 1; _delay_cycles(1000000); } } return 0; }
int main(void){ WDTCTL = WDTPW | WDTHOLD; char message[] = "ECE 382 is my favorite class! "; char message2[]= "I got 99 problems... but a git ain't one. "; initSPI(); LCDinit(); LCDclear(); cursorToLineOne(); scrollString(message,message2); while (1){}; }
/*Author: Travis Schriner * Date 21 Oct 2013 * Description: This program interacts with the * LCD in the geekbox and allows me to write to it * */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); LCDinit(); LCDclear(); char *topMessage = "ECE382 is my Favorite Class!"; char *prompt = "Message?"; char *promptKey = "Press123"; char *message1 = "This is message 1 fool!"; char *message2 = "This is message 2 fool!"; char *message3 = "This is message 3 fool!"; cursorToLineOne(); writeString(prompt); cursorToLineTwo(); writeString(promptKey); configureP1PinAsButton(BIT1|BIT2|BIT3); // configure pins 1, 2, and 3 as buttons P1DIR |= BIT0|BIT6; // set launchpad LEDs to output char buttons[] = {BIT1, BIT2, BIT3}; char pressedButton = pollP1Buttons(buttons, 3); switch (pressedButton) { case BIT1: waitForP1ButtonRelease(BIT1); scrollString(topMessage, message1); break; case BIT2: waitForP1ButtonRelease(BIT2); scrollString(topMessage, message2); break; case BIT3: waitForP1ButtonRelease(BIT3); scrollString(topMessage, message3); break; } while(1){ } }
void SPIworker(void) { unsigned char temp; initSPI(); while(1) { if(SSP2STATbits.BF) // we received something :) { temp=SSP2BUF; SSP2BUF=temp; //echo back } } }
int main(void) { initSPI(); // initUART(); while(1) { delayUs(1000); sendByte('c'); } return 0; }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Create strings of text to output to the user char * requiredMsg = "ECE382 is my favorite class! "; char * prompt = "Message?"; char * promptKey = "Press123"; char * message1 = "Learn from yesterday... "; char * message2 = "Live for today... "; char * message3 = "Hope for tomorrow. "; //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Position the cursor to write the prompt to the user. cursorToLineOne(); writeString(prompt); cursorToLineTwo(); writeString(promptKey); int buttonPushed = 0; //A different value is returned depending on which button is pushed. buttonPushed = pollButton(); //Move the selected message to the screen if (buttonPushed == 1) { scrollString(requiredMsg, message1); } if (buttonPushed == 2) { scrollString(requiredMsg, message2); } if (buttonPushed == 3) { scrollString(requiredMsg, message3); } return 0; }
int main (void) { trace_puts (PROJNAME); initIO(); initIRQ(); initDWT(); initSPI(); PCD8544_Init (0x38); char buf[25]; struct time_types tm; uint8_t x, y; PCD8544_GotoXY (0, 0); PCD8544_Puts ("SirVolta's", PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + PCD8544_CHAR5x7_HEIGHT + 1); PCD8544_Puts ("Library", PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT * 2) + 1); PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) - (PCD8544_CHAR5x7_HEIGHT / 2)); PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT + 3)); for (uint8_t i = 10; i > 2; i -= 2) PCD8544_DrawCircle(65, 10, i, PCD8544_Pixel_Set); PCD8544_DrawFilledCircle(65, 10, 2, PCD8544_Pixel_Set); PCD8544_Refresh (); PCD8544_GetXY(&x, &y); while (1) { GPIO_ToggleBits(LEDPORT, LEDPIN); delayMs(1000); tm.seconds = (uint32_t)(uptime_ms / 1000); secondsToTime(&tm); sprintf(buf, "%.2lud%.2luh%.2lum%.2lus\n", tm.days, tm.hours, tm.minutes, tm.seconds); //clear line of text, then print it to display PCD8544_DrawFilledRectangle(x, y, x + PCD8544_WIDTH, y + PCD8544_CHAR5x7_HEIGHT, PCD8544_Pixel_Clear); PCD8544_GotoXY (x, y); PCD8544_Puts (buf, PCD8544_Pixel_Set, PCD8544_FontSize_5x7); PCD8544_Refresh (); } }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer char mainMESSAGE[] = { 'E', 'C', 'E', '3', '8', '2', ' ', 'i', 's', ' ', 'm', 'y', ' ', 'f', 'a', 'v', 'o', 'r', 'i', 't', 'e', ' ', 'c', 'l', 'a', 's', 's', '!'}; int mainMessageLength = 29; char * mainMessagePointer = &mainMESSAGE[0]; initSPI(); LCDinit(); LCDclear(); while (1) { scrollString(mainMessagePointer, mainMessagePointer, mainMessageLength); } return 0; }
void main(void) { unsigned char byte; initSPI(); while (1) { // Wert über Switch eingeben (704) byte = inportb(SWITCH_LOW); sendCharToSPI(byte); // Ausgabe an LED outportb(LED_LOW, byte); waitForKeyPress(); } }
int main() { DDRB = (1 << PB4); DDRD |= (1 << PD2)|(1 << PD3); sei(); initUSART(); initSPI(); initADC(); while(1){ if(PINB & (1 << PB2)) { SPIReset(); } } }
uint16_t begin(void) { //! Todo: don't use _xgAddress or _mAddress, duplicating memory _xgAddress = settings.device.agAddress; _mAddress = settings.device.mAddress; constrainScales(); // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(); // Calculate g / ADC tick, stored in aRes variable if (settings.device.commInterface == IMU_MODE_I2C) // If we're using I2C initI2C(); // Initialize I2C else if (settings.device.commInterface == IMU_MODE_SPI) // else, if we're using SPI initSPI(); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. uint8_t mTest = mReadByte(WHO_AM_I_M); // Read the gyro WHO_AM_I delay(DELAY * 150); uint8_t xgTest = xgReadByte(WHO_AM_I_XG); // Read the accel/mag WHO_AM_I uint16_t whoAmICombined = (xgTest << 8) | mTest; if (whoAmICombined != ((WHO_AM_I_AG_RSP << 8) | WHO_AM_I_M_RSP)) { return 0; } // Gyro initialization stuff: initGyro(); // This will "turn on" the gyro. Setting up interrupts, etc. // Accelerometer initialization stuff: initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc. // Magnetometer initialization stuff: initMag(); // "Turn on" all axes of the mag. Set up interrupts, etc. // Once everything is initialized, return the WHO_AM_I registers we read: return whoAmICombined; }
uint16_t LSM9DS0::begin(gyro_scale gScl, accel_scale aScl, mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR) { // Store the given scales in class variables. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. gScale = gScl; aScale = aScl; mScale = mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(); // Calculate g / ADC tick, stored in aRes variable // Now, initialize our hardware interface. if (interfaceMode == MODE_I2C) // If we're using I2C {} //initI2C(); // Initialize I2C else if (interfaceMode == MODE_SPI) // else, if we're using SPI initSPI(); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. uint8_t gTest = gReadByte(WHO_AM_I_G); // Read the gyro WHO_AM_I uint8_t xmTest = xmReadByte(WHO_AM_I_XM); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(); // This will "turn on" the gyro. Setting up interrupts, etc. setGyroODR(gODR); // Set the gyro output data rate and bandwidth. setGyroScale(gScale); // Set the gyro range // Accelerometer initialization stuff: initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc. setAccelODR(aODR); // Set the accel data rate. setAccelScale(aScale); // Set the accel range. // Magnetometer initialization stuff: initMag(); // "Turn on" all axes of the mag. Set up interrupts, etc. setMagODR(mODR); // Set the magnetometer output data rate. setMagScale(mScale); // Set the magnetometer's range. // Once everything is initialized, return the WHO_AM_I registers we read: return (xmTest << 8) | gTest; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog time configClocks(); configPins(); configTimerA0(); configTimerA1(); configADC10(); initSPI(); initMessage(); _enable_interrupts(); // enable global interrupts while (1) { //pack our new message GPIOUpdate(); currentUpdate(); messagePackServoValues(servoValue); } }
void RFM70::begin() { initHardware(); initSPI(); delayMs(RFM70_BEGIN_INIT_WAIT_MS); initRegisters(); #if 0 confAddrWidth(3); //max power configRfPower(3); //gain configLnaGain(1); //default mode is rx mode setMode(MODE_PRX); #endif }
int main(void) { WDTCTL = (WDTPW|WDTHOLD); player = initPlayer(); //debugging: had player defined twice, caused * to jump around alot initSPI(); LCDinit(); LCDclear(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if(player == 0xC7){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gameover = 1; _delay_cycles(100000); } if(timerCount >= 4){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over!"); gameover = 1; _delay_cycles(100000); } } return 0; }
int main(void) { initSPI(); initNRF24L01(); //initUSART(); //Init LEDs and flash once to show script running LED_DDR|=(1 << LED_RED)|(1 << LED_GREEN); // set LED pins for output LED_DDR2|=(1 << LED_BLUE); // set blue LED pin for output flashLED(); //Flash to show initiated initADC(); ADCSRA |= (1<<ADSC); // Start conversion - didn't do earlier as not all bits set //Reduce power power_timer0_disable(); power_timer1_disable(); power_timer2_disable(); power_twi_disable(); //Sleep modes set_sleep_mode(SLEEP_MODE_ADC); sleep_enable(); sleep_bod_disable(); sleep_cpu(); sleep_mode(); //Power down nrf24 // Mainloop - use asm to stop empty infinite loop being optimised out. while(1) { asm(""); } return 0; }
/** * @brief main loop for AVR chip * */ int main(void) { // ==== do initializations!! === initRBELib(); // allows printf + more to work debugUSARTInit(OUR_BAUD_RATE); // intialize USART communications printf("Starting...\n\r"); // so we know if we freeze in setup initSPI(); // initialize SPI communications initArm(); // initialize the arm' stopConveyor(); // initialize servo positions openGripper(); // ==== end initializations ==== printf("I am alive... Looking for blocks to pickup.\n\r"); // ===== main loop ==== while (1) { finiteStateMachine(); // run FSM to determine what arm needs to do serviceArm(); // allow arm to react to changes and service PID if needed } return 0; }
/** ****************************************************************************** ** \简 述 初始化MCU系统,包括看门狗、系统时钟、GPIO和各种需要的外设 ** ** \参 数 none ** \返回值 none ******************************************************************************/ void initMCU(void) { initGpio(); LED1 = LED_ON; LED2 = LED_ON; LED3 = LED_ON; LEDRED = LED_ON; LEDGRN = LED_ON; delay100ms(2); LED1 = LED_OFF; LED2 = LED_OFF; LED3 = LED_OFF; LEDRED = LED_OFF; LEDGRN = LED_OFF; initUart(); initSPI(); initButton(); UsbConfig_UsbInit(); UsbDeviceCdcCom_SetSeparator('\r'); // there is the possibility to set end of buffer by a seperator UsbDeviceCdcCom_SetEchomode(TRUE); // all input shall be echoed UsbConfig_SwitchMode(); __enable_interrupt(); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Use seed to create a random number static const char seed = 1234; //Define all of the strings that will be used in the program char * you = "YOU "; char * win = "WIN! "; char * game = "GAME "; char * over = "OVER! "; char * boom = "BOOM! "; char * space = " "; //Initialize the timer init_timer(); //Initialize the buttons init_buttons(); //Enable the interrupt __enable_interrupt(); //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Place the player at the starting location printPlayer(location); //Create random mine placement char random = prand(seed); random = prand(random); char mine1Location = 0x81 + random % 7; random = prand(random); char mine2Location = 0xC0 + random % 7; //print the first mine, and check to make sure the second mine is printed in a place that the user can still win the game printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); //during the rest of the game while (1) { //This is the end of the level - player wins! if (location == 0xC7) { print2LineMessage(you, win); //Set flag and increment to a value above 4 so that 'game over' is not printed flag = 5; increment = 5; //Reset the game for the next level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); increment = 0; } //The game is over if the player hits a mine if (location == mine1Location || location == mine2Location) { flag = 4; print2LineMessage(boom, space); __delay_cycles(444444); } //If two seconds have passed, increment the mines to move in the opposite directions of each other if (increment == 4) { clearPlayer(mine1Location); clearPlayer(mine2Location); mine1Location--; mine2Location++; printMine(mine1Location); printMine(mine2Location); increment = 0; } //If the player loses, print 'game over' if (flag == 4) { print2LineMessage(game, over); flag = 5; increment = 5; //Reset the game for a new level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); flag = 0; increment = 0; mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); } } }
// hardware init void init(void) { // setup oscillator //OSCCON=OSCCONVALUE; OSCCONbits.SPLLEN=1; //software PLL enable x4 = 32mhz OSCCONbits.IRCF = 14;//8MHZ OSCCONbits.SCS =0;// osc dettermined by fosc // setup i/o pins // setup porta PORTA=0x00; LATA=0x00; ANSELA=0x00; TRISA=0xFF; WPUA=0x00; // disable weakpullups // setup portb PORTB=0x00; LATB=0x00; ANSELB=0x00; TRISB=0xFF; WPUB=0x50; // enable pullups on Y1 and Y2 // setup portb PORTC=0x00; LATC=0x00; ANSELC=0x00; TRISC=0xD7; // everything is input, except leds WPUC=0x05; // enable pullups on X1 and X2 nWPUEN=0; // enable weakpullups on jumpers // setup PPS (sorta :)) APFCON0=0x00; APFCON1=0x00; LED1ON; LED2ON; //X is device //Y is protocol // check jumpers mode_device=0x00; mode_protocol=0x00; mode_device|=(X2<<1); mode_device|=(X1); mode_protocol|=(Y2<<1); mode_protocol|=(Y1); // protocol specific initialisation switch(mode_protocol) { case MODESPI: initSPI(); break; case MODEI2C: initI2C(); break; case MODEUART: initUART(); break; case MODEUNK: break; default: break; } LED1OFF; // enable interrupts // PEIE=1; // GIE=1; }