shantilal.s50
Junior Member level 1
I'm writing a code to multiple the six seven segments as a counter through a single port in which max. count is "999999" but
here in my program it counts up to "65536" and then reset to "00000"
again it counts from "00000" to "34464" and then increment the 6th digit by '1'.
It repeats again and again for every "1" increment in the 6th digit. I don't know why it happens so please check my code and suggest me to use which data type to solve this problem..!
here in my program it counts up to "65536" and then reset to "00000"
again it counts from "00000" to "34464" and then increment the 6th digit by '1'.
It repeats again and again for every "1" increment in the 6th digit. I don't know why it happens so please check my code and suggest me to use which data type to solve this problem..!
Code:
#include<reg51.h>
long int b,c;
unsigned int d1,d2,d3,d4,d5,d6,r1,r2,r3,r4,r5,r6;
unsigned int a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; // common anode 7 segment
sbit s_ip=P3^0;
void delay(int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<275;j++);
}
void seg_display(void)
{
d6=b/100000; // 6th digit
r6=b%100000;
d5=r6/10000; // 5th digit
r5=r6%10000;
d4=r5/1000; // 4th digit
r4=r5%1000;
d3=r4/100; // 3rd digit
r3=r4%100;
d2=r3/10; // 2nd digit
r2=r3%10;
d1=r2; // 1st digit
P1=0x01; //Display 1st digit
P2=a[d1];
delay(2);
P1=0x02; //Display 2nd digit
P2=a[d2];
delay(2);
P1=0x04; //Display 3rd digit
P2=a[d3];
delay(2);
P1=0x08; //Display 4th digit
P2=a[d4];
delay(2);
P1=0x10 // Display 5th digit
P2=a[d5];
delay(2);
P1=0x20; //Display 6th digit
P2=a[d6];
delay(2);
}
void main()
{
P2=0x0 // Output port
b=0;
while(1)
{
while(s_ip==1) // Increment count when bit goes from high to low only
{
seg_display();
}
while(s_ip==0)
{
seg_display();
c++;
}
b=c;
}
Last edited: