int main ( void ) { /* Initialize all MPLAB Harmony modules, including application(s). */ SYS_Initialize ( NULL ); __builtin_disable_interrupts(); // set the CP0 CONFIG register to indicate that kseg0 is cacheable (0x3) __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583); // 0 data RAM access wait states BMXCONbits.BMXWSDRM = 0x0; // enable multi vector interrupts INTCONbits.MVEC = 0x1; // disable JTAG to get pins back DDPCONbits.JTAGEN = 0; // initialize I2C initI2C2(); // initialize IMU initIMU(); // initialize SPI, LCD // SPI1_init(); // LCD_init(); __builtin_enable_interrupts(); // LCD_clearScreen(BLACK); // char message[MAX_LENGTH]; unsigned char data[14]; // float accX, accY; _CP0_SET_COUNT(0); while ( true ) { if (_CP0_GET_COUNT() > 480000) { // 50 Hz i2c_read_multiple(IMU_ADDRESS, OUT_TEMP_L, data, 14); temp_raw = data[1] << 8 | data[0]; gyroX_raw = data[3] << 8 | data[2]; gyroY_raw = data[5] << 8 | data[4]; gyroZ_raw = data[7] << 8 | data[6]; accX_raw = data[9] << 8 | data[8]; accY_raw = data[11] << 8 | data[10]; accZ_raw = data[13] << 8 | data[12]; // accX = accX_raw * 2.0 / 32768; // accel in g // accY = accY_raw * 2.0 / 32768; // accel in g // accZ = accZ_raw * 2.0 / 32768; // accel in g // sprintf(message, "temp raw: %x ", temp_raw); // LCD_drawString(10, 10, message, WHITE); // // sprintf(message, "accX: %f g ", accX); // LCD_drawString(10, 20, message, WHITE); // // sprintf(message, "accY: %f g ", accY); // LCD_drawString(10, 30, message, WHITE); // // sprintf(message, "accZ: %f g ", accZ); // LCD_drawString(10, 40, message, WHITE); // // sprintf(message, "gyroX raw: %i ", gyroX_raw); // LCD_drawString(10, 50, message, WHITE); // // sprintf(message, "gyroY raw: %i ", gyroY_raw); // LCD_drawString(10, 60, message, WHITE); // // sprintf(message, "gyroZ raw: %i ", gyroZ_raw); // LCD_drawString(10, 70, message, WHITE); _CP0_SET_COUNT(0); } /* Maintain state machines of all polled MPLAB Harmony modules. */ SYS_Tasks ( ); } /* Execution should not come here during normal operation */ return ( EXIT_FAILURE ); }
int main() { __builtin_disable_interrupts(); // set the CP0 CONFIG register to indicate that kseg0 is cacheable (0x3) __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583); // 0 data RAM access wait states BMXCONbits.BMXWSDRM = 0x0; // enable multi vector interrupts INTCONbits.MVEC = 0x1; // disable JTAG to get pins back DDPCONbits.JTAGEN = 0; __builtin_enable_interrupts(); initSPI1(); initI2C2(); i2c_master_setup(); initExpander(); //sine wave int sine[1000]; int i; for(i = 0; i < 1000; i++){ sine[i] = 128 + 127*sin(2*3.14*10*i/1000); } int triangle[1000]; i = 0; for(i = 0; i < 1000; i++){ triangle[i] = .256*i; } i = 0; while(1) { _CP0_SET_COUNT(0); if(_CP0_GET_COUNT() > 24000){ i++; setVoltage(0, sine[i]); setVoltage(1, triangle[i]); _CP0_SET_COUNT(0); } if(i > 1000){ i = 0; } char status = getExpander(); //read the expander char g7 = (status & 0x80) >> 7; //get level of pin g7 setExpander(0, g7); //set pin 0 to level of g7 } }
int main() { //int value = 0; char r; makewave(); int count1 = 0; int count2 = 0; __builtin_disable_interrupts(); // set the CP0 CONFIG register to indicate that kseg0 is cacheable (0x3) __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583); // 0 data RAM access wait states BMXCONbits.BMXWSDRM = 0x0; // enable multi vector interrupts INTCONbits.MVEC = 0x1; // disable JTAG to get pins back DDPCONbits.JTAGEN = 0; // do your TRIS and LAT commands here TRISAbits.TRISA4 = 0; // ouput TRISBbits.TRISB4 = 1; // input LATAbits.LATA4 = 1; // intialize LED on initSPI1(); initI2C2(); init_ctrl1(); init_ctrl2(); init_ctrl3(); init_OC(); __builtin_enable_interrupts(); while(1) { // use _CP0_SET_COUNT(0) and _CP0_GET_COUNT() to test the PIC timing // remember the core timer runs at half the CPU speed _CP0_SET_COUNT(0); // set core timer to 0 while(_CP0_GET_COUNT() < 480000){ // wait 1ms / 0.001s ; } while(_CP0_GET_COUNT() < 480000){ // wait 1ms / 0.001s ; } while(_CP0_GET_COUNT() < 480000){ // wait 1ms / 0.001s ; } while(_CP0_GET_COUNT() < 480000){ // wait 1ms / 0.001s ; } //setVoltage(0,sinewave[count1]); //setVoltage(1,triangle_wave[count2]); //count1++; //count2++; //if(count1 == 100){ //count1 = 0; //} //if(count2 == 200){ //count2 = 0; //} I2C_read_multiple(0x6B, 0x20, data_array, 14); }// while loop //CS = 0; // listen to me //SPI1_IO(0x38); // most significant byte of address //SPI1_IO(0x00); // the least significant address byte //CS = 1; }