From Tacna in the south to Tumbes in the north, 5 million Peruvians went to the polls yesterday for the first time in 15 years. Half of those who voted had not participated in an election before.

Here in Trujillo, a rural city six hours' drive north of Lima that retains its colonial charm and provincial way of life, a serious but friendly mood prevailed as voters nationwide chose among 1,200 candidates for 100 seats in a constituent assembly that will prepare the way for a restoration of democratic government by 1980.

Men and women waited patiently at hundreds of voting tables scattered throughout the city, munching on little cakes that seem to be a specialty here or talking quietly among themselves. Many gathered afterwards in the central Plaza de Armas to discuss the candidates they had voted for, their country's desperate economic situation or the drought that has hurt production on the sugar cooperatives that dot the countryside not far from here.

Armed soldiers were assigned to each of the more than 28,000 polling stations throughout the country but there was no sign of trouble in Trujillo. The townspeople seemed to enjoy their opportunity to vote and the excuse it gave them for meeting their neighbors and friends in the noonday sun.

Sometimes today, if all goes according to plan, partial results will indicate which of the 12 political parties, ranging from ultra left to extreme right, that participated in the election will be represented in the consituent assembly. Seats will be divided according to the proportion of votes each party receives.

The assembly is to spend year drafting a new constitution for this nation of 16 million people on South America's west coast. Once the constitution is completed, President Francisco Morales Bermudez has promised that he will call general elections in late 1979 or 1980, thus ending the succession of military governments that have ruled since 1968, when the army overthrew the last elected president, Fernando Belaude Terry.

Peruvians have become deeply disenchanted with the military in recent years as economic and social policies contributed to a deep depression and brought the country to the verge of international default only a month ago.

Yesterday's election was being watched with great interest because the results should foretell the style of government to take power a year or two from now and, thus, which direction Peru will take to solve its severe, long-term economic problems.

The election was also being watched with quiet satisfaction by the Carter administration, which hopes that Peru will provide an example for other Latin American military governments, such as those in Argentina and Uruguay, that have, as yet, shown no signs of moving towards a restorations of democratic rule.

Next month, on the other hand, Bolivia and Ecuador are to hold general elections and exchange their military rulers for civilian governments.

For the past week, Peruvians have been bombarded by leaflets, speeches, outdoor rallies and radio and television commercials as the political campaigning, which began in January, resumed after a three-week, enforced lull. The government banned all political activity in mid-May after a series of harsh economic austerity measures provoked a two-day nationwide general strike that was accompanied by violence in several cities.

Although 12 parties put up slates of candidates, the election came down to a contest among the center-right Popular Christian party of Luis Bedoya Reyes, the center-left Apra Party of Victor Raul Hay de la Torre and six leftist parties that, together, are expected to receive between 15 and 20 percent of the vote.

Belaunde's Popular Action Party decided against participating for tactical reasons.

Rather than attacking each other during the campaign, most of the parties concentrated their fire at the government and its 10-year record.

The leftists argued that the generals, who came in promising "a revolution neither capitalist nor communist," had not gone far enough in enacting socialist reforms. The rightists said the government has gone too far while Haya de la Torre, a fixture of Peruvian political life since 1923, spoke in eloquent generalities, attempting to persuade his partisans that he was the man to lead the country through the year of constitution-writing and on to a more hopeful future.

The great unknown in how the approximately 2.5 million Peruvians who were too young to vote in the last nationwide election responded to the political sloganeering and appeals. Peruvian politics remains highly personalized, with parties built around individual politicians, although it may be that the better educated young will respond more readily to ideas than to personalities.

Nonetheless, here in Trujillo, where Haya de la Torre was born 83 years ago, APRA remains a force to be reckoned with and Victor Raul, as every one calls him, retains his grip on political life.

More than 35,000 people turned out for an APRA rally Friday night in the Plaza de Armas, a spectacular pageant of bands and speeches and parades and fireworks.

Once considered a dangerous radical for advocating economic and social reforms, Haya de la Torre influenced a generation of latin American politicians who read his books and essays calling for an end to imperialism, for internationalization of the Panama Canal and for a United States of Latin America -- 50 years ago.

Twice elected president of Peru and twice denied the right to serve -- once outright by the military and once as a result of vote counting irregularities -- Haya de la Torre would like to end his political career as president of the constituent assembly that will write Peru's new constitution.

The final results of yesterday's election will be known within 10 days.