Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple Button input problems

Status
Not open for further replies.

cosmonavt

Member
I was doing a project and I noticed the program going unexpectedly wrong. I was doubtful about the button inputs so I made a simple program to check this capability of the MCU.

I am using Atmega 16A. I wrote this simple prog:

Code:
#include <avr/io.h>

int main(void)
{
	DDRA = 0x00;
	DDRB = 0x11;
    while(1)
    {
        if(bit_is_clear(PINA, 0)){
			PORTB = 0x11;
		}
		else
			PORTB = 0x00;
    }
}

Ignore 0x11, it still means that Pin B0 should be set high (even though it was a typo).

Now the MCU is being supplied a voltage of 5 volt DC. When the Pin A0 is grounded, the voltage on pin B0 is 3.21V and when its disconnected from ground, Pin B0 is at a voltage of 1.63 V

What's going wrong?

I am making a binary clock and without the buttons, the clock was working fine. Now I had to add the time set buttons and problems started to appear....

Any clues where I am going wrong?
 
Have you applied external Pull Up Resistors at the Switch Ports?

When not, do that, or activate the internal Pullups by writing a locic 1 to the according PORT Bits
PORTA=0b00000011;
DDRA=0b00000000;
activates the internal Pullups at Port A Bit 0 and 1.
 
Thanks!

You mean that first specifying the PORTA register logic 1 and then DDRA register logic 0 will activate the internal pullups?
 
You mean that first specifying the PORTA register logic 1 and then DDRA register logic 0 will activate the internal pullups?
The order You'll do that, DDRx first or PORTx first, doesn't matter.
Not all Atmel controllers support internal pull ups on all pins, but most do it.

Take a look into the according datasheet.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top