Skip to content

Instantly share code, notes, and snippets.

@SaheblalBagwan
Last active August 27, 2016 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaheblalBagwan/816e5c73e37dfa2fe8d8fba640ab6b9a to your computer and use it in GitHub Desktop.
Save SaheblalBagwan/816e5c73e37dfa2fe8d8fba640ab6b9a to your computer and use it in GitHub Desktop.
#include <reg51.h>
#define SegOne 0x01
#define SegTwo 0x02
#define SegThree 0x04
#define SegFour 0x08
void DELAY_ms(unsigned int ms_Count)
{
unsigned int i,j;
for(i=0;i<ms_Count;i++)
{
for(j=0;j<100;j++);
}
}
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;
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;
P0 = SegOne;
P2 = seg_code[temp];
DELAY_ms(1);
temp = num / 100;
num = num % 100;
P0 = SegTwo;
P2 = seg_code[temp];
DELAY_ms(1);
temp = num / 10;
P0 = SegThree;
P2 = seg_code[temp];
DELAY_ms(1);
temp = num % 10;
P0 = SegFour;
P2 = seg_code[temp];
DELAY_ms(1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment