ATmega 328P programming reg

Discussion in 'Programmer's Corner' started by selvamurugan_t, Sep 16, 2016.

  1. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0
    I have some doubts about configuration of ATmega328P interface with Push button in Atmel studio 6.I am going to configure the reg and port .please conform to me ,it's correct or not.


    step1: DDRB |= 1 << PINB0; //This is for making pin B0 as output direction
    // PINBO=0b 0000 0000
    mask1=0b 0000 0000

    1<<PINBO= 0000 0001
    DDRB= 0000 0001
    DDRB|=1<<PINB0=0000 0001

    (Its correct or not)

    PORTB ^= 1 << PINB0;//this is make 5v output in PINB0

    PORTB=0b 0000 00001
    PINB0=0b 0000 0000
    Mask=0b0000 0001
    1<<PINB0=0b0000 0001

    Step 2: PORTB^=1<<PINB0=0b 0000 00001


    DDRB |= 1 << PINB2;//make Pin B1 as output direction

    DDRB=0b 0000 0100

    PINB2=0b0000 0000
    mask =0b0000 0001
    1<<PINB2=0b0000 0100

    PORTB^=1<<PINB0=0b0000 0100

    (Its correct or not)

    Step3: DDRB &= ~(1 << PINB1);//make pin B1 as input for push button interface

    DDRB=0x0000 0010
    pinB1=0x0000 0000
    Mask1=0x0000 0001

    1<<PINB1=0x0000 0010
    ~(1<<PINB1)=0x 1111 1101

    DDRB &= ~(1 << PINB1)=0x 0000 0000
    (Its correct or not)

    step 4: PORTB |= 1 << PINB1;(for 5v to PIN B1)
    PINB1=0x 0000 0000
    mask1=0x 0000 0001
    1<<PINb1=0x0000 0010
    PORTB=0x0000 0010

    PORTB |= 1 << PINB1 =0x 0000 0010;
    (Its correct or not)


    My question pinb0,b2 is output ,b1 is input

    So,DDRB=0x 0000 0101;

    every time we should do AND and OR operation with above steps or,first one is correct.
     
  2. jayanthd

    Member

    Jul 4, 2015
    274
    29
    Which Compiler are you using ?

    Code (C):
    1.  
    2. PORTB |= (1 << PINB0);
    3.  
    can be written as

    Code (C):
    1.  
    2. PORTB |= 0x01;
    3.  
     
  3. selvamurugan_t

    Thread Starter New Member

    Aug 8, 2016
    17
    0
    sorry for the delay.I am using Atmel studio 6.0
     
Loading...