Академический Документы
Профессиональный Документы
Культура Документы
EEE-347/CNG-336 INTRODUCTION TO
MICROPROCESSORS / EMBEDDED SYSTEMS DEVELOPMENT
Spring-2017
Midterm Exam 2
Full Name:...................................................................................................
Student Number:.........................................................................................
SCORE
Q-1
Q-2
Q-3
Q-4
TOTAL
Q-1 (25 pts.)
d) (4 pts.) Which of the following codes run faster? Circle (i) or (ii) ?
(i) (ii)
z = z ^ 0x0A50;
PORTC changes state every 1 sec. When the mode of operation changes, PORTC continues
counting or shifting from its current state.
Assume that there exists a library function void Delay_1sec(void) and the operation
continues forever. Also assume that status register SREG and the carry bit CARRY are also
defined in the header file io.h.
#include <avr/io.h>
int main(void)
{
DDRB = DDRB & ~(1<<3);
DDRB = DDRB & ~(1<<5);
DDRC = 0xFF;
while (1)
{
if (~(PINB & (1<<3)) & ~(PINB & (1<<5))) PORTC++;
if (~(PINB & (1<<3)) & (PINB & (1<<5))) PORTC--;
if ((PINB & (1<<3)) & ~(PINB & (1<<5)))
{
PORTC = PORTC << 1;
if (SREG.Carry) PORTC = PORTC | 0x01;
}
if ((PINB & (1<<3)) & (PINB & (1<<5)))
{
PORTC = PORTC >> 1;
if (SREG.Carry) PORTC = PORTC | 0x80;
}
Delay_1sec();
}
return(0);
}
Q-2 (25 pts.)
A memory system for a processor whose address bus is 16-bit wide is given below (data bus
connections, control signal connections, etc. are not shown for simplicity).
0 CS
A14 A (LSB) 1
A15 B (MSB) 2
3
E 2x4 Decoder ROM2 (2K)
0 CS
A12 A (LSB) 1
A13 B (MSB) 2
3
E
2x4 Decoder RAM1 (1K)
0 CS
A10 A (LSB) 1
A11 B (MSB) 2
3
E
2x4 Decoder RAM2
(512 Byte)
0 CS
A9 A (LSB) 1
0 B (MSB) 2
3
E
Note that:
CS CS
a) Give the memory map from $0000 to $FFFF by clearly indicating the address ranges
corresponding to each chip also indicating clearly the overlay area and the unused area.
A15 A14 A13 A12 A11 A10 A9 A8 ……… A1 A0
0 0 X X X X X X ……… X X ROM1 (with overlay)
1 1 0 0 X X X X ……… X X ROM2 (with overlay)
1 1 1 1 0 0 X X ……… X X RAM1 (no overlay)
1 1 1 1 1 1 0 X ……… X X RAM2 (no overlay)
a) (6 pts.) The following is the functional block diagram of Timer/Counter0 in AVR family
microcontrollers. Describe briefly how the circuit functions, clearly stating the role of each block
and signal separately.
b) (2 pts.) State the two major differences between Timer/Counter0 and 1.
Timer mode uses internal CPU clock and the clock can be pre-scaled.
Counter mode uses an external signal as the clock and active transition can be defined
to be positive or negative edge.
d) (15 pts.) Write a program in AVR assembly language that will generate a 694 Hz square wave
at PORTB.3 using CTC mode of Timer0 by ignoring the instruction overheads and by assuming
XTAL = 8 MHz.
Treq/2/Tclk = 720 microsec / 0,125 microsec = 5760 ticks per timer period
a) (20 pts.) Analyze the following code and describe its function in a couple of sentences. What
does it do? Assume XTAL = 8 MHz.
#include <avr/io.h>
#include <avr/interrupt.h>
int main()
{
DDRA = 0xFF;
DDRC = 0x00;
PORTC = 0xFF;
DDRD = 0xFF;
DDRB |= 0x40;
PORTB &= ~(0x40);
TCNT0 = -200;
TCCR0 = 0x06; //normal mode, falling edge, no prescaler
TIMSK = (1<<TOIE0)|(1<<TOIE1);
sei();
while (1)
PORTD = PINC;
}
ISR (TIME0_OVF_vect)
{
TCNT0 = -200;
PORTB ^= 0x40;
}
ISR (TIME1_OVF_vect)
{
TCNT1H = (-31250) >> 8;
TCNT1L = (-31250) & 0xFF;
PORTA++;
}
2- PORTA simultaneously counts up each time Timer1 overflows, which overflows once
every second (1 sec = 31250 x 1 / (8 x 106 / 256))
3- A pulse that is fed into T0 pin is also simultaneously counted. Whenever this count
value reaches 200, pin PORTB.6 is toggled.
a) (5 pts.) State whether the following statements are true or false.
ii) The AVR programmer cannot change the memory address location assigned to the interrupt
vector table.
True / False
iv) An address location is assigned to each of the external hardware interrupts INT0, INT1 and INT2.
True / False
v) If two interrupts arrive at the same time, one of them is arbitrarily chosen and served.
True / False
TIMER RELATED REGISTERS
INTERRUPT RELATED REGISTERS
SREG I T H S V N Z C
ISCn1,ISCn0
00: low-level
10: falling edge
11: rising edge
(01: reserved)