If I'm not mistaken the last code you provided, if connected to 4 leds, will turn each led on one by one, until all 4 are on, and then turn them off. If you intended to use those signals on the common pins of the 7 segment displays it will not work as expected because you will have often several display activated at the same time. The first code you provided will be better suited for this.
You have the code to control the common pin, and the code to translate from a binary value to 7 segments. Now you need to implement registers with BCD counters and connect everything together.