0

looking for a little help. I'm familiar with PIC Microcontrollers but have never used Atmel. I'm required to use an ATMEGA128 for a project at work so I've been playing around in Atmel Studio 6 the last few days.

I'm having an issue however, I can't even get an LED to blink.

I'm using the STK500 and STK501 Dev boards and the JTAGICE_MKII USB debugger/programmer.

The ATMEGA128 chip is a TQFP package that's in the socket on the STK501 board.

I'm able to program/read the chip no problems, and my code builds without error (except for when I try to use the delay functions used in the delay.h library - but that's another issue).

For now I'm just concerned with getting the IO working. I have a jumper from 2 bits of PORTD connecting to 2 of the LEDs on the STK500 board.

All I'm doing in my code is setting the PORT direction with the DDRx ports and then setting all the PORTD pins to 0. The LEDs remain turned on.

When I'm in debugging mode and I have the watch window open, I can break the code and the watch windows shows me that the PORTD bits are indeed all 0's, but the LEDs remain on.

So far, I hate Atmel. :)

Any ideas? Thanks

Killerb81
  • 53
  • 6

3 Answers3

0

Have you tried setting them to logic 1? It is common for LED circuits to connect the LED to Vcc via a current-limiting resistor, which means the output port has to be 0 to turn on the LED.

If you set it to 1 and the LED goes off, then that'll tell you it's an "active low" signal and you can reverse your logic accordingly.

dtynan
  • 78
  • 8
0

Have you read the STK500's doc? It is likely, that the LEDs are driven active low.

ogni42
  • 1,232
  • 7
  • 11
0

There are two steps to follow. First you set the "direction" of the pins, because they can be used as input or output. To make the D register pins output pins:

DDRD = 0xFF;

This will set all pins on the D register as output pins. Do this first. Then code like:

PORTD != 0x01;

will set the D0 pin high. And code like

PORTD ^= 0x01; 

will toggle the pin.

See this tutorial for a little more info or visit in with this community. The Atmel community is vibrant and helpful.

TomServo
  • 7,248
  • 5
  • 30
  • 47