Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.51 KB | None | 0 0
  1.  
  2. #include "LedDriver.h"
  3.  
  4. //Current dial value
  5. unsigned char ledValue_ = 0;
  6.  
  7. /**
  8. Initialise LED Dial, setting GPIO parameters
  9. */
  10. void initialiseLedDial()
  11. {
  12.   //GPIO 2.7
  13.   GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN7);
  14.    
  15.   //GPIO 5.1, 5.2, 5.3
  16.   GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3);
  17.    
  18.   //GPIO 8.0
  19.   GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0);
  20. }
  21.  
  22. void delayperiod()
  23. {
  24.   /*
  25.   //Select the relevant delay depending on delay_val
  26.   int del = 0;
  27.  
  28.   for(del = 0; del < (10*delay_val); del++){
  29.       __delay_cycles(100);
  30.     }
  31.   */
  32.   /*
  33.   switch(delay_val){
  34.    
  35.     case 1 :
  36.       __delay_cycles(10000);  //Delay 10ms
  37.       //printf("Delay 1");
  38.       break;
  39.     case 2 :
  40.       __delay_cycles(30000); //Delay 20ms
  41.       //printf("Delay 2");
  42.       break;
  43.     case 3 :
  44.       __delay_cycles(50000); //Delay 30ms
  45.       //printf("Delay 3");
  46.       break;
  47.   }
  48.   */
  49. }
  50.  
  51. /**
  52. Refresh the display
  53. */
  54.  
  55. void refreshLedDial()
  56. {
  57.  //Depending on the current value of ledValue_, the corresponding LED shall light.
  58.  
  59.   switch(ledValue_){
  60.    
  61.     case 0x01 :
  62.       //LED1
  63.       GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
  64.       GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
  65.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1  | GPIO_PIN2 | GPIO_PIN3);
  66.       delayperiod();
  67.       break;
  68.     case 0x02 :
  69.       //LED2
  70.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1);
  71.       GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
  72.       GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
  73.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2 | GPIO_PIN3);
  74.       delayperiod();
  75.       break;
  76.     case 0x04 :
  77.       //LED3
  78.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2);
  79.       GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
  80.       GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
  81.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN3);
  82.       delayperiod();
  83.       break;
  84.     case 0x08 :
  85.       //LED4
  86.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);
  87.       GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);
  88.       GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
  89.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2);
  90.       delayperiod();
  91.       break;
  92.     case 0x10 :
  93.       //LED8
  94.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);
  95.       GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
  96.       GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
  97.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2);
  98.       delayperiod();
  99.       break;
  100.     case 0x20 :
  101.       //LED7
  102.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2);
  103.       GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
  104.       GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
  105.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN3);
  106.       delayperiod();
  107.       break;
  108.     case 0x40 :
  109.       //LED6
  110.       GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1);
  111.       GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
  112.       GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
  113.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2 | GPIO_PIN3);
  114.       delayperiod();
  115.       break;
  116.     case 0x80 :
  117.       //LED5
  118.       GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
  119.       GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);
  120.       GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1  | GPIO_PIN2 | GPIO_PIN3);
  121.       delayperiod();
  122.       break;
  123.   }
  124.  
  125. }
  126.  
  127. /*
  128. Set dial and delay values
  129. */
  130. void setLedDial(unsigned char value)
  131. {
  132.   ledValue_ = value;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement