Microcontroller family => same microprocessor (different memory, I/O etc.)
Microcontroller
Memory
on chip peripherals
I/O
Heterogeneous memory mapped to one address space ( or mapped by compiler )
Usually:
Registers used for DIO:
DDR (Data Direction Register)
PORT (Port Register)
PIN (Port Input Register)
The Schmitt trigger can be used, when the inputs voltage levels are not well defined. It has a threshold Vmax over which it switches to a high output and a threshold Vmin under which it switches to a low output. Importantly, the Vmax >> Vmin, so that the output doesn’t flicker between high and low. It always outputs a clear Vcc or 0V.
Data can also be noisy in the time domain. (e.g. button bouncing)
There are different solutions to this.
Polling is where the code manually checks if an event happened. It has the disadvantage of wasting cpu cycles and making the code harder to modify.
Interrupts solve this by offloading the polling to the hardware. If a state change is detected the program is interrupted and an interrupt service routine is called.
Interrupts have to be activated by modifying the according registers
ATmega uses an interrupt vector table. A jump instruction to the according ISR body must be placed that each address. Empty vectors should point to an infinite loop (trap).
MCU monitors certain events and sets the respective flags. The three bits that need to be set in order for an ISR to be called:
Conflicting Interrupts can be resolved by the static or dynamic priorities. Static means they are set by the manufacturer and dynamic priorities can be set by the user.
When an ISR is triggered the following steps are executed in order:
leave ISR by assembly instruction RETI
Interrupts should be favored if:
Polling might be a better choice if: