Need explanation help
Moderators: adafruit_support_bill, adafruit

Need explanation help

by Jonxxxx on Thu Feb 07, 2013 5:17 am

at atmega88, could someone possibly help me with the explanation of this piece:


.equ PORTD=0x0B

LDI r16,0x30
OUT DDRC,r16

LDI r16, 0b11111001
OUT portd, r16


what does each line refer to or what does it mean :)
Thanks
Jonxxxx
 
Posts: 1
Joined: Thu Feb 07, 2013 5:16 am

Re: Need explanation help

by mwilson on Thu Feb 07, 2013 11:49 am

The 'equ' line gives the name 'PORTD' to the numeric value 0x0B (in hex. That would be 11 in decimal.) Using the name 'PORTD' later in the program will get you that numeric value in the executable code.

Each 'ldi' line takes a value given in the instruction and loads it into a register. Each 'out' line sends a value from a register to an I/O port.

So the first ldi/out pair sends the value 0x30 to the port whose port-number is named 'DDRC'. That's probably the data-direction register for PORTC.

The second ldi/out pair sends the value 0b11111001 (the same as 0xF9) to the port whose port-number is named 'PORTD', which was set up in the equ line.

It's hard to say what these do; they don't seem to work together at all. Setting the DDRC register that way would set two pins on PORTC as output and the others as inputs. Driving PORTD pins high and low is on a completely separate port.

Best is to get the data book for atmega88 http://www.atmel.com/Images/doc8271.pdf to explain all the ports and peripherals, and http://en.wikipedia.org/wiki/Atmel_AVR_instruction_set (or the link it has to the Atmel doc) for a description of the instructions.
mwilson
 
Posts: 46
Joined: Sun Oct 23, 2011 11:17 am
Location: Maynooth, Canada