Homework

advertisement
EEE3205 Microprocessors
Lab Homework #1
Name Surname:
ID:
Date:
Give brief answers to the following questions. You can edit this document and insert your answers after
each question, but you must print it out and submit a hardcopy for grading. No email attachments will be
accepted. See the course website for the due date for your class section.
1. Why is the first ‘banksel’ statement in lab02.asm unnecessary?
2. Rebuild (assemble, compile) the lab02.asm source code. Select ViewDisassembly Listing. Find the first
‘banksel’ directive. Notice that two instructions are associated with this directive. List the two instructions
and also give the more readable versions of these instructions.
3. When using the PICkit2 in debugging mode, certain resources on the PIC are reserved for the debugger. The
PICkit2 uses the same resources as the MPLAB ICD 2. Refer to the MPLAB ICD 2 Help, found in the
MPLAB IDE under HelpTopics and find the discussion on reserved resources.
a. Which pins (by name and pin number) are reserved for the PICkit2 debugger?
b. Which program memory addresses are reserved? (Give answers in hex and decimal.)
c. Open the Program Memory window. What is the opcode listed for the reserved registers in (b)?
d. Which data memory addresses are reserved? (Give answers in hex and decimal.)
e. Open the File Registers window. What is listed as the content of the reserved registers in (d)?
4. Refer to the description of the ADCON1 register in the PIC data sheet. Here is the table that shows the bit
names and locations in the register:
There are two errors in the labels in this table. What are they?
5. Suppose that the oscillator frequency is 4 MHz and OPTION_REG = 0000 0011. How often will Timer0
roll over?
6. Suppose that you wanted to use an external voltage source to supply Vref+ and Vref- for the A/D converter.
Suppose also that you wanted exactly two analog inputs for A/D conversion. What pin would you use for
Vref+ and what pin for Vref- ? (Give the names and pin numbers.) If you wanted the output of the A/D
converter to be left-justified, how should the eight bits of the ADCON1 register be set? Give the answer in
binary.
Page 1 of 2
7. Suppose the clock frequency is 10 MHz, and ADCON0 = 1000 0001. What is the ADC clock period? How
many microseconds does it take to convert one ADC sample?
8. Suppose your ADC references voltages in Lab02 were exactly 0.0 and 5.0 volts, and the input voltage was
exactly 1.3 volts. What would be the binary and hex values of ADRESH and ADRESL? (Hint: See the A/D
Result Registers topic in the data sheet.)
9. Close the lab02 project. Create a new folder called lab02_modified. Place a copy of lab02.asm in this folder
and rename it to lab02_modified.asm. Create a new project called lab02_modified in this folder using the
lab02_modified.asm file, and then run it and test your circuit.
Cut the following two instructions from their current location in the code and paste them right after the
‘movwf ADCON0’ instruction.
movlw
B'00001110'
movwf
ADCON1
Build, download, and run the code. What happens? Explain why.
10. Remove any code related to the A/D conversion. We will not be converting analog to digital in this exercise.
Modify the code so that PORTC is initially cleared and then is incremented every time Timer0 rolls over.
So, the LEDs will count from 0 to 255 until PORTC rolls over. When PORTC rolls over, leave the
increment loop and enter the pushbutton loop. You can achieve this by using the ‘incfsz’ instruction to
increment PORTC.
Rename the button loop to ‘LoopUntilPressed’ and use the instruction ‘btfsc’. This will cause the processor
to stay in the loop until the button is pressed. When the button is pressed, return to MAIN, and the LEDS
will begin to count again.
Calculate how long it takes the LEDs to count from all-off to all-on’? Answer to the nearest hundredth of a
second, and verify your answer approximately by observation.
Page 2 of 2
Download