Last active
April 1, 2016 08:26
-
-
Save raghavendrahassy/05af8109f493afdddf47dc62fd115fde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
#define SegOne 0x01 | |
#define SegTwo 0x02 | |
#define SegThree 0x04 | |
#define SegFour 0x08 | |
int main() { | |
char seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; | |
int cnt, num, temp,i; | |
/* Configure the ports as output */ | |
DDRB = 0xff; // Data lines | |
DDRD = 0xff; // Control signal PORTD0-PORTD3 | |
while (1) | |
{ | |
for (cnt = 0x00; cnt <= 9999; cnt++) // loop to display 0-9999 | |
{ | |
for (i = 0; i < 100; i++) | |
{ | |
num = cnt; | |
temp = num / 1000; | |
num = num % 1000; | |
PORTD = SegOne; | |
PORTB = seg_code[temp]; | |
_delay_ms(1); | |
temp = num / 100; | |
num = num % 100; | |
PORTD = SegTwo; | |
PORTB = seg_code[temp]; | |
_delay_ms(1); | |
temp = num / 10; | |
PORTD = SegThree; | |
PORTB = seg_code[temp]; | |
_delay_ms(1); | |
temp = num % 10; | |
PORTD = SegFour; | |
PORTB = seg_code[temp]; | |
_delay_ms(1); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment