4 bit 7 segment display with two 74HC595

Hello All,
I start to play with one of this cheap 4 digit 7 segment display. The display is driven by two 74HC595 which one is for segments and the other is for common cathodes (digits).
Here is the schematic:

I writed a simple code using Darrel's interrupts. Code multiplexing the digits using TMR1 interrupt.
It works OK, but I think that code is not as elegant. It looks rough, because I'm not a skilled programmer.
Can someone explain to me a better way to do this task?

Re: 4 bit 7 segment display with two 74HC595

It’s not bad except you don’t need 4 copies of the same lookup table. That should be a subroutine.
If possible, there should be four identical subroutines that you feed each digit to.

You’d normally do the display multiplex in the main program, and only use the interrupt to set a flag
that is being watched by the main program to know when a second, or whatever period ticks over.
The interrupt handler should be the smaller routine.

Re: 4 bit 7 segment display with two 74HC595

Itís not bad except you donít need 4 copies of the same lookup table. That should be a subroutine.
If possible, there should be four identical subroutines that you feed each digit to.

Youíd normally do the display multiplex in the main program, and only use the interrupt to set a flag
that is being watched by the main program to know when a second, or whatever period ticks over.
The interrupt handler should be the smaller routine.

Re: 4 bit 7 segment display with two 74HC595

Originally Posted by louislouis

Here: T1CON.0 = 1 ; restart timer

Code:

TMR1H = %11111100
TMR1L = %00011111
T1CON.0 = 1 ; restart timer

Most of the data sheets say that when you write to the TMRxH/L, you must declare the entire TxCON SFR. I personally have made a practice of using T1CON = %xxxxxxxx instead of isolating a single bit in the TxCON register after preloading the TMRx register. I actually had a bug that I couldn't figure out for the longest time. When I wrote to the entire Timer Register instead of just a single 1/0 bit, it started working. If it works now, you could leave it as is. If you have issues, try what I suggested here.

Re: 4 bit 7 segment display with two 74HC595

OK, looked through a K50 and 16F1619 Data Sheet for that note or catch phrase indicating a full write to TxCON is recommended after writing to the TMRxH/L registers and cannot find it. It might be for an older processor, or maybe I read it on a forum somewhere and now it's that propagating myth. Sorry.

Re: 4 bit 7 segment display with two 74HC595

Your code is probably for 4 digit 7 segment display where the segments is driven via 74HC595 shift register, and the common anodes via transistors directly from MCU or for multiplexing a bare display whitout driver right

wrong , my code is for your circuit but using a different pic chip . I don't have a 12f1840 on hand but I cannot see any reason for it not to work on that chip . if you use the right pins.
your code is for common anode mine common cathode the commented lines can be changed to suit

COMF _segment,W for common Anode becomes MOVF _segment,W
COMF _d_pointer,W for common Anode becomes MOVF _d_pointer,W
ie the current is reversed in the display

Re: 4 bit 7 segment display with two 74HC595

Originally Posted by richard

here is a 12f1822 version
with full hex [upper and lower case] space and - sign also
note comments for common anode/cathode

Thanks Richard, that code works, but that is a way more difficult understand to me because ASM and so on.
A few things I've noticed when I tried the code:
- your code is a way shorter in MCU memory like mine, which is good
- multiplex is a bit slower I see some flickers
- if I put in to the "value" variable mumber "1234" the display shows "4321"
of course I changed this line
arraywrite buff ,[HEX4 value,0]
to
arraywrite buff ,[DEC4 value,0]

Anyway, it is a good example how the skilled programmer thinks, and how a beginner thinks.

Last edited by louislouis; - 19th February 2018 at 23:49.
Reason: My English is terrible, will we go to Hungarian :-)

Re: 4 bit 7 segment display with two 74HC595

Originally Posted by richard

the difference with this method is that the mcu can now do other tasks and not spend all its time being just a display controller

Yes that's great, now the MCU has a way more time to do other tasks which I write using my poor skills in picbasic.
Probably this piece of your code will be used in my future projects with that type of 7 segment displays.
Thanks.