Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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_PIN2 | GPIO_PIN3);
- //GPIO 8.0
- GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0);
- }
- void delayperiod()
- {
- /*
- //Select the relevant delay depending on delay_val
- int del = 0;
- for(del = 0; del < (10*delay_val); del++){
- __delay_cycles(100);
- }
- */
- /*
- switch(delay_val){
- case 1 :
- __delay_cycles(10000); //Delay 10ms
- //printf("Delay 1");
- break;
- case 2 :
- __delay_cycles(30000); //Delay 20ms
- //printf("Delay 2");
- break;
- case 3 :
- __delay_cycles(50000); //Delay 30ms
- //printf("Delay 3");
- break;
- }
- */
- }
- /**
- Refresh the display
- */
- void refreshLedDial()
- {
- //Depending on the current value of ledValue_, the corresponding LED shall light.
- switch(ledValue_){
- case 0x01 :
- //LED1
- GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3);
- delayperiod();
- break;
- case 0x02 :
- //LED2
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1);
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2 | GPIO_PIN3);
- delayperiod();
- break;
- case 0x04 :
- //LED3
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2);
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN3);
- delayperiod();
- break;
- case 0x08 :
- //LED4
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2);
- delayperiod();
- break;
- case 0x10 :
- //LED8
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2);
- delayperiod();
- break;
- case 0x20 :
- //LED7
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2);
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN3);
- delayperiod();
- break;
- case 0x40 :
- //LED6
- GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1);
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2 | GPIO_PIN3);
- delayperiod();
- break;
- case 0x80 :
- //LED5
- GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
- GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
- GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3);
- delayperiod();
- break;
- }
- }
- /*
- Set dial and delay values
- */
- void setLedDial(unsigned char value)
- {
- ledValue_ = value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement