Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HW4 (Due in Class on Thursday, Nov. 9) 1. Write an instruction sequence to (5 ea

ID: 2249461 • Letter: H

Question

HW4 (Due in Class on Thursday, Nov. 9) 1. Write an instruction sequence to (5 each) (a) pull PA7, PA5, PA3, and PA1 pins to high without affecting other PORTA pins (b) pull PB6, PB4, PB2, & PBo pins to low without PORTB pins (c) toggle PCS, PC4, PC3 pins without other PORTC pins (d) read the voltage levels on PORTB pins and place value in register 20 (e) output the value ox53 to PORTA 2. Write an instruction sequence to configure PC7 & PCS pins to INTo with high priority and PC1 & PC3 pins to INT1 with low priority and enable interrupt globally.(10) 3. For the circuit shown in following figure, write a program to turn on one LED at a time from top to bottom and then from bottom to top. When turn on LEDs from top to bottom, the turn- on time from top to bottom are 800ms (top), 700 ms,. 100 ms (bottom). When turn on LEDs from bottom to top, the turn-on time for LEDs are 800 ms (bottom), 700 ms, and 100 ms (top). The delayby100ms subroutine is available for you to call. The multiple of the delay is passed in r16. (15) include catxmega128A1definc> def temp r16 .cseg org 0x00 rjmp start org 0xF6 Idi temp,low(RAMEND) out CPU SPLtemp ldi temp,high(RAMEND) : out CPU SPH,temp call setCPUCIkto32Mwith16MCrystal ldi 20,0xFF start: initialize the SP

Explanation / Answer

Answer:-1)a) To pull pins PA7, PA5, PA3 and PA1 as high, these pin must be configured as output pin. So the code is-
IN R16, DDRA      ;read DDRA and move to R16 register
ORI R16, 0xAA    ;to make pin position of 7,5,3 and 1 as high, rest pin values unaffected
OUT DDRA, R16 ;DDRA = R16, make the pins 7, 5, 3 and 1 as output pin, rest unaffected
IN R16, PINA ;read PORTA register
ORI R16, 0xAA     ;make bit positions 7, 5, 3 and 1 as high in R16 register
OUT PORTA, R16 ;make the pins high now

b) IN R16, DDRB ;read DDRB and move to R16 register
ORI R16, 0x55    ;to make pin position of 6, 4, 2 and 0 as high, rest pin values unaffected
OUT DDRB, R16 ;DDRB = R16, make the pins 6, 4, 2 and 0 as output pin, rest unaffected
IN R16, PINB       ; read PORTB register
ANI R16, 0xAA    ;make pins 6, 4, 2 and 0 as 0
OUT PORTB, R16 ;make the pins low now.

c) IN R16, DDRC ;read DDRC and move to R16 register
ORI R16, 0x38    ;to make pin position of 5, 4 and 3 as high, rest pin values unaffected
OUT DDRC, R16 ;DDRC = R16, make the pins 5, 4 and 3 as output pin, rest unaffected
IN R16, PINC    ; read PORTC register
LDI R17, 0x38     ;R17 = 0011_1000
EOR R16, R17    ;R16 = R16 xor R17
OUT PORTC, R16 ;toggle pins 5,4 and 3 without affecting rets pins on port c.

d) IN R20, PINB   ;read port B and store in R20

e) LDI R16, 0xFF   ;R16 = 1111_1111
OUT DDRA, R16   ;make oprt A as output pin
LDI R16, 0x53      ; load R16 with value 0x53
OUT PORTA, R16 ;write the value 0x53 to port A