+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 3
    Points: 86, Level: 1

    Join Date
    Mar 2019
    Posts
    5
    Helped
    0 / 0
    Points
    86
    Level
    1

    O/P not Extected in CAMMON ANODE 7-SEGMENTS

    Could u please let me know what is the issue for not getting expected o/p from 4 digit 7seg in XC8 16F877A uC. The Ckt diag. and Code is here.

    I am getting as o/p in 7seg only 0 and 8 but all control and data pins in mcu portion is blinking but all the control pins(1,2,3,4) under 7seg portion not blinking.
    Click image for larger version. 

Name:	CA 7SEG.jpg 
Views:	4 
Size:	270.5 KB 
ID:	153630

    Code:
    #include <xc.h>
    
    //***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[]={0XC0, //Hex value to display the number 0
                        0XF9, //Hex value to display the number 1
                        0XA4, //Hex value to display the number 2
                        0XB0, //Hex value to display the number 3
                        0X99, //Hex value to display the number 4
                        0X92, //Hex value to display the number 5
                        0X82, //Hex value to display the number 6
                        0XF8, //Hex value to display the number 7
                        0X80, //Hex value to display the number 8
                        0X90  //Hex value to display the number 9
                       }; //End of Array for displaying numbers from 0 to 9// FOR CA
     
    
    //*****I/O Configuration****//
    TRISC=0X00;
    TRISD=0x00;
    
    PORTC=0XFF; // FOR CA
    
    //***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=0; //Turn ON display 1 and print 4th digit
    __delay_ms(10);s1=1;     //Turn OFF display 1 after 5ms delay
    PORTD=seg[e];s2=0; //Turn ON display 2 and print 3rd digit
    __delay_ms(10);s2=1;     //Turn OFF display 2 after 5ms delay
    PORTD=seg[c];s3=0; //Turn ON display 3 and print 2nd digit
    __delay_ms(10);s3=1;     //Turn OFF display 3 after 5ms delay
    PORTD=seg[a];s4=0; //Turn ON display 4 and print 1st digit
    __delay_ms(10);s4=1;     //Turn OFF display 4 after 5ms delay
    
    if(flag>=10) //wait till flag reaches 100
    {
        i++;flag=0; //only if flag is hundred "i" will be incremented 
    }
    flag++; //increment flag for each flash
    }
    }

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 79,227, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,976
    Helped
    4332 / 4332
    Points
    79,227
    Level
    68

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    Obvious problems:

    Electrically you overload the PIC RD0 to RD6 pins, you must fit current limiting resistors in each of them.
    Code:
    if(flag>=10) //wait till flag reaches 100
    {
        i++;flag=0; //only if flag is hundred "i" will be incremented 
    }
    flag++; //increment flag for each flash
    Can never reach 100 and if you are using it as a delay it will be very short (a few uS). A better method if you want a reliable count speed is to use a timer interrupt.

    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.



  3. #3
    Newbie level 3
    Points: 86, Level: 1

    Join Date
    Mar 2019
    Posts
    5
    Helped
    0 / 0
    Points
    86
    Level
    1

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    tnx for reply.
    i have tested with same code and same ckt in proteus except (removing) bc557, ie, directly connecting all 4 control pins between mcu & digit, there was no problebs working correctly.
    But If add bc557, as ckt attached getting NOTHING ELSE EXCEPT 0 and 8(ie, 0 0 0 0 and 8 8 8 8).

    As per you,
    If it is "flag" issue, then why it will work in DIRECT connect control pin?
    Could u clera the matter..



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 256,096, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,657
    Helped
    13587 / 13587
    Points
    256,096
    Level
    100

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    Proteus is a strange simulator, the multi-digit 7-segment displays are modelled in a special way as pulse extending circuits to get a smooth display. Driving it with an open collector driver may give unexpected results.



  5. #5
    Newbie level 3
    Points: 86, Level: 1

    Join Date
    Mar 2019
    Posts
    5
    Helped
    0 / 0
    Points
    86
    Level
    1

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    i think base resistor is the problems. Could u please let me know how do I calculate base resistor for this matter..
    thx



    •   AltAdvertisement

        
       

  6. #6
    Newbie level 3
    Points: 86, Level: 1

    Join Date
    Mar 2019
    Posts
    5
    Helped
    0 / 0
    Points
    86
    Level
    1

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    ALONG WITH #4, what simulator is best??



  7. #7
    Super Moderator
    Points: 256,096, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,657
    Helped
    13587 / 13587
    Points
    256,096
    Level
    100

    Re: O/P not Extected in CAMMON ANODE 7-SEGMENTS

    The base resistor is O.K., at least for simulation purposes. In real hardware, a current limiting collector resistor would be necessary.

    I guess the simulation problem is that the pin 1-4 signals are not recognized as valid digital level. May be pull-down resistors can change the behaviour.

    ALONG WITH #4, what simulator is best??
    It depends on the simulation purpose. Proteus is unique as co-simulator of microcontroller code and discrete hardware. But it has some limitations and pitfalls.



--[[ ]]--