EDF - OnePIC MCU  v1.1.0
source/base/OnePIC_led.c
Go to the documentation of this file.
00001 
00009 #include "OnePIC_led.h"
00010 #include "Compiler.h"
00011 #include "bsp.h"
00012 
00016 void EDF_LEDInit()
00017 {
00018 
00019     gpLED_8_TRIS = 0;
00020     gpLED_7_TRIS = 0;
00021     gpLED_6_TRIS = 0;
00022     gpLED_5_TRIS = 0;
00023     gpLED_4_TRIS = 0;
00024     gpLED_3_TRIS = 0;
00025     gpLED_2_TRIS = 0;
00026     gpLED_1_TRIS = 0;
00027 
00028     gpLED_UP_TRIS    = 0;
00029     gpLED_DOWN_TRIS  = 0;
00030     gpLED_RIGHT_TRIS = 0;
00031     gpLED_LEFT_TRIS  = 0;
00032 }
00033 
00040 static void EDF_LEDMod(EDF_LED d, uint8_t s)
00041 {
00042    
00043     switch(d)
00044     {
00045         case LED_UP:    gpLED_UP     = s; break;
00046         case LED_DOWN:  gpLED_DOWN   = s; break;
00047         case LED_LEFT:  gpLED_LEFT   = s; break;
00048         case LED_RIGHT: gpLED_RIGHT  = s; break;
00049         case LED_1:     gpLED_1      = s; break;
00050         case LED_2:     gpLED_2      = s; break;
00051         case LED_3:     gpLED_3      = s; break;
00052         case LED_4:     gpLED_4      = s; break;
00053         case LED_5:     gpLED_5      = s; break;
00054         case LED_6:     gpLED_6      = s; break;
00055         case LED_7:     gpLED_7      = s; break;
00056         case LED_8:     gpLED_8      = s; break;
00057         default: break;
00058     }
00059 }
00060 
00065 void EDF_LEDSet(EDF_LED d) 
00066 { 
00067     EDF_LEDMod(d,LED_ON);
00068 }
00069 
00074 void EDF_LEDClr(EDF_LED d) 
00075 { 
00076     EDF_LEDMod(d,LED_OFF);
00077 }
00078 
00084 void EDF_pot2bar(uint16_t n)
00085 {
00086   //  if(n < 1024 && n >= 896)     { EDF_LEDBarSet(0xFF); }
00087   //  else if(n < 896 && n >= 768) { EDF_LEDBarSet(0x7F); }
00088     if(n < 1024 && n >= 850) { EDF_LEDBarSet(0x3F); }
00089     else if(n < 850 && n >= 680) { EDF_LEDBarSet(0x1f); }
00090     else if(n < 680 && n >= 510) { EDF_LEDBarSet(0x0F); }
00091     else if(n < 510 && n >= 240) { EDF_LEDBarSet(0x07); }
00092     else if(n < 340 && n >= 170) { EDF_LEDBarSet(0x03); }
00093     else if(n < 170 && n > 5)    { EDF_LEDBarSet(0x01); }
00094     else if(n <= 5) {EDF_LEDBarSet(0x00); }
00095 }
00096 
00102 void EDF_LEDBarSet(uint8_t bf)
00103 {
00104     if((bf&0x80)!=0){ EDF_LEDSet(LED_8); } else { EDF_LEDClr(LED_8); }
00105     if((bf&0x40)!=0){ EDF_LEDSet(LED_7); } else { EDF_LEDClr(LED_7); }
00106     if((bf&0x20)!=0){ EDF_LEDSet(LED_6); } else { EDF_LEDClr(LED_6); }
00107     if((bf&0x10)!=0){ EDF_LEDSet(LED_5); } else { EDF_LEDClr(LED_5); }
00108     if((bf&0x08)!=0){ EDF_LEDSet(LED_4); } else { EDF_LEDClr(LED_4); }
00109     if((bf&0x04)!=0){ EDF_LEDSet(LED_3); } else { EDF_LEDClr(LED_3); }
00110     if((bf&0x02)!=0){ EDF_LEDSet(LED_2); } else { EDF_LEDClr(LED_2); }
00111     if((bf&0x01)!=0){ EDF_LEDSet(LED_1); } else { EDF_LEDClr(LED_1); }
00112 }