Microcontrollers: Class 3: Interrupts
Microcontrollers: Class 3: Interrupts
Microcontrollers: Class 3: Interrupts
Class 3: Interrupts
Outline
Interrupts
External Interrupts
Interrupts
External Interrupts
Outline
Interrupts
External Interrupts
Polling
Event-Driven Programming
Interrupts
External Interrupts
External Interrupts
Examples
External Interrupts
Summary
External Interrupts
Misc Points
I You can use the light/heavy model to prioritize interrupts:
heavies happen immediately and pre-empt, lights happen in
the mainloop
I Can set INT0, INT1 interrupts for rising, falling, toggle, or
low state triggers
I The interrupt pins can still be used as output
can set an interrupt pin high in software to fire interrupts
I Debouncing becomes easier with timers, next class
Other Examples
Pin-Change Interrupts
Pin-Change Interrupts
Summary
Interrupts
External Interrupts
Interrupt-driven USART
Interrupt-driven USART
Transmit Version?
I Sure!
I Imagine you were sending short bits of bursty data, too much
for the serial baudrate
I Create an ISR thats triggered by the USART TX interrupt,
so that every time a transmission is complete, the next begins
I In ISR, check to see if your transmit buffer has entries. If it
does, transmit them and advance the buffer.
I In your mainloop, you just need to put your data into the
buffer the ISR will take care of sending it along when it can
Interrupt-driven ADC
Homework
I Every time you get a value on the ADC, send it out over serial
I This should be all configuration your mainloop can be empty
I The rest is code on your computer.
Next Class
Timers!
I Weve been doing a lot of for loops with delays in them
I Want a hardware-based way to count time or waste time
I Timers and counters!
I Its even better the timers can fire off interrupts
The End
Outline