Pommie I am using a PIC16F1788. I have PortB 3:0 configured for the BCD input to the decoder (SN74LS47) and PortB 7:4 as the individual digits on a 4digit-7segment display.
What I came up with is:
C:
uint8_t BCD;
LATBbits.LATB = (BCD & 0xFF)
Not sure if this is the most efficient way to do it but seam to work.
You need to display each digit for a short period, say 10mS and then switch to the next digit. I'm assuming you're using common anode displays as the 47 needs them.
Without interrupts, you could do,
Code:
while(1){
LATB=0; //ensure all off
LATB=digit1+0x80; //turn on digit 1
delay_ms(10);
LATB=0; //ensure all off
LATB=digit2+0x40; //turn on digit 2
delay_ms(10);
LATB=0; //ensure all off
LATB=digit3+0x20; //turn on digit 3
delay_ms(10);
LATB=0; //ensure all off
LATB=digit4+0x10; //turn on digit 4
delay_ms(10);
}
However, this would be much better using a 10mS interrupt.
Mike.
Actually, I've just realized that this will require 4 x 74LS47s - do you have a schematic?
Edit, I guess you have all the cathodes connected together and to 1 x 74LS47 and the individual anodes to portb 4-7 in which case the above should work.
I don't understand a couple of things about your code.
You don't appear to be advancing Digits!! Assuming Digits goes from 0 to 3 then changing to switch(++Digits&3) should do it.
Why is Dig3 in both one and tenth code?
Also, to avoid ghosting set LATB=0 before the switch instruction.
This comment is about the way you're using current limiting resistors for the 7 segment display.
You have placed the resistors in the digit lines instead of the segment lines. This will cause the brightness of the digit to change depending on how many segments are lit in the digit. For example, when a one is displayed, the total current is shared by 2 segments. But when an eight is displayed, that same current is shared by 7 segments. So a one will be brighter than and eight.
It would be better to place the resistors in the segment lines.
This comment is about the way you're using current limiting resistors for the 7 segment display.
You have placed the resistors in the digit lines instead of the segment lines. This will cause the brightness of the digit to change depending on how many segments are lit in the digit. For example, when a one is displayed, the total current is shared by 2 segments. But when an eight is displayed, that same current is shared by 7 segments. So a one will be brighter than and eight.
It would be better to place the resistors in the segment lines.
ChrisP58 Thank you for pointing that out. Because the router in my PCB program limits me to 250 pads (current design is 250 pads) I will have to eliminate the lamp test for the other LED's. JTOL
Are you locked into the 74LS47? A display driver chip like the TM1637 will drive up to 6 common anode displays using a 2-pin interface (CLK & DIO) and it handles display refresh. It's available in a DIP-20 or SOP20 package. You can get 5 chips for a couple bucks from AliExpress vendors or 4-digit 0.56" modules for about $3 (including shipping).
Mike. Mike - K8LH , I like those displays, played with some max7219 driven displays but 8 digits is normally too much. Four is perfect.
Edit, I note they have both the DP and the colon LEDs - are these all controllable?
Mike. Mike - K8LH , I like those displays, played with some max7219 driven displays but 8 digits is normally too much. Four is perfect.
Edit, I note they have both the DP and the colon LEDs - are these all controllable?