Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
EECS 203 Homework seven
When you can verify an answer, do so. I encourage you to use a PIC assembler and simulator to help you verify your answers. Show your work.
1. Consider the following sequence of PIC16C74A directives/pseudo-operations and instructions
BANKSEL TRISA
clrf TRISA
comf TRISA, F
(a) (5 pts.) Which of these are directives/pseudo-operations and which are instructions?
(b) (5 pts.) Use a sentence to describe the overall effect of this instruction sequence.
(c) (5 pts.) Assuming the output of a driver is connected to one of the pins on port a, why is this sequence of instructions potentially dangerous?
(d) (5 pts.) If your processor is clocked at 3 MHz, what is the maximum duration of the dangerous condition? Please refer to the Architectural Overview section in the PIC16C74A datasheet.
(e) (5 pts.) Write an instruction sequence that will safely accomplish the same thing as these potentially dangerous instructions.
(f) (5 pts.) Rewrite your answer to question 1e, replacing all directives with genuine sequences of instructions. Please refer to the Status Register documentation in the PIC16C74A datasheet.
(g) (5 pts.) Write the binary 14-bit opcode (including register specifiers) for each line of your answer to question 1f. Refer to the Table 15.2 in the PIC16C74A datasheet.
2. Consider the following subroutine
LOW_TICK equ 0x20
HIGH_TICK equ 0x21
delay_loop:
; Wait for 30 ms to make sure switch bouncing is finished
; 2 MHz clock, about 2 us per normal instruction, 4 us per taken loop
movlw d’30’
movwf HIGH_TICK
LONG_WAIT_LOOP
; Wait for approx. 1 ms
SHORT_WAIT
movlw d’100’
movwf LOW_TICK
; Loop body takes 10 us
SHORT_WAIT_LOOP
nop
nop
nop
decfsz LOW_TICK, F
goto SHORT_WAIT_LOOP
decfsz HIGH_TICK, F
goto LONG_WAIT_LOOP
return
(a) (5 pts.) Why is this subroutine broken into two loops instead of using only one loop?
(b) (10 pts.) Rewrite this subroutine such that, when called, it waits for 10 ms multiplied by whatever value was in the accumulator, W, when delay loop was called.
3. (5 pts.) In three or fewer sentences, describe use of the PIC16C74A’s FSR and INDF registers.
4. (0 pts.) Write a program in PIC assembly to find the maximum number out of a group of numbers. We have a group of n numbers, stored in a consecutive bytes of memory, the address to the first number is stored in register 0x20. The number n is stored in register 0x21. Please find the largest number out of these n numbers and store the result in register 0x22. Please refer to the documentation on indirect addressing on page 41 of the PIC16C74A datasheet.
5. (0 pts.) Write a program in PIC assembly to find the sum of a group of numbers. We have a group of n numbers, stored in a consecutive bytes of memory, the starting address of which is stored in register 0x20. The number n is stored in register 0x21. Please calculate the sum of the n numbers and save the result in register 0x22. Please refer to the documentation on indirect addressing on page 41 of the PIC16C74A datasheet.
6. (0 pts.) Write a program in PIC assembly to read numbers from PORTA and PORTB (assume you can read 8 bits numbers from the ports) and display a 0 in PORTC if the numbers are the 2’s complement representation of each other. Otherwise, display the larger of the 2 numbers at PORTC.
7. (0 pts.) What did you think of this homework assignment? Did walking through the code and giving referring to the datasheet help you understand the processor better? Did this assignment require enough creativity to be interesting?