mdowds95 / EE312

0 stars 0 forks source link

lab4 main testv2 #7

Open mdowds95 opened 8 years ago

mdowds95 commented 8 years ago

/**

EE312 Lab 2 Copyright 2015 University of Strathclyde * \ **/

include "LedDriver.h"

bool SW1interruptFlag;//true/false //unsigned int SW2interruptFlag = 0;//starting number unsigned int speedvalue_;

pragma vector = PORT1_VECTOR//lecture notes

__interrupt void P1_ISR(void) { switch(__even_in_range(P1IV,P1IV_P1IFG7)) { case P1IV_P1IFG3: //It is SW1 SW1interruptFlag = !SW1interruptFlag;//interrupt sw1 cannot equal interrupt sw1 1 after it is pressed (False to True, True to False)

GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3); break;

//case P1IV_P1IFG4: //It is SW2 //SW2interruptFlag = ++SW2interruptFlag;//interrupt increments through 3 options for SW2 //if(SW2interruptFlag == 3)//if sw2 is pressed 3rd time it returns to 0 //{ //SW2interruptFlag = 0; //} //GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4); //break; } //clear the interrupt GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3 );//removed | GPIO_PIN4 }

// acdctl0 is 0010 acdctl1 0200 in hex , acdctl2 0x0014, configure memory adcmctl0 0x09, ENABLE THE INTTERUPTS // THIS WILL SET IT UP //IN MAIN LOOP ADD ADCENC|ADCSC

//ADC interrupt service routine

pragma vector=ADC_VECTOR // these two lines are used by IAR and CCC

__interrupt void ADC_ISR(void) { switch(__even_in_range(ADCIV,ADCIV_ADCIFG)) { case ADCIVADCIFG: // conversion complete speedvalue= ADC_getResults( ADC_BASE);
break; } }

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

unsigned int i = 0;// initial i value unsigned char dialValue = 0x01; //starting point for leds WDTCTL = WDTPW | WDTHOLD; //stop watchdog timer

initialiseLedDial(); __enable_interrupt();

PMM_unlockLPM5();

while(1) {

ADC_startConversion(ADC_BASE, ADC_SINGLECHANNEL);

if(SW1interruptFlag == 1) dialValue = (dialValue<<1) | (dialValue>>7); //clockwise

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

//while(GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3) == 0) //{ //to correct bouncing //}

/* if(SW2interruptFlag == 0)//first option/speed speedvalue_ = 25;

else if(SW2interruptFlag == 1)//second option/speed speedvalue_ = 15;

else if(SW2interruptFlag == 2)//third option/speed speedvalue_ = 5; */ //Set value setLedDial(dialValue);

for(i=0; i < speedvalue_/10; i++)//run through each i value to change speed refreshLedDial();

} }