/* * Digital I/O (dual 7-segment LED) lab program that demonstrates * driving all segments of a dual 7-segment display directly, that * is, without the use of a decoder like the 7447. * * This program demonstrates counting down from 20 to 0, in real-time * (delaying one second per count). * * PORTB is used to display the left digit, and PORTC is used for the * right. * * The dual 7-segment LED board that we are using in this lab has the * segments for a..g on bits 0..6, respectively, and the decimal point * on bit 7. One digit occupies one eight-bit (10pin, incl. VTG & GND) * STK500-style connector. * * Last Modified 2010/09/28 17:10 (ebw) */ #include // for PORTx, DDRx, AD*, etc. #include // for _delay_ms() /* * Bit patterns for the digits 0..9 that can be written directly to the port * connected to one digit of our common-anode 7-segment LED display board. */ // pgfedcba #define PATTERN_0 0b11000000 #define PATTERN_1 0b11111001 #define PATTERN_2 0b10100100 #define PATTERN_3 0b10110000 #define PATTERN_4 0b10011001 #define PATTERN_5 0b10010010 #define PATTERN_6 0b10000011 #define PATTERN_7 0b11111000 #define PATTERN_8 0b10000000 #define PATTERN_9 0b10011000 #define PATTERN_DP 0b01111111 /* * Array indexed 0..9 containing bit patterns for digits 0..9. * HINT: this can make displaying digits much easier than using "if" or * "switch/case" statements.s */ int digitPatterns[10] = { PATTERN_0, PATTERN_1, PATTERN_2, PATTERN_3, PATTERN_4, PATTERN_5, PATTERN_6, PATTERN_7, PATTERN_8, PATTERN_9 }; void init(void) { DDRB = 0xFF; // all of PORTB is outputs DDRC = 0xFF; // all of PORTC is outputs } int main(void) { init(); PORTB = PATTERN_2; // display an initial value for testing PORTC = PATTERN_7; while (1) { /* for ( FIXME ) { PORTB = FIXME; PORTC = FIXME; _delay_ms(100); } */ } return 0; // never executed... }