Professional Documents
Culture Documents
LECTURE# 13
MICROPROCESSOR SYSTEMS AND INTERFACING
In our case
◦ ISR is a subroutine, executed only when particular interrupt occurs
◦ SPI, I2C 14
15
0x001A
0x001C
TIMER1_OVF
TIMER0_COMPA
Timer/Counter1 Overflow
Timer/Counter0 Compare Match A
16 0x001E TIMER0_COMPB Timer/Counter0 Compare Match B
Like TOV0, OCF0 flags, there are INTF0 and INTF1 in EIFR
◦ EIFR
◦ When an external interrupt is generated
◦ The corresponding flag is set
◦ If polling, the flag is manual cleared by writing 1 to it
◦ Means either no external interrupt is enable in EICR or global interrupt is disabled
◦ When using interrupts, the flag is automatically cleared
◦ Resources (registers and status flags) .ORG 0x14 ;location for TimerO compare match
should be managed carefully .ORG 0x100
JMP T0_CM_ISR
;-main program for initialization and keeping CPU busy
MAIN: LDI R20, HIGH(RAMEND)
Resource conflicts can occur OUT
LDI
SPH, R20
R20, LOW(RAMEND)
◦ When main program and ISR uses OUT
SBI
SPL, R20
DDRB, 5
;set up stack
;PB5 as an output
◦ Same registers or status flags LDI R20, (1<<OCIE0)
OUT TIMSK, R20 ;enable Timer0 compare match interrupt
SEI ;set I (enable interrupts globally)
Consider Program 10-4 LDI R20, 160
OUT OCR0, R20 ;load Timer0 with 160
◦ Main program increments R20 LDI R20, 0x09
OUT TCCR0, R20 ;CTC mode, int clk, no prescaler
◦ And write it to PORTC LDI R20, 0xFF
OUT DDRC, R20 ;make PORTC output
◦ ISR copies PIND To R20 increments it OUT DDRD, R20 ;make PORTD output
and writes it to PORTD LDI R20, 0
HERE: OUT PORTC, R20 ;PORTC = R20
◦ Do you see an issue here? INC R20
JMP HERE ;keeping CPU busy waiting for interrupt
.ORG 0x200
So, conflicting resources are copied T0_CM_ISR:
IN R20, PIND
ISR for Timer0 Compare Match