The Seven Segment has 8 or more pinouts and is connected to port0 with 8 pins. The pins should be connected to 5V or 0V in a predefined pattern to display each number.
When you write the value P0=0xF9
to port P0, the following values appears on the port pins, 11111001. 1 indicates 5V and 0 indicates 0 volt. Since the pins of seven segment are connected to this port pins, for a value of 0xF9 it will display “1”.
Similarly writing 0xA4 displays “2” and so on.