2 Jul 2012

Ports & Pins

PORTS & PINS:
         1. PORTS
         2. PINS

When ever you here these terms you should get into mind is these are  access to the external devices which act as interface between them and microcontroller.

                                                   [ Photo]

In Atmel they are termed as Ports and pins and should be accessed as whole port . i.e whole port is used for accessing even one pin. At the beginning it will be some what odd but while you will be programming na you will feel better. But i promise you if you learn this you can do any of the family like atmel, Pic , anything . Like if you learn this you will play with other microcontrollers .

Accessing Port in the Pic is very easy like if you are accessing PORTB assume ok. Now in order to access one pin just like PB0 = 1; like this is enough but when you come to Atmel if you want to access one pin i.e 0th pin of PORTB then you should do something like PORTB |= (1 << PB0). ya dont worry i will explain in detail ok.

In order to do port access first you should know what is data direction registers.
It means nothing but telling the microcontroller that port or pin is used for output or input. It is mandatory to tell the microcontroller what function the perticular pin of the port should do whether it should act as output or input.

In Atmel controllers we tell the microcontroller
                                     DDRB = 0xFF;   -->  1 indicates the PORT is designed to function as output if the same
                                     DDRB = 0x00;   -->  0 indicates that the PORT is designed to function as input of microcontroller.

Finally Atmega8 has 4 PORTS :
                     1. PORTA
                     2. PORTB
                     3. PORTC
                     4. PORTD
In the comming section i will explain you how to access the ports and pins in different styles.............................:-)

In order to get fast access in microcontroller you should be well prepared with bitwise operators. we use mostly these things in the microcontroller. 

No comments:

Post a Comment