表示

2017-08-13 6 views
0

私は、次の7セグメントLCD上の温度を表示するコードを書いている:表示

LCD-H301C31TF Datasheet

私はPIC24FJ64GA006マイクロを使用しています。

PORTB [13:6]、PORTD [0:7]、PORTE [0:7]ポートピンのみを使用できます。

次のコードを置き換えるよりエレガントな方法を見つけることができますか?

void SegLCD_Set(uint8_t Value,uint8_t Digit) 
{ 
    switch(Digit) 
    { 
     case 1: 
      if(Value==0x00){ LATB = (LATB & ~(0x7F<<6)) | (0x3F<<6); } 
      if(Value==0x01){ LATB = (LATB & ~(0x7F<<6)) | (0x0C<<6); } 
      if(Value==0x02){ LATB = (LATB & ~(0x7F<<6)) | (0x5B<<6); } 
      if(Value==0x03){ LATB = (LATB & ~(0x7F<<6)) | (0x5E<<6); } 
      if(Value==0x04){ LATB = (LATB & ~(0x7F<<6)) | (0x6C<<6); } 
      if(Value==0x05){ LATB = (LATB & ~(0x7F<<6)) | (0x76<<6); } 
      if(Value==0x06){ LATB = (LATB & ~(0x7F<<6)) | (0x77<<6); } 
      if(Value==0x07){ LATB = (LATB & ~(0x7F<<6)) | (0x1C<<6); } 
      if(Value==0x08){ LATB = (LATB & ~(0x7F<<6)) | (0x7F<<6); } 
      if(Value==0x09){ LATB = (LATB & ~(0x7F<<6)) | (0x7E<<6); } 
      break; 
     case 2: 
      if(Value==0x00){ LATD = (LATD & ~(0xFF)) | (0x3F); } 
      if(Value==0x01){ LATD = (LATD & ~(0xFF)) | (0x0C); } 
      if(Value==0x02){ LATD = (LATD & ~(0xFF)) | (0x5B); } 
      if(Value==0x03){ LATD = (LATD & ~(0xFF)) | (0x5E); } 
      if(Value==0x04){ LATD = (LATD & ~(0xFF)) | (0x6C); } 
      if(Value==0x05){ LATD = (LATD & ~(0xFF)) | (0x76); } 
      if(Value==0x06){ LATD = (LATD & ~(0xFF)) | (0x77); } 
      if(Value==0x07){ LATD = (LATD & ~(0xFF)) | (0x1C); } 
      if(Value==0x08){ LATD = (LATD & ~(0xFF)) | (0x7F); } 
      if(Value==0x09){ LATD = (LATD & ~(0xFF)) | (0x7E); } 
      break; 
     case 3: 
      if(Value==0x00){ LATE = (LATE & ~(0xFF)) | (0x3F); } 
      if(Value==0x01){ LATE = (LATE & ~(0xFF)) | (0x0C); } 
      if(Value==0x02){ LATE = (LATE & ~(0xFF)) | (0x5B); } 
      if(Value==0x03){ LATE = (LATE & ~(0xFF)) | (0x5E); } 
      if(Value==0x04){ LATE = (LATE & ~(0xFF)) | (0x6C); } 
      if(Value==0x05){ LATE = (LATE & ~(0xFF)) | (0x76); } 
      if(Value==0x06){ LATE = (LATE & ~(0xFF)) | (0x77); } 
      if(Value==0x07){ LATE = (LATE & ~(0xFF)) | (0x1C); } 
      if(Value==0x08){ LATE = (LATE & ~(0xFF)) | (0x7F); } 
      if(Value==0x09){ LATE = (LATE & ~(0xFF)) | (0x7E); } 
      break; 
     default: 
      LATB = (LATB & ~(0x7F<<6)) | (0x3F<<6); 
      LATD = (LATD & ~(0xFF)) | (0x3F); 
      LATE = (LATE & ~(0xFF)) | (0x3F); 
      break; 
    }; 

}//End SegLCD_Set 

ありがとう!

+0

は、配列を使用する方法を学びます。 – stark

答えて

1

私はそれが任意のよりエレガントだかはわからないが、これは仕事ができる...

void SegLCD_Set(uint8_t Value,uint8_t Digit) 
{ 
    unsigned char values[] = {0x3f, 0x0c, 0x5b, 0x5e, 0x6c, 0x76, 0x77, 0x1c, 0x7f, 0x7e}; 
    switch(Digit) 
    { 
    case 1: 
     LATB = (LATB & ~(0x7F<<6)) | (values[Value]<<6); 
     break; 
    case 2: 
     LATD = (LATD & ~(0xFF)) | (values[Value]); 
     break; 
    case 3: 
     LATE = (LATE & ~(0xFF)) | (values[Value]); 
     break; 

    default: 
     LATB = (LATB & ~(0x7F<<6)) | (0x3F<<6); 
     LATD = (LATD & ~(0xFF)) | (0x3F); 
     LATE = (LATE & ~(0xFF)) | (0x3F); 
     break; 
    }; 
}