18
Microprocessadores Microprocessadores 8051 – Aula 3 8051 – Aula 3 Interrupção Interrupção Prof Afonso Ferreira Prof Afonso Ferreira Miguel Miguel

Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Embed Size (px)

Citation preview

Page 1: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

MicroprocessadoresMicroprocessadores8051 – Aula 38051 – Aula 3InterrupçãoInterrupção

Prof Afonso Ferreira MiguelProf Afonso Ferreira Miguel

Page 2: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

InterrupçõesInterrupções

Mecanismos de InterrupçãoMecanismos de Interrupção IntroduçãoIntrodução

• Durante a execução normal de um programa um Durante a execução normal de um programa um dispositivo pode requisitar a atenção (IRQ);dispositivo pode requisitar a atenção (IRQ);

• Para atender a IRQ do dispositivo, este suspende Para atender a IRQ do dispositivo, este suspende a execução do programa e desvia para uma rotina a execução do programa e desvia para uma rotina de tratamento de interrupção (RTI) criada pelo de tratamento de interrupção (RTI) criada pelo usuário;usuário;

• Ao término da RTI, o processador continua a Ao término da RTI, o processador continua a execução do programa principal anteriormente execução do programa principal anteriormente suspenso.suspenso.

Page 3: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

InterrupçõesInterrupções

Mecanismos de InterrupçãoMecanismos de Interrupção IntroduçãoIntrodução

MainProgram

IRQ x RTI

Page 4: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

InterrupçõesInterrupções

Mecanismos de InterrupçãoMecanismos de Interrupção RTI (recomendações)RTI (recomendações)

• Rápida;Rápida;• Pequena;Pequena;• Salvar contexto;Salvar contexto;• Para algoritmos complexos, Para algoritmos complexos,

utilizar máquinas de estado utilizar máquinas de estado (Finite State Machine).(Finite State Machine).

Page 5: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

InterrupçõesInterrupções Estrutura de uma RTIEstrutura de uma RTI

Salvar o contextoSalvar o contexto: salvar variáveis : salvar variáveis comuns a RTI e programa principal comuns a RTI e programa principal ou outras RTIS (utiliza geralmente ou outras RTIS (utiliza geralmente PUSHs);PUSHs);

Código da RTICódigo da RTI: atende as : atende as requisições do dispositivo que requisições do dispositivo que solicitou a RTI;solicitou a RTI;

Restaurar o contextoRestaurar o contexto: recuperar o : recuperar o valor das variáveis salvas no item valor das variáveis salvas no item anterior;anterior;

RETIRETI: instrução que retorna da : instrução que retorna da RTI.RTI.

Salvar ocontexto

Código da RTI

Restauraro contexto

RETI

Page 6: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

TCON (0x88TCON (0x88)) IE (0xA8)IE (0xA8) IP (0xB8)IP (0xB8) SCON (0x98)SCON (0x98)

Page 7: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

The 8051 provides 5 interrupt sourcesThe 8051 provides 5 interrupt sources

INT0 INT0 INT1INT1 TF0TF0 TF1TF1 RI/TIRI/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.

Page 8: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Page 9: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Page 10: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 Microcontrolador 8051 (Interrupções)(Interrupções)

Todas as fontes de Todas as fontes de interrupção podem interrupção podem ser individualmente ser individualmente habilitadas ou habilitadas ou desabilitadas, desabilitadas, ativando ou ativando ou desativando bits em desativando bits em IE.IE.

Page 11: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Interrupts flags are sample at Interrupts flags are sample at S5P2 of every machine cycle.S5P2 of every machine cycle.

Page 12: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

O 8051 realiza um LCALL para a O 8051 realiza um LCALL para a correspondente RTI, exceto nas correspondente RTI, exceto nas seguintes condições:seguintes condições: Uma interrupção de igual ou maior Uma interrupção de igual ou maior

prioridade está em execução;prioridade está em execução; Uma instrução ainda não está completa; Uma instrução ainda não está completa; A instrução em progresso é uma RETI A instrução em progresso é uma RETI

ou está sendo realizada uma escrita em ou está sendo realizada uma escrita em IE ou IP.IE ou IP.

Page 13: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Priority can be set by Priority can be set by the software;the software;

All interrupts can All interrupts can either be set to a high either be set to a high or low priority.or low priority.

Page 14: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Priority works as followsPriority works as follows High-priority interrupts can not be interrupted;High-priority interrupts can not be interrupted; Low-priority interrupts can be interrupted Low-priority interrupts can be interrupted

ONLY by high-priority interrupts;ONLY by high-priority interrupts; If two request of different priorities occur If two request of different priorities occur

‘simultaneously’, the request with the higher ‘simultaneously’, the request with the higher priority is serviced;priority is serviced;

Page 15: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Priority works as followsPriority works as follows If request with the If request with the samesame priority occur priority occur

‘simultaneously’, then an internal polling ‘simultaneously’, then an internal polling sequence is used:sequence is used:

Page 16: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

If none of the previous conditions have If none of the previous conditions have violated, then the 8051 will generate a violated, then the 8051 will generate a LCALL to the appropriate serving routine. LCALL to the appropriate serving routine. In most cases it also clears the flag that In most cases it also clears the flag that generated the interrupt.generated the interrupt. Note: Serial Port flag is never cleared and as Note: Serial Port flag is never cleared and as

such must be handled by softwaresuch must be handled by software

Page 17: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

LCALL pushes the current contents of the Program LCALL pushes the current contents of the Program Counter onto the stack and reloads an address that Counter onto the stack and reloads an address that depends on the source of the interrupt;depends on the source of the interrupt;

Execution proceeds until RETI is encountered. The Execution proceeds until RETI is encountered. The execution of this command allows the 8051 to know that execution of this command allows the 8051 to know that the current interrupt routine is no longer in progressthe current interrupt routine is no longer in progress

The 8051 then reloads the Program Counter from the The 8051 then reloads the Program Counter from the stack and continues from where is left off.stack and continues from where is left off.

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Page 18: Microprocessadores 8051 – Aula 3 Interrupção Prof Afonso Ferreira Miguel

Microcontrolador 8051 (MCS-51)Microcontrolador 8051 (MCS-51)

Interrupção:Interrupção: Estrutura em Estrutura em

AssemblyAssembly