PDA

View Full Version : programming problem in 7segment display



muttusarve
- 10th April 2012, 20:20
programming problem in 7segment display
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[i];delay_ms(10);
}
}

Demon
- 10th April 2012, 21:37
That looks like C, this is a PIC Basic forum.

Robert

muttusarve
- 11th April 2012, 06:44
yes its a pic16f877 only and the code is in embedded c.. then where should i post it..

muttusarve
- 11th April 2012, 06:49
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.fig3 shows the message what i'm getting when i simulate it in protues.. 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[i];delay_ms(10);
}
}

ScaleRobotics
- 11th April 2012, 07:36
yes its a pic16f877 only and the code is in embedded c.. then where should i post it..

How about a C compiler forum, like http://www.microchip.com/forums/

But we could tell you why it won't work on our basic compiler :)

Ramius
- 18th April 2012, 23:27
When it comes to 7-segment displays there are 2 types, "common anode" and "common cathode" both require a different way of driving them. One suggestion is dump the 74ls78 bcd to 7 segment decoder and 74ls138 decoder and go to a MAX7219 and an LTC-4727JR. The MAX7219 communicates with 3 wires. The LTC-4727JR is a very flexable display.

Best, Ed