This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:avr:external_interrupts [2010/03/04 13:47] – Translation in progress yllars | en:avr:external_interrupts [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== External | + | ====== External |
- | External interrups are one of the most simple peripheral functions. AVRs typically | + | External interrups are one of the most simple peripheral functions. |
- | To use an external interrupt, the pin has to be configured as standard IO input (it can also be used as an output, but in this case the interrupt can only be created by the controller itself). It is necessary to allow receiving interrupts and specify the condition that causes the interrupt to fire in the external interrupt configuration register. There are four possible conditions: | + | To use an external interrupt, the pin has to be configured as a standard IO input (it can also be used as an output, but in this case the interrupt can only be created by the controller itself). It is necessary to allow receiving interrupts and specify the condition that causes the interrupt to fire in the external interrupt configuration register. There are four possible conditions: |
* Logical zero (voltage of 0V) | * Logical zero (voltage of 0V) | ||
Line 10: | Line 10: | ||
* Rising front - logical change from zero to one. | * Rising front - logical change from zero to one. | ||
- | Katkestuse tekitamiseks loogilise nulli valimisel tekitatakse katkestust järjest senikaua, kuni viigu väärtus on null. Põhiprogrammi töö on samal ajal peatatud. | ||
- | Lähtudes tööpõhimõttelt, on väliseid katkestusi kahte liiki: kontrolleri taktiga sünkroniseeritud ja asünkroonsed. Sünkroniseeritud katkestused toimivad sisendite väärtuse meelespidamise teel, mis tähendab, et loogilised muutused leitakse kahel erineval taktil saadud väärtuste võrdlemise teel. Kui välise signaali loogilised muutused toimuvad kiiremini, kui käib töötakt, siis katkestused, | + | When the mode is set to logical zero, the interrupt will fire continuously as long as the pin has a value of zero. During this period the execution of the main program is stopped. |
- | ~~PB~~ | + | Grouped by principle, there are two types of interrupts: synchronized to the controller' |
- | <box 100% round # | + | <pagebreak> |
- | Vaja on panna ATmega128 | + | <box 100% round # |
+ | |||
+ | Task: Make ATmega128 | ||
<code c> | <code c> | ||
#include < | #include < | ||
- | // Välise katkestuse programm | + | // The code of the external interrupt |
ISR(INT7_vect) | ISR(INT7_vect) | ||
{ | { | ||
- | // Tee midagi | + | // Do something |
} | } | ||
int main() | int main() | ||
{ | { | ||
- | // Siini E viigu 7 muutmine sisendiks biti 7 nullimise teel | + | // Change pin 7 on bus E to an input by changing bit 7 to zero |
DDRE &= ~(1 << PIN7); | DDRE &= ~(1 << PIN7); | ||
- | // Siini E viigule 7 pull-up | + | // Defining a pull-up |
+ | // to prevent input floating | ||
PORTE |= (1 << PIN7); | PORTE |= (1 << PIN7); | ||
- | // Väliste katkestuste seaderegistris katkestuse | + | // Set the interrupt mode to logical change for interrupt |
- | // tekitajaks loogilise muutuse määramine | + | // in the external interrupt configuration register |
EICRB = (1 << ISC70); | EICRB = (1 << ISC70); | ||
- | // Välise katkestuse | + | // Allow external interrupt |
EIMSK |= (1 << INT7); | EIMSK |= (1 << INT7); | ||
- | // Globaalne katkestuste lubamine | + | // Allow global interrupts |
sei(); | sei(); | ||
- | // Lõputu programmitsükkel | + | // Endless loop |
while (1) continue; | while (1) continue; | ||
} | } | ||
Line 54: | Line 56: | ||
</ | </ | ||
- | Lisaks üksikute viikude tekitatavatele katkestustele on suurematel | + | In addition to interrupts fired by single pins, if the AVR has enough pins it is possible to use entire groups of pins to fire logical value change interrupts. These interrupts are simply called |