How Crystals and RC Oscillators Work
We need a clock to know when to do something. Likewise the microcontroller or microprocesser also needs a clock. It will execute one or more instructions per clock tick. This clock works really faster than our clocks. There’s a speed limit for the microcontroller or microprocessor which is mentioned in the datasheets.
What happens in RC is that a capacitor charges through a resistor and when it reaches some voltage, it discharges through internal circuitry of the microcontroller. This happens again and again which produces a clock. This provides a simple clock but not accurate since capacitance changes in different temperatures.
This image is of a 4 MHz crystal. The crystal is a piezoelectric ceramic. When you alter dimensions of piezoelectric ceramic, a voltage appears across it. The inverse happens if you apply a voltage across it, it expands and contracts which ultimately results an electrical oscillation.
A crystal is very accurate up to 5 decimals. Crystals are used in every time sensitive applications. The watch you use right now is using a 32.768 kHz crystal as a reference clock to give you time of the day.