예제 #1
0
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;
    
    // do your TRIS and LAT commands here
    TRISAbits.TRISA4=0;
    TRISBbits.TRISB4=1;
    //spi_init();
    i2c_master_setup();
   // readaddress();
    init_OC();
    setlsm(0x10,0b10000000);
    setlsm(0x11,0b10000000);
    setlsm(0x12,0b00000100);
   // i2c_readmulti();
    __builtin_enable_interrupts();
    
    LATAbits.LATA4=0;    
     while(1){
        _CP0_SET_COUNT(0);
        //LATAINV = 0x10; // make sure timer2 works
        /*
        if(PORTBbits.RB4==0)
        {
            if(read == 0x69)
            LATAbits.LATA4=1;
            else
            LATAbits.LATA4=0;
        }
        else
        LATAbits.LATA4=0;
         */
        while(_CP0_GET_COUNT() < 480000) { 
            ;
        }
i2c_readmulti();
    }   
}
예제 #2
0
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;   
    
}