Home   Single 7 Segment display


Embedded C code for Single 7 Segment display


Sample code for Single 7 Segment display delay subroutine.
Following code can be using for AVR series ICs like: ATmega8, ATmega16, ATmega32.

 

#include <avr/io.h> #include <util/delay.h> #define DISPLAY_PORT PORTD #define DISPLAY_DDR DDRD #define ZERO 0x77 #define ONE 0x41 #define TWO 0x3B #define THREE 0x6B #define FOUR 0x4D #define FIVE 0x6E #define SIX 0x7E #define SEVEN 0x43 #define EIGHT 0x7F #define NINE 0x6F #define DOT 0x80 int main(void) { DISPLAY_DDR=0xFF; DISPLAY_PORT=0x00; while(1) { DISPLAY_PORT=ZERO; _delay_ms(1000); DISPLAY_PORT=ONE; _delay_ms(1000); DISPLAY_PORT=TWO; _delay_ms(1000); DISPLAY_PORT=THREE; _delay_ms(1000); DISPLAY_PORT=FOUR; _delay_ms(1000); DISPLAY_PORT=FIVE; _delay_ms(1000); DISPLAY_PORT=SIX; _delay_ms(1000); DISPLAY_PORT=SEVEN; _delay_ms(1000); DISPLAY_PORT=EIGHT; _delay_ms(1000); DISPLAY_PORT=NINE; _delay_ms(1000); DISPLAY_PORT=DOT; _delay_ms(1000); } return 0; }