Understaning Atmega 8 I/O Pin bit control

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
BrownGray
Posts: 6
Joined: 18 May 2015 12:10

Understaning Atmega 8 I/O Pin bit control

#1 Post by BrownGray » 18 May 2015 12:28

Code: Select all

void main(){
DDRB.b0=0; // input BUTTON
Portb.b0=1; // set Pull-up
DDRB.b1 = 1; // output LED
while(1){
if(portb.b0==0) portb.b1 = 1; // if button has pressed turn on led
}}
Hi, i wanna control only one bit how can i do ?
I tried up side code but it is not working.
Can somebody tell me somethings about DDRX, PORTX, PINX ?

Thanks Gray.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Understaning Atmega 8 I/O Pin bit control

#2 Post by Aleksandar.Mitrovic » 19 May 2015 13:12

Hi,

I suggest you first to take a look at our examples which you can find in compilers example folder.
There also you can find example code how to turn on LED's:
...\mikroC PRO for AVR\Examples\Development systems\EasyAVR7\Button

For more information I suggest you to refer to the page 52 of this datasheet:
http://www.atmel.com/images/atmel-2486- ... asheet.pdf

Best regards,
Aleksandar

BrownGray
Posts: 6
Joined: 18 May 2015 12:10

Re: Understaning Atmega 8 I/O Pin bit control

#3 Post by BrownGray » 19 May 2015 21:52

Aleksandar.Mitrovic wrote:Hi,

I suggest you first to take a look at our examples which you can find in compilers example folder.
There also you can find example code how to turn on LED's:
...\mikroC PRO for AVR\Examples\Development systems\EasyAVR7\Button

For more information I suggest you to refer to the page 52 of this datasheet:
http://www.atmel.com/images/atmel-2486- ... asheet.pdf

Best regards,
Aleksandar
I tried Page 55 example C code

Image

Nikitos
Posts: 40
Joined: 06 May 2015 15:07

Re: Understaning Atmega 8 I/O Pin bit control

#4 Post by Nikitos » 20 May 2015 08:42

Try to use not PB1, PB2 etc. Try for example 1<<1, 1<<2 (instead PB1 use only number of the port)

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Understaning Atmega 8 I/O Pin bit control

#5 Post by Aleksandar.Mitrovic » 21 May 2015 14:20

Hi,

I'm afraid you didn't understand my answer.
Example given in this datasheet is not for our compiler.

If you want to see examples written for our compiler and for our Development boards I suggest you to take a look at Gif in attachment.
There you will find two examples which I opened ("Adc on Led's" and "Button") in mikroC PRO for AVR.

Please take a look how we write examples for microcontrollers. If you want to use some example on ATmega8 you will have to customize this code.

Best regards,
Aleksandar
Attachments
AVR_gif.gif
AVR_gif.gif (1.11 MiB) Viewed 3216 times

BrownGray
Posts: 6
Joined: 18 May 2015 12:10

Re: Understaning Atmega 8 I/O Pin bit control

#6 Post by BrownGray » 21 May 2015 18:32

Nikitos wrote:Try to use not PB1, PB2 etc. Try for example 1<<1, 1<<2 (instead PB1 use only number of the port)
Thanks you it is working :D

Post Reply

Return to “mikroC PRO for AVR General”