Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Ghanina
PostPosted: Apr 26, 2012 - 02:33 AM
Newbie


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.
 
 View user's profile Send private message  
Reply with quote Back to top
haker_fox
PostPosted: Apr 26, 2012 - 02:55 AM
Resident


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...
 
 View user's profile Send private message  
Reply with quote Back to top
Ghanina
PostPosted: Apr 26, 2012 - 03:04 AM
Newbie


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!
 
 View user's profile Send private message  
Reply with quote Back to top
haker_fox
PostPosted: Apr 26, 2012 - 05:02 AM
Resident


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.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Apr 26, 2012 - 11:53 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62941
Location: (using avr-gcc in) Finchingfield, Essex, England

Show us how CHECKBIT() is defined.

Also can we assume DDRD is set correctly?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits