mdowds95 / EE312

0 stars 0 forks source link

Main lab2 #1

Open mdowds95 opened 8 years ago

mdowds95 commented 8 years ago

/**

int main(void) {

//Default MCLK = 1MHz unsigned int i = 0;//set i unsigned char dialValue = 0x01; //starting led point bool switch1 = false; //beginning value of switch 1 is 0 WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

initialiseLedDial(); setSwitch();

// Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings PMM_unlockLPM5();

while(1) {

//Set value
setLedDial(dialValue);

if(GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3) == 0)
  switch1 = !(switch1); //switch cannot equal switch 1 after it is pressed (False to True, True to False)

//Refresh display (10 times for each position)
for(i = 0; i < 10; i++)
  refreshLedDial(); //required to check the value of dialValue and turn on the appropriate led

if(switch1 == false)
{
  dialValue = dialValue * 0x02; //when false multiply led value by 2
  if(0x00 == dialValue) //if led reaches out of bounds area it restarts at led 1
     dialValue = 0x01;
}

if (switch1 == true)
{
  dialValue = dialValue / 0x02; //when true divide led value by 2
  if(0x00 == dialValue)  //if led reaches out of bounds area it restarts at led 8
     dialValue = 0x80;
} 

} } /*int main(void) { //Default MCLK = 1MHz

unsigned int i = 0; unsigned char dialValue = 0x01; unsigned int dialGoingCW = 1; unsigned char pinState; unsigned char lastPinState=1;

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

initialiseLedDial(); //boolean for switch toggle // bool clockwise = false;

GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1,GPIO_PIN3);

// Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings PMM_unlockLPM5();

while(1) { //test button state pinState = GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3);

if (1==lastPinState)
{
  if(0 == pinState)
  {
    dialGoingCW=!dialGoingCW;
    __delay_cycles(1000000);
  }
}
lastPinState=pinState;

//update value
if(1==dialGoingCW)
  dialValue=(dialValue>>1)|(dialValue<<7); //rotate clockwise

else
  dialValue=(dialValue>>1)|(dialValue<<7); //rotate counterclcokwise

  dialValue = dialValue * 0x02;

  if(0x00 == dialValue)
     dialValue = 0x01;

//Set value
setLedDial(dialValue);

//Refresh display (10 times for each position)
for(i = 0; i < 10; i++)
  refreshLedDial();

/ / //while(1) //{ //if statement for if the switch is pressed if(GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3) == 0) { clockwise = !(clockwise); } //if switch isn't pressed, led ring operates as before if(clockwise == false) { //set all led's off refreshLedDial(dialValue); //set led of dialvalue on setLED(dialValue); //multiply dial value by two to move the led number along //1 will move to the left in hex value dialValue = dialValue * 0x02; //if value is 0, replace with 1 if(0x00 == dialValue) dialValue = 0x01; //set all led's off again refreshLedDial(dialValue); } //else statement for if switch is pressed else { //set all led's off refreshLedDial(dialValue); //set led of dialvalue on setLED(dialValue); //to reverse the order, divide by 2 rather than multiply dialValue = dialValue / 0x02; //now if hex value is 0 we replace it with led 5 if(0x00 == dialValue) dialValue = 0x80; //switch all led's off refreshLedDial(dialValue);

}

} */