Transcript Sistemas Microcontrolados e Programação em C
Microprocessadores 8051 – Aula 3 Interrupção
Prof Afonso Ferreira Miguel
Interrupções
Mecanismos de Interrupção Introdução • Durante a execução normal de um programa um dispositivo pode requisitar a atenção (IRQ); • • Para atender a IRQ do dispositivo, este suspende a execução do programa e desvia para uma rotina de tratamento de interrupção (RTI) criada pelo usuário; Ao término da RTI, o processador continua a execução do programa principal anteriormente suspenso.
Interrupções
Mecanismos de Interrupção Introdução
IRQ
Main Program
x
RTI
Interrupções
Mecanismos de Interrupção RTI (recomendações) • • • • Rápida; Pequena; Salvar contexto; Para algoritmos complexos, utilizar máquinas de estado (Finite State Machine).
Interrupções
Estrutura de uma RTI
Salvar o contexto
: salvar variáveis comuns a RTI e programa principal ou outras RTIS (utiliza geralmente PUSHs);
Código da RTI
solicitou a RTI; : atende as requisições do dispositivo que
Restaurar o contexto
anterior; : recuperar o valor das variáveis salvas no item
RETI
: instrução que retorna da RTI.
Salvar o contexto Código da RTI Restaurar o contexto
RETI
Microcontrolador 8051 (MCS-51) TCON (0x88 ) IE (0xA8) IP (0xB8) SCON (0x98)
Microcontrolador 8051 (MCS-51) The 8051 provides 5 interrupt sources INT0 INT1 TF0 TF1 RI/TI
External Interrupts and can be either level or transition activated Timer 0 and 1 overflow/rollover activated Serial Port both receive and transmit
Since both TX and RX are the same interrupt, the service routine will have to determine which it was.
All the bits that generate interrupts can be set or cleared by software, with the same results as if they had been set or cleared by hardware.
Microcontrolador 8051 (MCS-51)
Microcontrolador 8051 (MCS-51)
Microcontrolador 8051 (Interrupções) Todas as fontes de interrupção podem ser individualmente habilitadas ou desabilitadas, ativando ou desativando bits em IE.
Microcontrolador 8051 (MCS-51)
Interrupts flags are sample at S5P2 of every machine cycle.
Microcontrolador 8051 (MCS-51) O 8051 realiza um LCALL para a correspondente RTI, exceto nas seguintes condições: Uma interrupção de igual ou maior prioridade está em execução; Uma instrução ainda não está completa; A instrução em progresso é uma RETI ou está sendo realizada uma escrita em IE ou IP.
Microcontrolador 8051 (MCS-51) Priority can be set by the software; All interrupts can either be set to a high or low priority.
Microcontrolador 8051 (MCS-51) Priority works as follows High-priority interrupts can not be interrupted; Low-priority interrupts can be interrupted ONLY by high-priority interrupts; If two request of different priorities occur ‘simultaneously’, the request with the higher priority is serviced;
Microcontrolador 8051 (MCS-51) Priority works as follows If request with the
same
priority occur ‘simultaneously’, then an internal polling sequence is used:
Microcontrolador 8051 (MCS-51) If none of the previous conditions have violated, then the 8051 will generate a LCALL to the appropriate serving routine. In most cases it also clears the flag that generated the interrupt.
Note: Serial Port flag is never cleared and as such must be handled by software
Microcontrolador 8051 (MCS-51) LCALL pushes the current contents of the Program Counter onto the stack and reloads an address that depends on the source of the interrupt; Execution proceeds until RETI is encountered. The execution of this command allows the 8051 to know that the current interrupt routine is no longer in progress The 8051 then reloads the Program Counter from the stack and continues from where is left off.
Microcontrolador 8051 (MCS-51) Interrupção: Estrutura em Assembly