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

Q1) Write an instruction sequence to output the value 0x53 to PORTA. Q2) Write a

ID: 3602303 • Letter: Q

Question

Q1) Write an instruction sequence to output the value 0x53 to PORTA.

Q2) Write an instruction sequence to read the value in register r20. voltage levels on PORTB pins and place the value in register r20

Please include full working code, Including any setup code. I have what i think should work, but i keep getting errors

for 8.1 I have,

LDI r16, 0xFF

OUT DDRA, r16

LDI r16, 0x53

OUT PORTA, r16

I get the errors 'Undefined symbol:DDRA' and Undefined symbol: PORTA'

For 8.2 I have

LDI r16, 0x00

OUT DDRB, r16

IN r20, PINB

With similar errors, I dont know how to 'define' the ports and DDRB/DDRA

The code needs to actually work in the Atmel assembly studio

Explanation / Answer

First, the question should have mentioned the particular controller in question.

Atmega8515 has been considered in the answer, however, same process applies to all controllers.

There are two methods to fix this problem.

1) Simply include the header file as

before the first line of instruction.

The header file contains all the register names and their address in the actual controller. This is known as a register definition.

Look for the header file name for your controller.

Writing to a port of a controller is same as writing to a particular address in the memory of the controller. Here, that address is the address of the corresponding register.

2) Here, we do not need to use any header file as we would be defining the register name and its address ourselves such as the following example.

.EQU PORTB, 0x18

before any other instruction using PORTB.

Now, we have dfined the PORTB register name and it's address(0x18).

Now we may write the remaining code using PORTB.

Similarly, consult your controller datasheet and define all registers that you use and their addresses before loading data into them.