/** * Initialize the I2C */ void InitI2C() { //I2C Pin Config mPORTBSetPinsDigitalOut(I2C_SCL_Pin | I2C_SDA_Pin); I2CEnable(I2C1, FALSE); //Soft reset I2C Bus by pulsing the clock line 10 times mPORTBSetBits(I2C_SCL_Pin | I2C_SDA_Pin); unsigned int i; unsigned int wait; for (i = 0; i < 20; i++) { for (wait = 0; wait < 20; wait++); mPORTBToggleBits(I2C_SCL_Pin); } mPORTBSetBits(I2C_SCL_Pin | I2C_SDA_Pin); // Configure Various I2C Options //!!!!! - Slew rate control off(High speed mode enabled), If enabled, RA0 and RA1 fail to work, see silicon errata (Microchip Hardware Bugs) I2CConfigure(I2C1, I2C_ENABLE_SLAVE_CLOCK_STRETCHING | I2C_ENABLE_HIGH_SPEED); // Set the I2C baud rate int I2C_actualClock = I2CSetFrequency(I2C1, SYS_FREQ, I2C_Clock); UART_SendString("I2C Clock: "); UART_SendInt(I2C_actualClock); UART_SendString(" Hz\n\r"); // Enable the I2C bus I2CEnable(I2C1, TRUE); while (!I2CTransmitterIsReady(I2C1)); // configure the interrupt priority for the I2C peripheral //INTSetVectorPriority(INT_I2C_1_VECTOR,INT_PRIORITY_LEVEL_3); //INTClearFlag(INT_I2C1); //INTEnable(INT_I2C1,INT_ENABLED); }
// === Thread 4 ====================================================== // just blinks static PT_THREAD (protothread4(struct pt *pt)) { PT_BEGIN(pt); while(1) { mPORTBToggleBits(BIT_0); // put a 10 microsec pulse on the debug pin with amplitude 1 PT_DEBUG_VALUE(1, 10) ; PT_YIELD_TIME_msec(wait_t2) ; // never exit while } // END WHILE(1) PT_END(pt); } // thread 4
void TOGGLE_LED(short lednumber) { switch(lednumber) { case 0: {} case 1: {} case 2: { mPORTDToggleBits(1 << lednumber); break; } case 3: {} case 4: { mPORTBToggleBits(1 << (lednumber+1)); } default: { break; } } }
void toggleLed2() { mPORTBToggleBits(BIT_9); }
void toggleLed1() { mPORTBToggleBits(BIT_8); }