Need explanation help

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Need explanation help

Postby Jonxxxx » Thu Feb 07, 2013 4: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 4:16 am

Re: Need explanation help

Postby mwilson » Thu Feb 07, 2013 10: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: 39
Joined: Sun Oct 23, 2011 10:17 am
Location: Toronto, Canada


Return to Microcontrollers

Who is online

Users browsing this forum: No registered users and 2 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]