Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] I'm facing problem Regarding "Data type" in "c language"...!

Status
Not open for further replies.

shantilal.s50

Junior Member level 1
Joined
Jun 8, 2013
Messages
15
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Jaipur
Activity points
110
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..!

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:

Which compilier you are using ?? Many be data size for long int is different for that compliler.
Because as your code count upto a certain value only then you have to change datatype for "b" and "c".
 

Do this..............
This should work. Although strictly speaking, only r6 is overflowing the unsigned int range.

By the way, the shown code won't count at all. It's increasing c but displaying b...

P.S.: There should be possibly a reset for count > 999999.
 
Last edited:
And there is no proper info about "b" in the code....
and instead of c++ put b++ ..and check ..
 

Re: I'm facing problem Regarding &quot;Data type&quot; in &quot;c language&quot;...!

FvM,

Sir , I made a mistake in the code as earlier I was incrementing variable "c" instead of "b".

but
know I make some correction that "b=c" inside "while(1)" loop...............so please check the code again.

- - - Updated - - -

vicky
.
I make some correction that "b=c" inside "while(1)" loop...............so please check the code again.
 
Last edited:

This should work. Although strictly speaking, only r6 is overflowing the unsigned int range.

By the way, the shown code won't count at all. It's increasing c but displaying b...

P.S.: There should be possibly a reset for count > 999999.
.
.
.
.
Thanks a lot
.
Know it works properly...................!
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top