PORTF in ATMega1280

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

I'm using ATMega1280, and trying to do simple testing. The switch is connected to PF4 pin, and LED is connected to PF1. Switch and LED are active low.

 

So, when we press the switch, LED should turn on. it's world's simple programming but I don't know why my code is not working. The LED just stays on all the time. Please help me.

 

Here is the part of my code:

 

 

// Port F initialization
DDRF=(0<<DDF7) | (0<<DDF6) | (0<<DDF5) | (0<<DDF4) | (0<<DDF3) | (0<<DDF2) | (1<<DDF1) | (0<<DDF0);
PORTF=(0<<PORTF7) | (0<<PORTF6) | (0<<PORTF5) | (1<<PORTF4) | (0<<PORTF3) | (0<<PORTF2) | (1<<PORTF1) | (0<<PORTF0);


    while (1)
    {

        if (~(PINF) & (1<<PORTF4))
        {
            PORTF &= ~(1<<PORTF1);	//LED1 on	
        }
        else
        {
            PORTF |= (1<<PORTF1);	//LED1 off
        }

    }

 

 

This topic has a solution.

:)

Last Edited: Wed. Feb 12, 2020 - 10:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


gregg333 wrote:
Here is the part of my code:

When you have a sanity-check program, post the entire program.  Also build sequence and results [to ensure correct target selected].  Toolchain, version, build options.

 

Show the complete schematic.  Tell exactly what is connected to these pins in question.  Is the LED right-way-round?  How is the switch connected?

 

What is the voltage on PF4, RIGHT ON THE MICRO PIN, when the switch is pressed?  What is the voltage when not pressed?

 

I need to look up the alternate functions of that port on that model...is that JTAG?

 

][edit] Aha!

 

The complete schematic will tell more about AVcc, all the power and ground ins connected, and decoupling.

 

 

Is your AVR really running, and not held in reset for some reason?  How have you proven that?

 

 

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Wed. Feb 12, 2020 - 05:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PF4 is multiplexed with JTAG.TCK; IIRC, mega1280 are JTAG enabled during package assembly and/or test.

ATmega640/1280/1281/2560/2561 datasheet summary (page 2)

"Dare to be naïve." - Buckminster Fuller

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

Oops, You are correct. the JTAG was enabled and I was not aware of it. Wow! It's working perfectly fine now.

Thanks for your comment  theusch  and  gchapman

:)

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

gregg333 wrote:
Wow! It's working perfectly fine now.

Jolly Good! Now please mark the solution.

 

See Tip #5 in my signature (below; may not be visible on mobile)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...