Пример #1
0
int main() {
    unsigned char master_read  = 0x00; 

    __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 = 1; //set portA4 as input pin for button input
     TRISBbits.TRISB4 = 0; //set port B4 as output pin for LED
    
     
     i2c_init();
     i2c_expander_init();
     
    __builtin_enable_interrupts();
    
  
   
    
    while(1) {
        master_read = getExpander();
    if(master_read>>7 ==0x01)
   {
          setExpander(0,1);
   }else{
        
        setExpander(0,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;


    __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



    }


}