Lab 3/time4io/mipslabwork.c
void labwork( void )
{
  int button_status = getbtns(); //0000...0ABC
  if(button_status != 0){
    bool btn_4_status =  button_status >> 2; //000.0A
    bool btn_3_status =  (button_status >> 1) - (btn_4_status << 1); ///000.00B
    bool btn_2_status =  button_status -(btn_4_status << 2)- (btn_3_status << 1); ///000.00C

    int switch_status = getsw();
    if(btn_4_status == true){
      int maskning = mytime & 0b00000000000000000000111111111111; //0x0fff
      mytime = maskning + (switch_status << 12);
      //0b0000000000000000ABCD000000000000
      //0b00000000000000000000XXXXXXXXXXXX

      //switch_status 0000...0XYZW e.g. 0000.00100

      //mytime = 000...0EEEEFFFFGGGGHHHH
      //                       +
      //         000000000000XYZW = switch_status

     
    }

    if(btn_3_status == true){
      int maskning = mytime & 0b00000000000000001111000011111111;
      mytime = maskning + (switch_status << 8);
      //0b00000000000000000000ABCD00000000
      //0b0000000000000000XXXX0000XXXXXXXX

    }
    if(btn_2_status == true){
      int maskning = mytime & 0b00000000000000001111111100001111;
      mytime = maskning + (switch_status << 4);
      //0b000000000000000000000000ABCD0000
      //0b000000000000XXXXXXXXXXXX0000XXXX
    }

    
    
  }
  delay( 1000 );
  time2string( textstring, mytime ); //pass by reference (textstring is also a pointer to the first element in the char array)
  display_string( 3, textstring );
  display_update();
  tick( &mytime );
  num_ticks++; //increment ticks
  volatile char* p = 0xbf886110; //PORTE
  *p = num_ticks; //5 <=> 00000101 <=> 0x05
  display_image(96, icon);
}
/* This function is called repetitively from the main program */
This function is called repetitively from the main program
This function is called repetitively from the main program
void labwork( void )
{
  int button_status = getbtns(); 
  if(button_status != 0){
    bool btn_4_status =  button_status >> 2; 
    bool btn_3_status =  (button_status >> 1) - (btn_4_status << 1); 
    bool btn_2_status =  button_status -(btn_4_status << 2)- (btn_3_status << 1); 
    int switch_status = getsw();
    if(btn_4_status == true){
      int maskning = mytime & 0b00000000000000000000111111111111; 
      mytime = maskning + (switch_status << 12);
    }
    if(btn_3_status == true){
      int maskning = mytime & 0b00000000000000001111000011111111;
      mytime = maskning + (switch_status << 8);
    }
    if(btn_2_status == true){
      int maskning = mytime & 0b00000000000000001111111100001111;
      mytime = maskning + (switch_status << 4);
    }
  }
  delay( 1000 );
  time2string( textstring, mytime ); 
  display_string( 3, textstring );
  display_update();
  tick( &mytime );
  num_ticks++; 
  volatile char* p = 0xbf886110; 
  *p = num_ticks; 
  display_image(96, icon);
}
void labwork ( void ) { int button_status = getbtns ( ) ; if ( button_status != 0 ) { bool btn_4_status = button_status >> 2 ; bool btn_3_status = ( button_status >> 1 ) - ( btn_4_status << 1 ) ; bool btn_2_status = button_status - ( btn_4_status << 2 ) - ( btn_3_status << 1 ) ; int switch_status = getsw ( ) ; if ( btn_4_status == true ) { int maskning = mytime & 0b00000000000000000000111111111111 ; mytime = maskning + ( switch_status << 12 ) ; } if ( btn_3_status == true ) { int maskning = mytime & 0b00000000000000001111000011111111 ; mytime = maskning + ( switch_status << 8 ) ; } if ( btn_2_status == true ) { int maskning = mytime & 0b00000000000000001111111100001111 ; mytime = maskning + ( switch_status << 4 ) ; } } delay ( 1000 ) ; time2string ( textstring , mytime ) ; display_string ( 3 , textstring ) ; display_update ( ) ; tick ( & mytime ) ; num_ticks ++ ; volatile char * p = 0xbf886110 ; * p = num_ticks ; display_image ( 96 , icon ) ; }
This function is called repetitively from the main program
This function is called repetitively from the main program
//0000...0ABC //000.0A ///000.00B ///000.00C //0x0fff //0b0000000000000000ABCD000000000000 //0b00000000000000000000XXXXXXXXXXXX //switch_status 0000...0XYZW e.g. 0000.00100 //mytime = 000...0EEEEFFFFGGGGHHHH //                       + //         000000000000XYZW = switch_status //0b00000000000000000000ABCD00000000 //0b0000000000000000XXXX0000XXXXXXXX //0b000000000000000000000000ABCD0000 //0b000000000000XXXXXXXXXXXX0000XXXX //pass by reference (textstring is also a pointer to the first element in the char array) //increment ticks //PORTE //5 <=> 00000101 <=> 0x05