0
\$\begingroup\$

I want to show the digits'18221021' simultaneously. The seven segment display should show all 8 digits at a once.

I wrote the following code. It shows all the digits but not simultaneously. It is showing them one by one like 1 then 2 then 8 and so on.

I tried lowering the delay from 200ms to 20ms but at 20ms the output looks scrambled.

How can I solve this problem?

include <mega32.h>
#include <delay.h>


void main(void)
{

DDRA=0xFF;//DATA_BUS 
DDRC=0xFF;//DATA_SELECTOR

while (1)
      { 
      PORTA=0b00000110; //Digit1
      PORTC=0b11111110;   //Data selector
      delay_ms(200);
      
      PORTA=0b01111111; //Digit 8
      PORTC=0b11111101;
      delay_ms(200);
      
      PORTA=0b01011011; //Digit 2
      PORTC=0b11111011;
      delay_ms(200);
      
      PORTA=0b01011011; //Digit 2
      PORTC=0b11110111;
      delay_ms(200);
      
      PORTA=0b00000110; //Digit1
      PORTC=0b11101111;   
      delay_ms(200);
      
      PORTA=0b00111111; //Digit0
      PORTC=0b11011111;   
      delay_ms(200);
      
      PORTA=0b01011011; //Digit 2
      PORTC=0b10111111;
      delay_ms(200); 
      
      PORTA=0b00000110; //Digit1
      PORTC=0b01111111;   
      delay_ms(200);
      
      
      }
}

Simulation: (One digit at a time)

\$\endgroup\$
9
  • \$\begingroup\$ Please edit to include a datasheet link for the display you are using. Using the delay() function is bad programming practice as it completely ties up the processor. It's OK for a quick debug but you should learn how to create a timer function and check this in you main loop. \$\endgroup\$
    – Transistor
    Commented Jul 29, 2021 at 11:55
  • \$\begingroup\$ Are you really using a bare LCD? Or is it a 7-segment LED module? LCDs get damaged if you drive them with a DC bias like this. \$\endgroup\$ Commented Jul 29, 2021 at 11:56
  • \$\begingroup\$ @JonathanS. Sorry Edited . I used 8 Digit 7 segment Common Cathode \$\endgroup\$
    – bighero666
    Commented Jul 29, 2021 at 11:57
  • 1
    \$\begingroup\$ Did you try with no delay? Or 1 ms delay? But there is no way around that, as the display is multiplexed. And you need to turn off a digit first before updating the segments and turning on the next digit. \$\endgroup\$
    – Justme
    Commented Jul 29, 2021 at 11:58
  • 2
    \$\begingroup\$ You're getting "ghosting". You need to set PORTC to all-ones before moving on to the next digit. Only change PORTA when no digit is selected. \$\endgroup\$
    – Dave Tweed
    Commented Jul 29, 2021 at 12:20

1 Answer 1

7
\$\begingroup\$

That appears to be an LED seven segment display. You can only light up one digit at a time. You have do it one digit after another. If you do that fast enough the digits will appear to all be on at the same time.

  1. Take out the delays.
  2. Blank each digit before you switch to the next.
  3. Set the PORTC values before you set the PORTA values. PORTC selects which position the character is drawn in while PORTA draws the character. If you do it in the wrong order, your characters won't be where you expect them.

Like this:

  PORTC=0b11111110;   //Data selector
  PORTA=0b00000110; //Digit1
  delay_ms(1);
  PORTA=0b00000000; //blank
  delay_ms(1);
  
  PORTC=0b11111101;
  PORTA=0b01111111; //Digit 8
  delay_ms(1);
  PORTA=0b00000000; //blank
  delay_ms(1);
  
  //Following digits as above

The real question is how well the simulator can simulate the seven segment display and whether it can do it as fast as the simulated processor runs.

This is the kind of thing best done on real hardware. You are trying to learn the basics of how a circuit works, and having to fight simulator problems as well as the things you set out to learn.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.