While most of Hans Christian Andersen's fairy tales were original creations (unlike the Brothers Grimm, who based their stories on existing folktales), this one was an adaptation of an old Danish story. In Andersen's version, there were three peas under the mattresses rather than just one.
Whenever King Fredrico speaks, the sound of birds chirping is always heard. This symbolizes his "bird-brained" intelligence.
Judging by the costumes and architecture, the story seems to take place during the Regency era (1795-1837).