Hello,
I have read about multiplexing seven segment displays and I believe I understood it's theory. That the individual digits of the seven segment display should be turned on alternately with a very small refresh rate so that persistence of vision causes the numbers to appear steady. I created a code with mikroC and a simulation circuit with Proteus Isis.
However, the display didn't turn out as expected. I observed that even when I already deactivate my transistor (BC557), it would still conduct for approximately 1 second - keeping it's display turned on in the process. This totally messes with the program and if I set the refresh delays for alternately turning on the displays to be very small (50ms), both displays would be turned on all the time. I need to set the delay to at least be 1300ms to make the theory of multiplexing work in which the displays are turned on one at a time. I can't seem to figure it out what I did wrong.
I have attached an image of my circuit and the C code. My circuit is supposed to be a coinslot but the problem I'm having is only on the seven segment displays. You can disregard the other parts of the circuit. I hope you guys can help me with this.
Code:
void display(int number)
{
int digit1, digit2;
digit1 = number/10;
digit2 = number%10;
portb.f6 = 1;
portb.f7 = 1;
switch (digit1)
{
case 1: { porta = 0xC9; portb.f4 = 1; portb.f5 = 1; break;}
case 2: { porta = 0x84; portb.f4 = 0; portb.f5 = 1; break;}
case 3: { porta = 0x80; portb.f4 = 1; portb.f5 = 1; break;}
case 4: { porta = 0x89; portb.f4 = 1; portb.f5 = 0; break;}
case 5: { porta = 0x82; portb.f4 = 1; portb.f5 = 0; break;}
case 6: { porta = 0x82; portb.f4 = 0; portb.f5 = 0; break;}
case 7: { porta = 0xC8; portb.f4 = 1; portb.f5 = 1; break;}
case 8: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
case 9: { porta = 0x88; portb.f4 = 1; portb.f5 = 0; break;}
case 0: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
}
portb.f6 = 0;
Delay_ms(50);
portb.f6 = 1;
Delay_ms(50);
switch (digit2)
{
case 1: { porta = 0xC9; portb.f4 = 1; portb.f5 = 1; break;}
case 2: { porta = 0x84; portb.f4 = 0; portb.f5 = 1; break;}
case 3: { porta = 0x80; portb.f4 = 1; portb.f5 = 1; break;}
case 4: { porta = 0x89; portb.f4 = 1; portb.f5 = 0; break;}
case 5: { porta = 0x82; portb.f4 = 1; portb.f5 = 0; break;}
case 6: { porta = 0x82; portb.f4 = 0; portb.f5 = 0; break;}
case 7: { porta = 0xC8; portb.f4 = 1; portb.f5 = 1; break;}
case 8: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
case 9: { porta = 0x88; portb.f4 = 1; portb.f5 = 0; break;}
case 0: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
}
portb.f7 = 0;
Delay_ms(50);
portb.f7 = 1;
Delay_ms(50);
}
void main() {
int Active, Account;
cmcon = 0x07;
TRISA = 0x30;
TRISB = 0x01;
Active = 1;
porta = 0xFF;
portb = 0xFF;
while(1){
Display(98);
}
}
I have read about multiplexing seven segment displays and I believe I understood it's theory. That the individual digits of the seven segment display should be turned on alternately with a very small refresh rate so that persistence of vision causes the numbers to appear steady. I created a code with mikroC and a simulation circuit with Proteus Isis.
However, the display didn't turn out as expected. I observed that even when I already deactivate my transistor (BC557), it would still conduct for approximately 1 second - keeping it's display turned on in the process. This totally messes with the program and if I set the refresh delays for alternately turning on the displays to be very small (50ms), both displays would be turned on all the time. I need to set the delay to at least be 1300ms to make the theory of multiplexing work in which the displays are turned on one at a time. I can't seem to figure it out what I did wrong.
I have attached an image of my circuit and the C code. My circuit is supposed to be a coinslot but the problem I'm having is only on the seven segment displays. You can disregard the other parts of the circuit. I hope you guys can help me with this.
Code:
void display(int number)
{
int digit1, digit2;
digit1 = number/10;
digit2 = number%10;
portb.f6 = 1;
portb.f7 = 1;
switch (digit1)
{
case 1: { porta = 0xC9; portb.f4 = 1; portb.f5 = 1; break;}
case 2: { porta = 0x84; portb.f4 = 0; portb.f5 = 1; break;}
case 3: { porta = 0x80; portb.f4 = 1; portb.f5 = 1; break;}
case 4: { porta = 0x89; portb.f4 = 1; portb.f5 = 0; break;}
case 5: { porta = 0x82; portb.f4 = 1; portb.f5 = 0; break;}
case 6: { porta = 0x82; portb.f4 = 0; portb.f5 = 0; break;}
case 7: { porta = 0xC8; portb.f4 = 1; portb.f5 = 1; break;}
case 8: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
case 9: { porta = 0x88; portb.f4 = 1; portb.f5 = 0; break;}
case 0: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
}
portb.f6 = 0;
Delay_ms(50);
portb.f6 = 1;
Delay_ms(50);
switch (digit2)
{
case 1: { porta = 0xC9; portb.f4 = 1; portb.f5 = 1; break;}
case 2: { porta = 0x84; portb.f4 = 0; portb.f5 = 1; break;}
case 3: { porta = 0x80; portb.f4 = 1; portb.f5 = 1; break;}
case 4: { porta = 0x89; portb.f4 = 1; portb.f5 = 0; break;}
case 5: { porta = 0x82; portb.f4 = 1; portb.f5 = 0; break;}
case 6: { porta = 0x82; portb.f4 = 0; portb.f5 = 0; break;}
case 7: { porta = 0xC8; portb.f4 = 1; portb.f5 = 1; break;}
case 8: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
case 9: { porta = 0x88; portb.f4 = 1; portb.f5 = 0; break;}
case 0: { porta = 0x80; portb.f4 = 0; portb.f5 = 0; break;}
}
portb.f7 = 0;
Delay_ms(50);
portb.f7 = 1;
Delay_ms(50);
}
void main() {
int Active, Account;
cmcon = 0x07;
TRISA = 0x30;
TRISB = 0x01;
Active = 1;
porta = 0xFF;
portb = 0xFF;
while(1){
Display(98);
}
}