mdowds95 / EE312

0 stars 0 forks source link

leddriver.c testv2 #8

Open mdowds95 opened 8 years ago

mdowds95 commented 8 years ago

/** LEDDriver.c Drives LED display * Copyright 2015 University of Strathclyde ****/

include "LedDriver.h"

//Current dial value unsigned char ledValue_ = 0;

/* Initialise LED Dial, setting GPIO parameters / void initialiseLedDial() { //GPIO 2.7 GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN7);

//GPIO 5.1, 5.2, 5.3 GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN3); //Inserted by student

//GPIO 8.0 GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0); //Inserted by student ///GPIO 1.3 GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN3, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3);

GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3);

///GPIO 1.4

GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN4, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4);

GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4);

}

void initialisepot() { GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P8, GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION); ADC_init(ADC_BASE, ADC_SAMPLEHOLDSOURCE_SC, ADC_CLOCKSOURCE_ADCOSC, ADC_CLOCKDIVIDER_1); ADC_enable(ADC_BASE); ADC_setupSamplingTimer(ADC_BASE,ADC_CYCLEHOLD_4_CYCLES,ADC_MULTIPLESAMPLESENABLE); ADC_configureMemory(ADC_BASE,ADC_INPUT_VEREF_N,ADC_VREFPOS_AVCC,ADC_VREFNEG_AVSS); ADC_enableInterrupt(ADC_BASE,ADC_COMPLETED_INTERRUPT); ADC_clearInterrupt(ADC_BASE, ADC_COMPLETED_INTERRUPT_FLAG); ADC_setDataReadBackFormat(ADC_BASE, ADC_UNSIGNED_BINARY);

}

void setSwitch() { GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3); }

void setLedDial(unsigned char value) //Set dial value { ledValue_ = value; }

/* Refresh the display 8 if statements, one for every LED / /

Refresh the display with value set using setLedDial()

LED ring can be throught of as an 8 bit binary display

*/

void refreshLedDial()

{ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3);

///Initialising switch for change in direction

//Start with LEDS 1 - 4

//For LED 1-4 2.7 must be set low (see lecture 2, slide 11)

GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);

//Bit 0 -> LED 1

if(ledValue_ == 0x01) //0000 0001

GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); //High for on

else

GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);

//Bit 1 -> LED 2

if(ledValue_ == 0x02) //0000 0010

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); //High for on

else

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1);

//Bit 2 -> LED 3

if(ledValue_ == 0x04) ////0000 0100

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); //High for on

else

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2);

//Bit 3 -> LED 4

if(ledValue_ == 0x08) //0000 1000

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); //High for on

else

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);

__delay_cycles(10000); //A delay to give us time to view the display

//LEDS 5 - 8

//For LED 5-8 2.7 must be set high (see lecture 2, slide 11)

GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);

//Bit 4 -> LED 8

if(ledValue_ == 0x10) //0001 0000

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); //Low for on

else

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);

///Bit 5 -> LED 7

if(ledValue_ == 0x20) //0010 0000

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); //Low for on

else

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2);

///Bit 6 -> LED 6

if(ledValue_ == 0x40) //0100 0000

GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); //Low for on

else

GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1);

///Bit 7 -> LED 5

if(ledValue_ == 0x80) //1000 0000

GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); //Low for on

else

GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);

__delay_cycles(10000); //A delay to give us time to view the display

}