Rev 3460 Rev 3618
Line 12... Line 12...
12 // 12 //
13 // (c) miho 2014 http://www.mlab.cz 13 // (c) miho 2014 http://www.mlab.cz
14 // 14 //
15 // History 15 // History
16 // 2014 01 31 - First demo 16 // 2014 01 31 - First demo
-   17 // 2014 02 07 - Added support for Comon Anoda / Comon Catoda
17   18  
18   19  
19 // System Configuration 20 // System Configuration
20 #define F_CPU 4000000 // Do not forget to set FUSEs to external XTAL osc with DIV/8 off and connect xtal 21 #define F_CPU 4000000 // Do not forget to set FUSEs to external XTAL osc with DIV/8 off and connect xtal
21   22  
22 // LED Display - Configuration 23 // LED Display - Configuration
-   24 #define LED_COMON_ANODA 0 // 0=Comon Catoda / 1=Comon Anoda
23 #define LED_DIGITS_PORT C // Digits Port (common anodas) 25 #define LED_DIGITS_PORT C // Digits Port (common anodas or comon catodas)
24 #define LED_DIGITS 4 // Number of display digits (1..8) 26 #define LED_DIGITS 6 // Number of display digits (1..8)
25 #define LED_SEGMENTS_PORT D // Segments Port (catodas) 27 #define LED_SEGMENTS_PORT D // Segments Port (catodas or anodas)
26 #define LED_SEGMENTS 8 // Usualy 7 or 8 (bit 0 is A) 28 #define LED_SEGMENTS 8 // Usualy 7 or 8 (bit 0 is A)
27 #define TICKS_PER_SEC 500 // Number of interrupts per second ( >250 to look steady) 29 #define TICKS_PER_SEC 500 // Number of interrupts per second ( >250 to look steady)
28   30  
29   31  
30 // -------------- DO NOT EDIT BELOW THIS LINE -------------- 32 // -------------- DO NOT EDIT BELOW THIS LINE --------------
Line 63... Line 65...
63   65  
64 // 7 Segment Decoder 66 // 7 Segment Decoder
65 unsigned char Convert(unsigned char Number) 67 unsigned char Convert(unsigned char Number)
66 { 68 {
67 // 7 Segment Decoder Table 69 // 7 Segment Decoder Table
-   70 // A
-   71 // ---
-   72 // F| | B
-   73 // | G |
-   74 // ---
-   75 // E| | C
-   76 // | |
-   77 // --- * H
-   78 // D
68 const unsigned char Decoder[] = 79 const unsigned char Decoder[] =
69 { 80 {
70 // HGFEDCBA 81 // HGFEDCBA
71 0b00111111, // 0 82 0b00111111, // 0
72 0b00000011, // 1 83 0b00000110, // 1
73 0b01101101, // 2 84 0b01011011, // 2
74 0b01100111, // 3 85 0b01001111, // 3
75 0b01010011, // 4 86 0b01100110, // 4
76 0b01110110, // 5 87 0b01101101, // 5
77 0b01111110, // 6 88 0b01111101, // 6
78 0b00100011, // 7 89 0b00000111, // 7
79 0b01111111, // 8 90 0b01111111, // 8
-   91 0b01101111, // 9
80 0b01110111 // 9 92 0b01110111, // A
-   93 0b01111100, // b
-   94 0b00111001, // C
-   95 0b01011100, // d
-   96 0b01111001, // E
-   97 0b01110000 // F
81 }; 98 };
82   99  
83 // Decoding Function 100 // Decoding Function
84 if(Number<sizeof(Decoder)) return Decoder[Number]; else return 0; 101 if(Number<sizeof(Decoder)) return Decoder[Number]; else return 0;
85 } 102 }
Line 165... Line 182...
165 case 1: Segments = Convert(Seconds10); 182 case 1: Segments = Convert(Seconds10);
166 break; 183 break;
167 case 2: Segments = Convert(Minutes); 184 case 2: Segments = Convert(Minutes);
168 break; 185 break;
169 case 3: Segments = Convert(Minutes10); 186 case 3: Segments = Convert(Minutes10);
-   187 break;
-   188 case 4: Segments = Convert(Hours);
-   189 break;
-   190 case 5: Segments = Convert(Hours10);
-   191 break;
170 } 192 }
-   193 #if LED_COMON_ANODA==0
-   194 // LED display update - All digits off
-   195 PORT(LED_DIGITS_PORT) |= LED_DIGITS_MASK; // common catoda 1=off
-   196 // LED display update - New segments combination
-   197 PORT(LED_SEGMENTS_PORT) = (PORT(LED_SEGMENTS_PORT) & ~LED_SEGMENTS_MASK) | (Segments & LED_SEGMENTS_MASK);
-   198 // LED display update - One digit on
-   199 PORT(LED_DIGITS_PORT) &= ~(LED_DIGITS_MASK & DisplayDigitMask); // (common anoda 0=on)
171   200 #else
172 // LED display update - All digits off 201 // LED display update - All digits off
173 PORT(LED_DIGITS_PORT) &= ~LED_DIGITS_MASK; // common anoda 0=off 202 PORT(LED_DIGITS_PORT) &= ~LED_DIGITS_MASK; // common anoda 0=off
174 // LED display update - New segments combination 203 // LED display update - New segments combination
175 PORT(LED_SEGMENTS_PORT) = (PORT(LED_SEGMENTS_PORT) & ~LED_SEGMENTS_MASK) | (~Segments & LED_SEGMENTS_MASK); 204 PORT(LED_SEGMENTS_PORT) = (PORT(LED_SEGMENTS_PORT) & ~LED_SEGMENTS_MASK) | (~Segments & LED_SEGMENTS_MASK);
176 // LED display update - One digit on 205 // LED display update - One digit on
177 PORT(LED_DIGITS_PORT) |= (LED_DIGITS_MASK & DisplayDigitMask); // (common anoda 1=on) 206 PORT(LED_DIGITS_PORT) |= (LED_DIGITS_MASK & DisplayDigitMask); // (common anoda 1=on)
-   207 #endif
178 } 208 }
179   209  
180   210  
181 // Main 211 // Main
182 int main() 212 int main()