| Author |
Message |
|
|
Posted: Apr 26, 2012 - 02:33 AM |
|

Joined: Apr 18, 2012
Posts: 4
|
|
Hi all, I have a problem with reading the input of a switch in an if/else condition.
Below is the coding I have done:
Quote:
while(1)
{
keys=~PINC;
if(CHECKBIT(keys,PC0))
{
CLEARBIT(PORTD,PD1);
CLEARBIT(PORTD,PD2);
SETBIT(PORTD,PD0);
SETBIT(PORTD,PD4);
SETBIT(PORTD,PD3);
Lup();
Rup();
RLdown();
}
else
{
break;
}
I've check the switch board itself and determine it is fully working. The situation is,
The programming doesn't respond to the closing/opening of my switch. I want the program to execute the "if" function if PC0 is set to High. And if PC0 is low, it will "break" and loop continuously. However, this program does not work.
Things to take note of:
I've declared PORTC as input pins.
Will be glad if anybody can guide me on this. |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 02:55 AM |
|


Joined: Oct 15, 2005
Posts: 530
Location: Russia, Far East Siberia, Irkutsk
|
|
Hello!
1. Check have you disabled JTAG? I don't remember exactly but it can prevents some I/O lines on PORTC to be normally worked.
2.You shouldn't using "break" operator! If you're not going to do anything if your condition is false, just not write anything, because "BREAK" make the AVR (as any other processor) out of loop. So your uC runs something else but not the loop.
3. Have you connected pull-up/down resistor?
Sorry if I've wrote not clear. I have bad night. I'm sleepy) And I have mental fog... |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 03:04 AM |
|

Joined: Apr 18, 2012
Posts: 4
|
|
May I know what is JTAG and how do I disable it? I've removed the "break;" function and change it into something else and it still doesn't works.
I have connected the Pull up and pull down resistors too.
Thanks for your help! |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 05:02 AM |
|


Joined: Oct 15, 2005
Posts: 530
Location: Russia, Far East Siberia, Irkutsk
|
|
What about JTAG, see related pages in datasheet.
Quote:
I have connected the Pull up and pull down resistors too
You mean both of them you have connected? If so, it's wrong. You need only resistor: either pull-up or pull-down. Pull-up are often used. |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 11:53 AM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Show us how CHECKBIT() is defined.
Also can we assume DDRD is set correctly? |
_________________
|
| |
|
|
|
|
|