The accentuation system in the orthography of Portuguese was created to be logic, so that every word shows where the stressed syllable is in the most economic way, making only a relatively small number of words accentuated.
Proparoxytones are the rarest words in portuguese, so all of them are accentuated. Paroxytones are the most common, so in all common endings, such as a(s), o(s), e(s) and em/ens they are not accentuated, and that already leaves a huge amount of words without accents. To complete that, all words with other endings and that have no graphic accent are deductively oxytones, leaving a whole bunch of other words without an accent and still showing where the tonicity is. It is quite smart.
If it uses the circumflex or an accute accet depends on the quality of the vowel, if it is more closed, the circumflex is used (â, ê, ô) and if it is more open, the acute accent is used (á, é, ó) — í and ú are used just to show tonicity.
This system we use today is recent, the latest "update", was made a few years ago in the last reform and it is adopted in every Portuguese-speaking country.
The whole diacritic thing started a long time ago. The tilde (ã, õ...), for instance, was invented during the Middle Ages to represent the nasalization of vowels, in fact it was originally a superscprit little N, the letter that represents the very sound that disappeared and left the nasal trace in the vowel during the evolution of the language. The cedilla (ç) originated from a small subscript Z. These were created to write the new sounds that emerged in the evolution, because there was no way to write them with the roman alphabet.
The grave accent (à) is used nowadays only when there is crasis, not to change the quality or show accentuation.
Portuguese makes a really good use of its five diacritics.