In the beginning, there was only the cup. The Anglo-Saxon word was cuppe, a borrowed word from Latin cuppa, which entered many European languages (such as Spanish copa and French coupe). The original meaning was simply a drinking-vessel.
The form of the vessel developed in two directions: without a stem (as in the modern tea-cup) and with a stem and foot (as in a wine-cup or chalice, sometimes with a cover), reflecting an increasing diversity of functions. It first developed a strong religious connotation in Christianity, being used in the sense of 'chalice' in Wyclifffe's translation of the Bible (14th century), later in the Book of Common Prayer (16th century), and thus into modern usage (eg as communion cup). In the 17th century it also developed an ornamental sense, being used as a prize in a contest - initially, in horse-racing (the Doncaster Cup), which is the commonest modern application.
Cup then developed a very wide range of senses, in which its shape was applied to any rounded cavity, such as in plants (an acorn-cup), human anatomy (the cup of the hip-bone), golf (a depression in the ground), and clothing (in bras). The linguistic result was the formation of many compound words, such as cup-holder, cup-final, and cup-cake. Colloquially, it became a replacement for the liquid a cup might contain, as in cuppa (cup of tea) and to drink a cup (Auld Lang Syne), and that in turn led to further everyday usage. 'That's not my cup of tea.' 'He's in his cups.' It even generated a proverb: 'There's many a slip between cup and lip'.
The history of mug is totally different. The word arrived in English much later, in the Middle Ages. Nobody is quite sure where it came from. There are similar-sounding words in German, Dutch, and the Scandinavian languages, all referring to some sort of open can or jug. It may be an adaptation of a Latin word for a measuring vessel (modius), because the notion of measurement is found in the earliest recorded use of mug in English in 1400.
From the outset it seemed to be used more to refer to the physical object than to the content it might contain. It comes to be used with such adjectives as large and half-pint, and with words that describe its material, such as silver or stone. The fashion for ornamental and collectible mugs also drew attention to the mug as a physical object. We are also much more likely to find the word mug used in relation to a location - a steaming mug of tea was left 'on the bench', 'by the fire'... Cups weren't so often 'located' in this way.
The early use of mug was mainly in regional dialects, and especially in Scotland, for any earthenware bowl or pot. It began to be used routinely for a drinking vessel in the 17th century, and gradually came to be distinguished from the tapering cup by its cylindrical shape and larger size. But it was the social activity that led to the main difference between the two.
In the 18th century, the taking of tea became a mark of high society. The word tea-cup arrives in the language (earliest recorded usage in 1700). Saucers joined cups as the norm (to ensure that any spillage was contained). Mugs then became associated with lower-class activities, where spilling didn't matter so much, and where the larger size reflected the thirstiness of the drinker - always assumed to be a manual worker. Early examples of mug are almost all to do with beer. Mugs of tea were drunk by people who were either blue-collar workers or - later - those who wanted to be thought of as down-to-earth, ordinary types. These connotations remain today.
As the taking of tea became less class-conscious, and a more informal occasion, it led to the shortened form cuppa in British regional English. There seems to have been a need to get away from the formality of 'high tea'. By contrast, there is no word mugga in English - presumably because mug was always felt to be associated with less formal settings.
The usage of the two words now differs greatly, reflecting their different social history. When people talk of cups, they're more likely to be thinking of the contents rather than the object. One sips a cup of tea, one pours a cup of tea, one talks about a lovely cup of coffee, a perfect cup of tea. The cup is associated with drinking as a social event: one offers someone a cup of coffee, and people enjoy a cup of tea together. It marks the passing of time: we talk about an early morning cup of tea, my third cup of coffee. Try replacing the word cup with mug in these examples, and you can sense the difference. Mug is actually very rare in these circumstances: in an interesting study of the 650-million-word Bank of English corpus, carried out in 2009 by Brett Laybutt, cup of tea was found to be fifteen times more common than mug of tea. (There were also, incidentally, many examples of cup of soup, but none of mug of soup.)
Some results of the Heinz survey reinforce these historical trends. Cup generates more diverse forms and functions than mug. The informants use cup for purposes other than for tea/coffee/soup far more than for mug (in aggregate, 1952 vs 1440). They don't differentiate much between cup and mug when it comes to tea/coffee, but there's a huge difference when it comes to soup, with 1093 opting for mug vs 344 for cup. This, along with a clear preference for eating vs drinking soup (three out of four people prefer the former - a trend that is most noticeable in the north-east), suggests a strong linguistic expectation that eat and mug will go together, when it comes to soup, so that the collocation Heinz Cup Soup immediately stands out as a departure from the norm.
When people were shown pictures and asked to name them, most opted for simply cup or mug. But those who gave a longer description were nearly four times more likely to go for tea/coffee cup (95 instances) than tea/coffee mug (26 instances). There's little sign of significant regional difference any more, but a trend is very noticeable with reference to age: the younger you are, the more you're likely to use cup with diverse functions. For example, less than 4% of age 55+ use cup as a toothbrush holder, whereas 30% of age 18-24 do. Similarly, only 2% of age 55+ use cup to wash paintbrushes, whereas almost 18% of age 18-24 do. By contrast, there's no such noticeable difference across age for the uses of mug. For older people, the distinction in relation to soup is irrelevant. The older you are, the more likely you are to take your soup in a bowl.
And, as a footnote: When the Japanese wanted a word to name a drinking vessel that was neither a mug nor a cup, they borrowed both words from English, put them together, and came up with magukappu.