DDRA reseting for some reason

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm somewhat of a newbie when it comes to microcontrollers. Well sort of. I'm hoping to graduate in February, and am having a hard time with my Senior Project. My professor suggested coming here for help, so here I am. Anyway, I'm using the MEGA16L and am wanting it to scroll the various input ports and see if a button was pushed. I've simulated it, and it seems to be working fine, but when I program the chip, it doesn't do what it's supposed to do. I am also using the JTAG ICE mk-II and emulating it. So when I do that and single step through the code, the PINA is being set to various inputs that I'm not wanting them to. So I've reset the DDRA in some of the areas that it was happening. Any help would be greatly appreciated.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are yu doing this?
DDRA = 0xFF;
DDRA = 0x00;

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ccoffman wrote:
PINA is being set to various inputs that I'm not wanting them to. So I've reset the DDRA in some of the areas that it was happening.

I notice that you compare the entire PINA register to a constant 8-bit value in a few places.

For instance:

       if(PINA == 0x04)
		iInputVariable = 'b';

But in your port setup, PORTA gets set to 0x00 which disables the pullups on input pins.

My guess is that your 8-bit comparisons fail because the unused pins on port A are floating. Try changing "PORTA = 0x00" to "PORTA = 0xFF"

/* John Butera */

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sutton, Whenever I'm single stepping through the code using the JTAG ICE, there are certain areas that are changing the PINA inputs even though they don't have anything to do with PORTA. So whenever I do the

DDRA = 0xFF;
DDRA = 0x00;
it resets the PINA configuration. I'm not sure why PINA is changing even though there's hasn't been any change as far as the actual input goes. I'll try turning on the pullup resistors like pepsi suggested. I originally was trying to compare just one specific pin with
if(PINA.2 == 1)

but since that wasn't really working, I thought I would try comparing the entire port, so that's why I did that. Thanks for helping. I won't be able to try this until Friday. My lab partner has the circuit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just thought I'd let you know that it worked out by turning on the pull up resistors. Thanks for the help