Note: This is straight from wikipedia. :wacko:
Prologue: Rising of the Catalans
Louis the Pious, son of Charlemagne, captured Barcelona in 801 after a siege of several months. It was to be the most southerly of his gains from Moors as he was pushed back from Tortosa, and the rivers Llobregat and Cardener marked the boundaries of the Carolingian possessions. The border regions were organised into the Spanish Marches (Marca Hispanica), administered by a number of counts appointed by the King, and Barcelona became the seat of a county.
The first Carolingian Counts of Barcelona were little more than royal administrators, but the position steadily gained in power and independence from the central rule with the weakening of the Carolingian kings. At the same time, several of the counties of the Spanish Marches came to be ruled by the same individual. The last Count of Barcelona to be appointed by the Carolingian authorities was Wilfred the Hairy (Catalan: Guifré el Pelós) at the Assembly of Troyes in 878: Wilfred, who was already Count of Cerdanya and Urgell, also received the counties of Girona and Besalú. At his death in 897, Wilfred's possessions were divided between his sons Wilfred II Borrel, Sunyer and Miró the Younger, marking the beginning of a hereditary régime. Wilfred II Borrell was the last of the Counts of Barcelona to pledge fidelity to the Carolingian court.
The preeminence of the Counts of Barcelona among the nobility of the Spanish Marches was in part due to their ability to expand their territory by conquests from the Moorish walís. They also repopulated their inland realms, whose population had plummeted after two centuries of war. The city of Barcelona, easily defensible and with excellent fortifications, prospered with the increasing power of its overlords, while the other Marcher counties had more limited prospects.