+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Member level 2
    Points: 477, Level: 4

    Join Date
    Apr 2018
    Posts
    51
    Helped
    0 / 0
    Points
    477
    Level
    4

    Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    While simulating in proteus 4-DIGIT 7-SEGMENT DISPLAY in xc8(v2.0) , the counting not incrementing.
    Only geting 0 at each of every 4 digit segments at startup and after few sec all are going to 8 8 8 8 and again 0000.
    What is the problems in program..
    Pl suggest anybody..
    the code is below with proteus schematics .
    Code:
    //Common Cathode seven segment display
    //https://circuitdigest.com/microcontroller-projects/7-segment-display-interfacing-with-pic16f877a
    
    
    // CONFIG
    #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
    #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
    #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
    #pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
    #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
    #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
    
    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.
    
    #include 
    
    //***Define the signal pins of all four displays***//
    #define s1 RC0
    #define s2 RC1
    #define s3 RC2
    #define s4 RC3
    //***End of definition**////
    
    void main()
    {
    unsigned int a,b,c,d,e,f,g,h; //just variables
    int i = 0; //the 4-digit value that is to be displayed
    int flag =0; //for creating delay
    
    unsigned int seg[]={0X3F, //Hex value to display the number 0
                        0X06, //Hex value to display the number 1
                        0X5B, //Hex value to display the number 2
                        0X4F, //Hex value to display the number 3
                        0X66, //Hex value to display the number 4
                        0X6D, //Hex value to display the number 5
                        0X7C, //Hex value to display the number 6
                        0X07, //Hex value to display the number 7
                        0X7F, //Hex value to display the number 8
                        0X6F  //Hex value to display the number 9
                       }; //End of Array for displaying numbers from 0 to 9
    
    //*****I/O Configuration****//
    TRISC=0X00;
    PORTC=0X00;
    TRISD=0x00;
    PORTD=0X00;
    //***End of I/O configuration**///
    
    #define _XTAL_FREQ 20000000
    
    while(1)
    {
      //***Splitting "i" into four digits***//  
    a=i%10;//4th digit is saved here
    b=i/10;
    c=b%10;//3rd digit is saved here
    d=b/10;
    e=d%10; //2nd digit is saved here
    f=d/10;
    g=f%10; //1st digit is saved here
    h=f/10;
    //***End of splitting***//
    
    PORTD=seg[g];s1=1; //Turn ON display 1 and print 4th digit
    __delay_ms(10);s1=0;     //Turn OFF display 1 after 5ms delay
    PORTD=seg[e];s2=1; //Turn ON display 2 and print 3rd digit
    __delay_ms(10);s2=0;     //Turn OFF display 2 after 5ms delay
    PORTD=seg[c];s3=1; //Turn ON display 3 and print 2nd digit
    __delay_ms(10);s3=0;     //Turn OFF display 3 after 5ms delay
    PORTD=seg[a];s4=1; //Turn ON display 4 and print 1st digit
    __delay_ms(10);s4=0;     //Turn OFF display 4 after 5ms delay
    
    if(flag>=100) //wait till flag reaches 100
    {
        i++;flag=0; //only if flag is hundred "i" will be incremented 
    }
    flag++; //increment flag for each flash
    }
    }
    Click image for larger version. 

Name:	7seg.png 
Views:	11 
Size:	62.7 KB 
ID:	153217

    pl suggset ahat actually problems.

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 23,418, Level: 37
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    4,485
    Helped
    991 / 991
    Points
    23,418
    Level
    37

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    I'm not familiar with what you can do with Proteus, but have you looked at your intermediate values, e.g., a.b.c. etc. and the value of PORTD to verify that they are proper?

    Not sure why "delay_ms(10)" would give you a 5ms delay, shouldn't it be 10ms?

    You say "after a few seconds" it goes to 8888. By my calculation, the display should increment every 4 seconds (or 2 seconds, by your reckoning). Is that the same as your "few seconds"?



  3. #3
    Super Moderator
    Points: 79,430, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,011
    Helped
    4345 / 4345
    Points
    79,430
    Level
    68

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    Not sure why the simulation fails and I do not have Proteus to check.
    If you built it in real hardware you need a resistor in series with each LED segment signal to limit the current or else the PIC or the LED will be damaged.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 51,807, Level: 55

    Join Date
    Apr 2011
    Location
    Minneapolis, Minnesota, USA
    Posts
    12,713
    Helped
    2529 / 2529
    Points
    51,807
    Level
    55

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    Quote Originally Posted by saramah View Post
    all are going to 8 8 8 8
    Isn't this what happens when you do a test of all connections? By changing state at a certain pin, and it makes the IC light up everything on the display.

    Does your IC have a pin to do that? Does it have a pullup (or pulldown) resistor? Or does your code contain a command to briefly light up the entire display?



  5. #5
    Advanced Member level 2
    Points: 2,835, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    561
    Helped
    49 / 49
    Points
    2,835
    Level
    12

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    The display enable pins that is the 4 common cathode pins need a pull-up of say 10k to 5V in Proteus but not needed in hardware.



  6. #6
    Super Moderator
    Points: 79,430, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,011
    Helped
    4345 / 4345
    Points
    79,430
    Level
    68

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    I don't use Proteus (or Windows apps at all) but if what Baileychic just said:
    The display enable pins that is the 4 common cathode pins need a pull-up of say 10k to 5V in Proteus but not needed in hardware.
    I would say it is a very poor simulator. I can see why simulations cannot cover every eventuality but to need extra components to make the simulated electronics work is a serious deficiency in it's operation.

    Saramah, I would add an extra line to your code to debug it:
    Place "i=1234;" at the very start of the while() loop and see if that number is really displayed.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  7. #7
    Member level 2
    Points: 477, Level: 4

    Join Date
    Apr 2018
    Posts
    51
    Helped
    0 / 0
    Points
    477
    Level
    4

    Re: Can't get digits other than 'zero' in 4-DIGIT 7-SEGMENT DISPLAY

    whah!!very Thnks @ baileychic for you good comment working the segments as desired with adding the pulup.
    also thanks @ betwixt for your comment also.

    thks all u very much..



--[[ ]]--