Thanks, but post visiting 100s of forum, came here to ask as they didn't worked out. I've also taken help of ChatGPT and Bard, seems they helped a bit but not expected result.Suggest you look at any of the hundreds of examples on the web.
What I want is:Are the pins configured as outputs, digital inputs, or analog inputs?
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#define LED 0
#define SHORTPIN1 1
#define SHORTPIN0 0
int main() {
DDRD &= ~(1 << SHORTPIN0 ) & ~(1 << SHORTPIN1);
DDRC |= (1 << Buzzer);
while (1) {
if ((PIND & (1 << SHORTPIN0)) && (PIND & (1 << SHORTPIN1)))
{
PORTB |= (1 << LED);
}
else
{
PORTB &= ~(1 << LED);
}
}
}
[B]This code doesn't give the expected result[/B]
You don't need both PORTD0 and PORTD1 pins. You can do it with just one pin configured as input.What I want is:
I'm working on ATMEGA16 IC. I want LED (Connected at PORTC0) to be turned ON only when PORTD0 and PORTD1 pin of IC are shorted(or joint) using for ex: soldiering iron, metal piece. As soon as I remove that metal piece and unshort the IC pins, the LED should turn off.
Obviously LED will be configured as output, but having confusing about those IC pins (PORTD0 and D1) whether to be configured as IP or OP
[/B]
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#define LED 0
#define SHORTPIN1 1
#define SHORTPIN0 0
int main() {
DDRD &= ~(1 << SHORTPIN0) & ~(1 << SHORTPIN1);
PORTD |= ((1 << SHORTPIN0) | (1 << SHORTPIN1));
DDRC |= (1 << LED);
while (1) {
if (((PIND & (1 << SHORTPIN1)) && (PIND & (1 << SHORTPIN1)))==0)
{
PORTC |= (1 << LED);
}
else
{
PORTC &= ~(1 << LED);
}
}
}
Except you don’t need a pin to check to see if another pin is at ground or V+.You make one pin an input and make the other pin an output. Then:
- Set the output pin low and if the input is low then proceed to step 2, otherwise they are not shorted.
- Set the output pin high and if the input is high then you can conclude they are shorted, otherwise they are not shorted.
Well you do if the act of shorting two pins together is what you want to detect. That is a different problem than whether a pin is high or low. It is also important that you not check the pin directly without either setting the output low or verifying that it is in that condition. I suppose you could have the input connected to a pullup resistor (internal or external). Then set or verify the output is low and check to see if the input is low.Except you don’t need a pin to check to see if another pin is at ground or V+.
The ATMega16C has internal pullups which can be enabled.If you must use two pins, then I would still use a 1-10kΩ pull-up or pull-down resistor.
Yes, I thought of that but was too lazy to look it up. External pullup resistor will always work if the MCU does not have internal pullup.The ATMega16C has internal pullups which can be enabled.
When you work with a certain family of parts you just get used to things they offer being there.Yes, I thought of that but was too lazy to look it up. External pullup resistor will always work if the MCU does not have internal pullup.
Sure, he probably wants to short them with a solder bridge. Other than that, how is it different than shorting a single pin to ground?Well you do if the act of shorting two pins together is what you want to detect
Or maybe a screwdriver tip. If the nearest ground is some distance away, he might have to go find a test probe or a jumper wire. It is sometimes hard to get into the mind of a TS. I spent half a century in the business and never found the motivation to do something like this. But, hey - I'm a boomer.Sure, he probably wants to short them with a solder bridge. Other than that, how is it different than shorting a single pin to ground?