Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programing in Atmega using AVR Studio 4

Status
Not open for further replies.
i just made as you had told but nothing happened except that the led lightning is lower.
 

You mean that you have connected the resistor and the led still doesn't turn off?
Can you try a different pin of the mcu, you may have damaged the pin.
You can also check with a voltmeter the state of the pin.

Alex
 

i completely changed the pins but the same thing happened!
i made it like this:
#include <avr/io.h>

int main(){
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
DDRC=0XFF;
DDRD=0x00;
for(;;)
{


if (!CHECKBIT(PIND,7)) // check if bit1 of portC is 1, or use !CHECKBIT(PINC,1) to check if it is 0
{
SETBIT(PORTC,2); // I assume that you want to set one bit only and not all bits of portA
}
else
{
CLEARBIT(PORTC,2);
}}
return 0;
}
 

You also have to enable the pullup resistor of the input pin (since you don't have any external pullup) so that when the button grounds the input it can be detected.

Code C - [expand]
1
2
3
DDRC=0XFF;
DDRD=0x00;
PORTD=0x80;  // enable pullup resistor for bit 7 input of port D (the button pin)



and the defines don't need to be inside the main, they are usually placed in the first lines of the code so that they can be used before the main too when there is a function

Alex
 
Last edited:
finally it worked ......thank you for all your support during the last period
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top