0

I'm having some troubles about my 7 segment 2 digit counter. I'm using a PIC16F877A with 20Mhz crystal. I'm programming my pic using a replica PICKIT 3 and MPLAB IDE.

Circuit

When i write 02,03,04,04...06 segment displaying it like 88 but 2. Digit C and F segments are not bright as other segments.

02

When i write 01,07,10, everything is normal

My code:

#include <16F877A.h>   
#use delay(clock=20m)
#define Dig2 PIN_A0
#define Dig1 PIN_A3
#define rfid PIN_A1
#define reset PIN_A2
#use fast_io(b)
#use fast_io(a)
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
//static const int digit[10]= { 0b0111111, 0b0000110, 0b1011011, 0b1001111,0b1100110,0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };// anode
static const int digit[10]= { 0b1000000, 0b1111001, 0b0100100, 0b0110000,0b0011001,0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000 };//cathode

//SECOND CODE
void display(unsigned char value)
{
    int onlar = value / 10;
    int birler = value % 10;
    output_low(Dig2);
    output_high(Dig1);
    output_b(digit[onlar]);
    delay_ms(5);
    output_low(Dig1);
    output_high(Dig2);
    output_b(digit[birler]);
    delay_ms(5);
    }
/* FIRST CODE
// Written by Michaël Roy
void display(unsigned char value)
{
    static char tens = 0;
    char dig = (tens) ? (value / 10) : (value % 10);
    dig = digit[dig];
    output_high((tens) ? Dig1 : Dig2);
    output_b(dig); 
    output_low((tens) ? Dig2 : Dig1); 
    tens = !tens;
} */
void main()
{

   char sayi = 0;
   set_tris_b(0b10000000);
   set_tris_a(0b11111010);

   while(1)
   {
     display(sayi);

     if(input(rfid) == 0)
     {
        sayi++;       
    while(input(rfid) == 0)
    {
       display(sayi);
    }
    if (sayi == 100)
    {
                sayi = 0  ;

    }
}
     if(input(reset) == 0)
     {
                delay_ms(3000);
                if(input(reset) == 0)
                {
                   sayi = 0;
                   }
                }
}
}

How can I solve this?

Emre Badem
  • 13
  • 5
  • Express clearly, for example in showing number 7 my segment have trouble and show correctly 2 number. – EsmaeelE Aug 19 '17 at 23:00
  • My circuit showing 1,7 number correctly but in showing number 2,3,4,5,6,8,9 my segment have trouble – Emre Badem Aug 19 '17 at 23:03
  • what is your 7 segment type? common anode or common cathode? – Ihdina Aug 19 '17 at 23:30
  • I'm using cathode. – Emre Badem Aug 19 '17 at 23:58
  • 1
    static const int digit[10] ={0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01100111}; // CC (Active High) – Ihdina Aug 19 '17 at 23:59
  • You entered false value for first element of array it must have two bit off because of Zero: 0 number in 7seg. – EsmaeelE Aug 20 '17 at 00:10
  • Not worked Ihdina. – Emre Badem Aug 20 '17 at 00:13
  • What is `set_tris_b(0b1<000000);` for ? And the test for sayi == 100 is misplaced, it should be placed right after the increment. – Michaël Roy Aug 20 '17 at 00:32
  • I changed it to set_tris_b(0b10000000); And did you meant this? if(input(rfid) == 0) { sayi++; if (sayi == 100) { sayi = 0 ; } while(input(rfid) == 0) { display(sayi); } – Emre Badem Aug 20 '17 at 00:38
  • You say the 1 and 7 digits works, that means your seven segment is CA (Active Low) type, not CC (Active High). – Ihdina Aug 20 '17 at 00:42
  • static const int digit[10]= { 0b11000000, 0b11111001, 0b10100100, 0b10110000, 0b10011001, 0b10010010, 0b10000010, 0b11111000, 0b10000000, 0b10011000}; // CA (Active Low) – Ihdina Aug 20 '17 at 00:43
  • @EmreBadem That's what I meant, yes. Always clamp the value before use. – Michaël Roy Aug 20 '17 at 00:45
  • Most likely something wrong with the circuit, the micro-controller will only output +5V or 0V. Remember they are meant to support a maximum of 25mA on a pin, so make sure you're using a power interface for the cathodes. If you are draining all that current directly into PIN_A0 and PIN_A1 you will have problems and will soon burn that chip. – Havenard Aug 20 '17 at 00:46
  • Yeah you are right Ihdina but i think it is not about digit array and my code aren't working after changes. Now I m checking my power usage. – Emre Badem Aug 20 '17 at 00:46
  • Emre, try to use CA (Active low) for digit[10] array. Can you show your schematic? I am sure there is an error in your circuit. – Ihdina Aug 20 '17 at 00:50
  • You only have a 5ms delay between showing the numbers. That is very quick, even for the human eye. Try changing it to 500ms. – cup Aug 20 '17 at 00:50
  • The only thing I see that could cause this is that B6 is also the PGC pin. But it is definitely an electrical problem. Is the voltage on that pin swinging the full range from 0 to 5V? If not, you may need to add a transistor there and reverse the logic on that pin. – Michaël Roy Aug 20 '17 at 00:51
  • I tried your array Ihdina, I tried it Cup it didn't worked. I'm checking it Michael – Emre Badem Aug 20 '17 at 00:53
  • If you have full swing. measure all resistors before doing anything else. – Michaël Roy Aug 20 '17 at 00:59
  • Sorry, I misread. the faulty lines are RB2 and RB5, right? These are not special in any way.... How much current are your segments drawing? – Michaël Roy Aug 20 '17 at 01:08
  • I don't reach my multimeter for now so i checked with a mini 7 segment voltmeter and i noticed something after giving power to PIC,PICKIT 3'S voltage dropped from 5 to 4.38 volt. Is that normal? – Emre Badem Aug 20 '17 at 01:11
  • I tried reading your circuit, but couldn't.... Havenard is right about having transistors for draining all this current. A couple 2N3906 or equivalent PNP small signal transistors on Dig1 and Dig2 should be enough, The voltage drop on the pickit is normal, it's not meant to provide a lot of current, though. – Michaël Roy Aug 20 '17 at 01:21
  • Emre, your schematic like this (CA - Active Low. )? http://www.electronics-tutorials.ws/articles/segment4.gif – Ihdina Aug 20 '17 at 01:24
  • Yes ihdina same resistor and power – Emre Badem Aug 20 '17 at 01:27
  • You should try this. Unplug Dig1 and Dig2. change your program to display only the lower digit. Connect one of Dig1 or Dig2 directly to the 5V supply and check the result. I am assuming that you have 7 resistors on the segments – Michaël Roy Aug 20 '17 at 01:29
  • I'm rebuilding my circuit. I will try it when it done. – Emre Badem Aug 20 '17 at 01:32
  • I'm changed my resistors to 320 ohm and problem solved thank you for your help. – Emre Badem Aug 20 '17 at 01:55
  • Glad to hear. An electric current of 10 - 20 mA is enough to turn on the led of the seven segment. – Ihdina Aug 20 '17 at 02:29
  • If the problem has been solved, please post an answer to this question. Answering your own question is encouraged! Incorporate the advice provided by Michael Roy, and give him credit in the answer. – Cody Gray - on strike Aug 20 '17 at 12:19

0 Answers0