Microprocessors I
Download
Report
Transcript Microprocessors I
16.317
Microprocessor Systems Design I
Instructor: Dr. Michael Geiger
Fall 2014
Lecture 31:
PIC exam practice problems
Lecture outline
Announcements/reminders
HW 5 due Monday, 12/1
HW 6 due Wednesday, 12/10
No more lectures of new material
Exam 3: Monday, 12/15, 3:00-6:00 PM
Next lecture: Exam 3 Preview, Wednesday, 12/10
I’ll be in my office at 8:00 every MWF until classes end
(with the exception of Wednesday, 11/26)
Will need to complete course eval (to be posted online)
prior to exam
Today’s lecture: Exam practice problems
7/18/2015
Microprocessors I: Lecture 31
2
Review: Analog to digital conversion
10-bit resolution (result = (V / VREF) * 1023)
Configuration requires
Choosing reference voltage
Choosing conversion speed via clock source
Appropriate bit(s) = 1 in ANSELx register
Left- or right-justifying result
11 channels split across ports A, B, C
Configuring input channel(s) as analog input(s)
Divided system clock or external oscillator
Choosing input channel
VDD/VSS, internal fixed voltage ref, or external source
L: ADRESH = upper 8 result bits, lower 6 bits of ADRESL = 0
R: ADRESL = lower 8 result bits, upper 6 bits of ADRESH = 0
Setting ADON bit in ADCON0
Conversions
Wait ~5 us for charging cap to settle
Assert GO bit in ADCON0
7/18/2015
Bit will be cleared when conversion is complete
Microprocessors I: Lecture 31
3
Exam practice problems
Two problems from Spring 2014 exam
Given short, partially complete programs to
be completed
Comments next to each blank tells you what
statement(s) in those spaces should do
7/18/2015
Microprocessors I: Lecture 31
4
Example 1 solution
void interrupt ISR(void) {
if (IOCAF) {
IOCAF = 0;
__delay_ms(5);
if (SWITCH == DOWN) {
LATC = 0;
i = 0;
}
}
if (INTCONbits.T0IF) {
INTCONbits.T0IF = 0;
LATC = st[i];
//
//
//
//
//
//
SW1 was pressed
Clear flag in software
Delay for debouncing
If switch still pressed
clear LEDs
and reset i
i++;
//
//
//
//
//
Timer 0 interrupt
Clear flag in software
Update LEDs to show
current st[] value
Increment i
if (i > 7)
i = 0;
// If i exceeds max index
//
reset i
}
}
7/18/2015
Microprocessors I: Lecture 31
5
Example 2 solution
void read_adc(void) {
unsigned char lobits;
//
//
//
//
//
__delay_us(5);
GO = 1;
while (GO) continue;
lobits = ADRESL & 0x03;
if (lobits == 0b01) {
LATC = LATC ^ 0x01;
}
else if (lobits == 0b10) {
LATC = LATC ^ 0x02;
}
else if (lobits == 0b11) {
LATC = LATC | 0x03;
}
Variable to hold lowest 2
bits of ADC result
Wait for ADC cap to settle
Start conversion
Wait until conversion done
// lobits = lowest two bits
//
of ADC result
// In this case, toggle
//
lowest LED
// In this case, toggle
//
second LED
// In this case, turn first &
//
second LEDs on
}
7/18/2015
Microprocessors I: Lecture 31
6
HW 6 notes
Will write three programs
Display sequence of values on LEDs, changing
once per second
Count button presses and display count on LEDs
Variable speed/direction LED rotation
Specification also contains helpful hints for
setting up and completing programs
7/18/2015
Microprocessors I: Lecture 31
7
Final notes
Next time:
Exam 3 Preview (Wednesday, 12/10)
Reminders:
HW 5 due Monday, 12/1
HW 6 due Wednesday, 12/10
No more lectures of new material
Exam 3: Monday, 12/15, 3:00-6:00 PM
7/18/2015
I’ll be in my office at 8:00 every MWF until classes end (with
the exception of Wednesday, 11/26)
Will need to complete course eval (to be posted online) prior
to exam
Microprocessors I: Lecture 31
8