# What is the error in this small "c" program ??

Status
Not open for further replies.

#### iscore

##### Junior Member level 1
Hi ..I have written a c program to display 4 numbers, each on a 7 segment display(1 segment for 1 digit).. I am using input keys , 80c51...I am writing the code in keil...According to my logic, it should take 4 values through input keys one after the other and display them in their respective 7 segment displays as soon as key is pressed....And the execution should be finished after the 4th digit is displayed...Because i am not writing the program inside "while(1) " loop...I am using a switch which is always '0'(closed)...

But the problem is, when i simulated the code in keil and proteus, after displaying the 4th digit, it again goes back and displays the 1st digit, then 2nd and the process never stops(But i need it to happen only once)...Kindly help me in finding where the error is ....I have attached the program...

Code:
		  #include<reg51.h>

unsigned char sec=00;
unsigned char min=00;			/* initial minutes value which is displayed at the start*/

/* initial seconds value which is displayed at the start*/

unsigned char sec1,sec2;
unsigned char min1,min2;
unsigned char delay=0;
unsigned char array[];
unsigned char sec1=0,sec2=0,min1=0,min2=0;
unsigned char demux=0x00;
unsigned char count=0,display=0;
/*unsigned char flag=0;*/
unsigned int i=0;
unsigned char j=0;
unsigned char value1=0x00,value2=0x00,value3=0x00,value4=0x00;

#define set_time P3
#define display_time P1
#define time_demux P2
sbit s1=P0^0;
sbit s2=P0^1;

void manual_input();  /*function to give manual time settings */
void delay_subroutine();

void main()
{
s1=1;	  /*pause button making it input */
s2=1;
set_time=0xFF;
/*  IE=0X82;
TMOD=0X01;
TH0=0XEE;
TL0=0X00;	*/
/*port through which you set time.making it input*/

manual_input();

do
{

delay_subroutine();

time_demux=0x0F;
time_demux=0x00;
display_time=sec1;

delay_subroutine();

time_demux=0x0F;
time_demux=0x01;
display_time=sec2;

delay_subroutine();

time_demux=0x0F;
time_demux=0x02;
display_time=min1;

time_demux=0x0F;
time_demux=0x03;
display_time=min2;

delay_subroutine();
} while(s1==0);

}

/* void timer0 () interrupt 1
{	 TH0=0XEE;
TL0=0X00;

flag=1;
display=display+1;
if(display==4)
{
display=0;}
}	*/

void manual_input()
{
while(count<4)/*  this is because you have 4 values to enter	*/
{
while(i<3000)	  /* a small delay during which any initialkey press is released*/
{	i++;
}
i=0;
if(set_time==0XF0)
{
while(i<=45000)	/*for this duration of time the value from port3 connected to output of encoder is takenand stored in array*/

{
array[j]=set_time & 0x0F;/*masking last four bits and taking only the first four because that gives binary equivalent of number pressed */

i++;
time_demux=demux;   /* activating  demux and selecting the seven segment displays*/
display_time=array[j];/* displaying the value entered*/

}
i=0;	 }

demux=demux+1;		/*incrementing demux value so that control goes to next segment and next digit for timeis entered and displayed on the corrsponding display */

j++; /*incrementing index of array */

while(i<=45000)
{	 i++;
}
i=0;
count++;
} sec1=array[0];
sec2=array[1];
min1=array[2];
min2=array[3];

}

void delay_subroutine()
{
while(delay<=2)
{
delay++;
}
}

#### Attachments

• code.txt
3 KB · Views: 22
Last edited by a moderator:

#### pratzz

##### Member level 5
hey i have not read your code but if you want to just display it just once,then in the end of main()
just write

while(1);
i.e
Code:
void main()
{
while(1);

}
and check it out.

Also try to post your code in code tags (the # sign on top) instead of attching it.

#### bigdogguru

I've inserted the code contained in your attached text file within your initial post.

It appears the last routine is incomplete, missing one or more curly brackets.

BigDog

#### i_chaitanya

##### Member level 2
curly braces are missing for sure :....

#### pratzz

##### Member level 5
i dont think there are missing curly brackets as when i comppiled it build was successful

Status
Not open for further replies.