Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

atmega128 avr micro controllers assembly

Status
Not open for further replies.

Sana Srikar

Newbie level 5
Joined
Jul 19, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
73
can we load a value directly into internal sram of atmega128 does avr architecture support that ?
2. what is wrong with the instruction sts ocro,r23 ?


i was reading the book mazzidi and i got stuck in these two quesitons. started avr a day back and i was trying to solve the problems ......

1. for the first one i thought this is it because there is no enough space in opcode for it like we cannot use ldi to r0-r15...am i correct and
for the second one i thought was sts requires 16 bit address but ocro only gives 8 bit address(within 64)
 

According to the AVR Instruction Set Manual:

The STS command "store direct to data space" moves the contents of a register to the given address. A hex value is put into the register first using the LDI command. The opcode for the STS instruction is 32 bits long. 16 bits of it are used for the data space address.

The OUT command, "Stores data from register Rr in the Register File to I/O Space (Ports, Timers, Configuration Registers, etc". It would be used to put a value from a register into the OCR0 register, not the STS command.
 
Last edited:

sir do you say that ocro only works with OUT command........
i read that we can write the names of the registers or ports to call them no need to use address every time in such a way why is sts command still not working?
 

An example of the OUT command would be:
Code:
OUT OCR0, r23

The OUT command is needed because the OCR0 register is a Timer register in I/O space. It can be refered to by it's name, OCR0. OUT is used to write to I/O registers.

An example of the STS command would be:
Code:
STS $0F00, r2

Where $0F00 is an address within the 4k of SRAM that the contents of r2 is written to. $0F00 is not a register address but a SRAM address. STS is used to write to SRAM locations.

The AVR Instruction Set Manual has good explanations and examples for each command and is a good reference to understand each command's purpose and function.
 

sir i think STS command will work for every location in data space and as it is a big instruction of fourbytes this OUT is used and what i am asking is doesnot OCR0 gets replaced by its address why doesnot it ........................................
 

Hi,

See datasheet page 363: ORC0 has two different addresses $31 ($51). it depends what instruction you use.
Usually you use IN and OUT with $31
but you may use ST with $51

datasheet page 25 says:
When using the I/O specific commands IN and OUT, the
I/O addresses $00 - $3F must be used. When addressing I/O registers as data space using LD
and ST instructions, $20 must be added to these addresses.


Klaus
 

then whats wrong in the command STS ORC0 r17 ?
 

Hi,

then whats wrong in the command STS ORC0 r17 ?
you address "DDRD"!

again: datasheet says: ...$20 must be added to these addresses...

This is what you have to do, but you didn´t.

maybe something like STS OCR0 + $20, R17
(it depends on your compiler if this is allowed or if this is the correct syntax)

Klaus
 

In and out instructions just use one cycle to be done and just need one word in flash memory,but sts need 2 cycle to be done and need two word in flash memory, it is reasonable to use in and out for i/o
 

Hi,

IN and OUT is preferred.

Klaus
 

ATMEGA128 RET insturction

sir i was looking at the RET instruction and was wondering why it was taking four clock cycles.
why is it taking four cycles

2. what will be the default values of the DDR register when the device is turned on?

3.can we pop out the value directly into the program counter ?


thank you for answering and helping me out .
srikar sana
 

Re: ATMEGA128 RET insturction

Hello,
1-probably two cycle need to fetch return address from stack(in sram) and two cycle to write it into program counter
2-the default values of all program data(including 32 register,i/o register & sram) is zero.well,ddr is i/o register with default value zero.
3-you can use all jump instructions to pop out the value directly to program counter
For example jmp 0x0250 (the next instruction will start from 0x0250 address in flash memory)
actually we use lable for easy programming, jmp loop
 

Hi,

I recommend to make the complete port setup at power up, then the initial value of DDRD register is not important.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top