I'm reading a book in which the author used both 皇帝 and 皇上 to say 'The Emperor'. I'm a bit confused about why the author would use two words (that according to my knowledge have the same meaning) to refer to the same person in one story. Could anyone please tell me the difference between them?
'皇帝' is a title for 'Emperor' (n)
'皇上' is an honorific (n), exclusively reserved for an emperor. It is like "Your Majesty" or "His Majesty" in English.
You address an emperor as '皇上/陛下/主上/聖上' (Your Majesty) when you are speaking to him
You refer an emperor in third person by his honorific '皇上/陛下/主上/聖上' (His Majesty) or by his title '皇帝' (Emperor)
You do not address an emperor by his title '皇帝' (Emperor) in front of him
The nickname '萬歲爺' (The great one who will live for ten thousand years) is also used to refer to the emperor in third person
皇上 (emperor above); 陛下 (The one who stands at the bottom of the stairs to the throne); 主上 (master above); 聖上 (virtuous one above)
'陛下' is the one still in use in modern Chinese language. 皇上, 主上 and 聖上 are all archaic terms. They can only be found in something like period dramas on T.V
Compared with 皇上, 皇帝 is a bit more formal. That's why 皇上 could be used as a normal addressing term by his subjects.
In the word of 皇帝，皇 means emperor/sovereign and 帝 refers to empire(帝国, the country in the feudal system).
As 皇帝 connotes 'the country/empire' and his supreme power, it would be used when engaging the concept of country, emphasizing his supreme power, or both. Examples,
An emissary from another country would call the empire 皇帝陛下, because there are two countries involved here.
我才是这个国家的皇帝！It emphasizes both his supreme power and the emperor of the country.
封建帝国的统治者是皇帝！It emphasizes his supreme power and also engages the concept of 封建帝国.
皇帝的尊严！ It emphasizes his supreme power.
Most of time, 皇帝 and 皇上 are interchangeable in other normal contexts. For example, 我是皇帝==我是皇上，皇上旨意==皇帝旨意，他想做皇上==他想做皇帝... ...