PORTC of ATMEGA324P acting funny

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

Trying to hook up 4 Seven Segment Displays to my ATMEGA324P.

PD0-PD3 passes power to the common anode of each digit one at a time. As each digit is powered, each segment has its current sunk into PC0-PC7 (also one at a time).

All of the displays have been tested.

I've checked continuity from the cathodes to their respective pins on PORTC.

Either PC2-PC5 are busted (they won't sink current for me), or there's a mistake in my code.

#include 
#include 

int main (void){
	DDRC = 0xFF; // set as output, sink current
	DDRD = 0x0F; // first 4 pins output, source current
	PORTC = 0x00;
	PORTD = 0x00;
	
	while(1){
		for (int j = 0; j < 8; j++){
			// set the segment pin low (sink)
			PORTC = ~(1<<j);
			for (int i = 0; i < 4; i++){
				PORTD |= (1<<i);
				_delay_ms(20);
				PORTD = 0x00;
			}
		}
	}
}

This is the weirdest glitch I've ever encountered. Any input is greatly appreciated!

I know that the port groups on this micro can only source/sink 100mA simultaneously, but because I'm only lighting one segment at a time, I don't think this would be an issue.

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

You have the JTAG interface enabled?
You can change a fuse setting or write one to the JTD bit in MCUCSR at runtime.

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

I didn't enable JTAG, but I'll check the fuses

For convenience

Datasheet: http://www.atmel.com/dyn/resourc...

Pinout:

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

HAH! it works :)

Didn't know JTAG was enabled by default.

Thanks a million, Alan.