Open mdowds95 opened 8 years ago
/**
//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
} 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
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
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
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
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
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
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
GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
}
/* TEST 1 GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 5-9)
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); __delaycycles(1000000); //Delay 10ms / /_ //Refresh lower bank (LEDs 4) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 1) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); //led6 GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 2) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 3) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 8) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 5) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 6) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 7) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 9) // GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
// GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); // __delaycycles(1000000); //Delay 10ms / /_ // TEST 2 GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
////////LED 1////////
if(ledValue_ & 0x01) //0000 0001 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
} ////////LED 2//////// if(ledValue_ & 0x02) //0000 0010 { delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIOPIN1); } ////////LED 3//////// if(ledValue & 0x04) ////0000 0100 { delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIOPIN2); } ////////LED 4//////// if(ledValue & 0x08) //0000 1000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); }
GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
////////LED 8//////// if(ledValue_ & 0x10) //0001 0000 { delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIOPIN3); } ////////LED 7//////// if(ledValue & 0x20) //0010 0000 { delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIOPIN2); } ////////LED 6//////// if(ledValue & 0x40) //0100 0000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); }
////////LED 5////////
if(ledValue_ & 0x080) //1000 0000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); }
//Refresh lower bank (LEDs 5-9) //Inserted by student __delay_cycles(1000000); //Delay 10ms
} */
/**
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
} 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
}
/* TEST 1 GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(1000000); //Delay 10ms
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); __delaycycles(1000000); //Delay 10ms / /_ //Refresh lower bank (LEDs 4) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 1) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7); //led6 GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); __delay_cycles(1000000); //Delay 10ms
//Refresh lower bank (LEDs 2) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 3) GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 8) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 5) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 6) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 7) GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
//Refresh lower bank (LEDs 9) // GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
// GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7); // __delaycycles(1000000); //Delay 10ms / /_ // TEST 2 GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
////////LED 1////////
if(ledValue_ & 0x01) //0000 0001 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
} ////////LED 2//////// if(ledValue_ & 0x02) //0000 0010 { delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIOPIN1); } ////////LED 3//////// if(ledValue & 0x04) ////0000 0100 { delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIOPIN2); } ////////LED 4//////// if(ledValue & 0x08) //0000 1000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); }
GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
////////LED 8//////// if(ledValue_ & 0x10) //0001 0000 { delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3); delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIOPIN3); } ////////LED 7//////// if(ledValue & 0x20) //0010 0000 { delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2); delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIOPIN2); } ////////LED 6//////// if(ledValue & 0x40) //0100 0000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1); __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1); }
////////LED 5////////
if(ledValue_ & 0x080) //1000 0000 { __delay_cycles(100000); //Delay 10ms GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0); __delay_cycles(100000); //Delay 10ms GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0); }
//Refresh lower bank (LEDs 5-9) //Inserted by student __delay_cycles(1000000); //Delay 10ms
} */