Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

7 segment problem

Status
Not open for further replies.

muttu.sarve

New Member
hi every one..
i'm facing some problem in my projects. i worked it on proteus and i have attached some snaps shot of my project. i'm reading analog i/p from RA2 and display it on 4 7-segments devices. i used 74ls78 bcd to 7 segment decoder and 74ls138 decoder. i've copied my source code too with this. the fig1 shows the intial setup and fig2 shows the during execution of the project. i think the problem with the code it self.. when i simulate in proteus only one device is active and its always shows zero (0) irrespective of analog input. i want to display the result on 7 segment so please go through the code and let me know if is there any changes have to make in this.
code:

#include<16f877.h>
unsigned int cnt, brk;
char led [3];
unsigned int rem;
void converter (unsigned int z);
void scanled (void);
void main()
{
OPTION_REG=0x80;
PORTA=0;
TRISA=255;
PORTD=0;
TRISD=0;
while(1)
{
cnt=ADC_Read(2);
cnt=cnt*5;
converter (cnt);
scanled ();
}
}
void converter(unsigned int z)
{
led[0]=z/1000;
rem=z%1000;
led[1]=rem/100;
rem=rem%100;
led[2]=rem/10;
led[3]=rem%10;
}
void scanled (void)
{
unsigned char i;
for (i=0;i<4;i++)
{
portd=i;portd=led;delay_ms(10);
}
}
 
Code:
#include<16f877.h>
unsigned int cnt, brk;
char led [3];
unsigned int rem;
void converter (unsigned int z);
void scanled (void);
void main()
	{
	OPTION_REG=0x80;
	PORTA=0;
	TRISA=255;
	PORTD=0;
	TRISD=0;
	while(1)
		{
		cnt=ADC_Read(2);
		cnt=cnt*5;
		converter (cnt);
		scanled ();
		}
	}
	
void converter(unsigned int z)
	{
	led[0]=z/1000;
	rem=z%1000;
	led[1]=rem/100;
	rem=rem%100;
	led[2]=rem/10;
	led[3]=rem%10;
	}
	
void scanled (void)
	{
	unsigned char i;
	for (i=0;i<4;i++)
		{
		portd=i;
		portd=led[i];
		delay_ms(10);
		}
	}

You should use code tags... its the # symbol above.

The scan routine should select each LED in turn.

Code:
void scanled (void)
	{
	unsigned char i;
	unsigned char f=0x10;
	for (i=0;i<4;i++)
		{
		portd = f;
		portd += led[i];
		delay_ms(10);
		f <<= 1;
		}
	}
 
hi ian.. thanks for replying.. what u mean by code tags.. i didnt get u.. and is that only thing i need to change in my program.. will it work.. please help me out..
 
hello IAN, i tried the code that you posted but it still giving the problem.. is it because of code problem or proteus problem?? because when i simulate it then i got message like this.. check out the attachment.
View attachment 63233
 
I have to use Hi-tech C, so my code is slightly different....But you should get the gist.

Code:
#include<htc.h>

unsigned int cnt, brk;
unsigned char led [4];
unsigned int rem;

void converter (unsigned int z);
void scanled (unsigned char);
int ADC_Read(unsigned char);
void delay_ms(int);

void main()
	{
	unsigned char i=0;
	OPTION_REG=0x80;
	PORTA=0;
	ADCON1 = 0x82;
	ADCON0 = 0x40;
	TRISA=255;
	PORTD=0;
	TRISD=0;
	while(1)
		{
		cnt=ADC_Read(2);
		cnt=cnt*5;
		converter (cnt);
		scanled (i++);
		delay_ms(5);
		if(i == 4) i = 0;
		}
	}
 
void converter(unsigned int z)
	{
	led[0]=z/1000;
	rem=z%1000;
	led[1]=rem/100;
	rem=rem%100;
	led[2]=rem/10;
	led[3]=rem%10;
	}
 
void scanled (unsigned char f)
	{
	unsigned char buff;
	buff = led[f];
	f<<=4;
	buff |= f;
	PORTD = buff;
	
	}

int ADC_Read(unsigned char CH)
	{
	int result;
	CH<<=3;
	ADCON0 |= 1;
	ADCON0 |= CH;
	delay_ms(1);
	GO = 1;
	while(GO){};
	result = ADRESH;	
	result<<=8;
	result += ADRESL;
	return result;
	}
void delay_ms(int x)
	{
	int t;
		
	while(x--)
		{
		t=56;
		while(t--);
		}
	}

you need to lock ONE digit at a time...
 
thank you so much for helping me.. this is working now. i need to clarify one more think with you. that is if i need to add three more 7 segment display to this circiut then what should i need to change in the program. i can connect another 3 display's segments to 74ls48 bcd to 7segments and with help of remaining pins in 74ls138 decoder i can manage to to connect those pins to common cathode pins of another 3 displays. i just want to know what changes can i make in your code to work it for all seven (7) displays work at once.. i mean to say i'm using another 3 more displays to show some other operation output so i divide these 4 display suppurate and 3 display suppurate want to combine both these displays (4+3) in this single circuit and do the rest operation. i hope you understood my question. please do the helpful and i will also try to resolve this problem.
thank you.
 
Last edited:
You need to pay attention to the timing... If you add more displays the time for viewing each digit will decrease thus the display will dim.. If you keep the timing and add more displays it might start to flicker.

You can always drive two 74ls48's with one port and control with another... That way you can scan two digits at a time..

If you can get hold of latching shift registers (or a chip that drives that many segments ) it will look better... Some of the newer PIC's have LCD segment drivers built in.
 
ya you are right.. but the problem is, i need to reduce my i/o ports as much as possible. so i move to use decoder and bcd to 7 segment. i dont have any other pins in my pic to use another 3 more display. so i need to add those display in this circuit only. these three displays i'm using to display some digits all the time.. like 100. is it not possible to add 3 more display on it.. please let me know if is there any changes in this code..
 
You can increase the scanled to 7 digits, without any mods to the code (apart from increasing led[4] to led[7] )

and the conversion routine.... You then just mess with the delay_ms, until it looks right

I've just done it with a 6 digit and its flickering.. with a 1ms delay
 
Last edited:
ya i too tried it in simulation and its not working... when i change the scan led to 7 then only one digit gets on and all other will be off.. then actually the project is like this. i will initialize the count to 100 ( it can be change) and it is display on 3 device of 7segment display. and the another 4 device segment display is use to show the count value which is reading from adc. i'm trying this from many days but not getting the correct output. can you tell me how to do it with simple code..
thank you so much.
 
Last edited:
as i'm using decoder and bcd to 7segment driver so it has not to flicker right.. because i'm not driving directly with pic ports.
my project goes like this.. please go through it.
there are two set of display. one 4 device 7segment is using to display the current count of adc output and another 3 device 7segment display which is to display the predefined count.. for example if i give 100(can be changed)count which is display on 3 device 7segment and the 4 device 7 segment willl count until it reaches 100 and it will show the output in 4 device 7 segment. i made the hardware arrangement for it. i'm trying to do the program for it but still not getting the output so help me out to solve this with simple program.
thank you :)
 
here is the schematic.. the 1st 4 digits in the display are used to display the count value which is read from adc and next 3 digits are used to display the user defined count number (like 100) and last digit is dummy in this schematic. the user define the count using keypad and which will display on 3 digit display then adc will start counting and corresponding display will come in 1st 4 digits of 7segment display.. when the predefined count will reach then the adc have to stop the couuting..

View attachment 63244
 
i hope you got too know what i'm trying to say.. please help me out to solve this issue.. the remaining i/o pins in the pic are connected to other devices like led, external devices.. i'm trying to solve it and doing hard work but still not getting the output. please let me know if you solved this issue with simple code..
thank you so much :)
 
i hope you got too know what i'm trying to say.. please help me out to solve this issue.. the remaining i/o pins in the pic are connected to other devices like led, external devices.. i'm trying to solve it and doing hard work but still not getting the output. please let me know if you solved this issue with simple code..
thank you so much :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top