Cannons

Photon Cannons are a building that can attack oncoming units. They are high-priority targets and generally your army can safely build up behind them until your cannon dies or the enemy's oncoming army is weakened enough for you to push it back. They cost 150 minerals to build.

They deal splash damage to targets near the primary victim of their attack.

Photon Cannons can be upgraded to Chelupa Cannons, which have more hitpoints and attack far faster for 300 minerals.

Repair! Repair! Repair!
It must be noted that Cannons do not recover hitpoints on their own! They need to be repaired by builders in order to survive!

While you may see a lot of players in public games insisting not to Nuke until AFTER a Cannon has perished, it is almost always a better idea to Nuke before it is about to die. You're wasting your investment in the Cannon and a Nuke when you wait until it dies!

When to use Cannons
When to use Cannons is a subject of much debate. Some players regard them as a staple in early game play when being pushed, and others regard them as a waste of money better used on units. Unlike unit-producing buildings, Cannons do not give any income. Placement and team-awareness is important when building a cannon, and it is a judgement call that is a tough consideration even for some of the most experienced players.

It's important to remember that while a Cannon can hold off enemies for some time, it costs a considerable amount of resources that are generally not immediately paid back. Using a Nuke in the same situation can turn the tides in your team's favor as well- it costs no resources, immediately gives you the bounty for the enemy units, and allows you time (albeit sometimes short) to spend the minerals you've gained and rebuff a push.