2 Jul 2012

PINS

PIN TERMINOLOGY:

             Same way as Ports . Remember the number of Ports you have is equal to number of pins because there are fixed number of pins for a microcontroller right.

Do you remember i told you you should access whole port even you want to access only one pin. In the same way you should access whole PINX for even you need only one pin to access. X = A, B, C ,D.

Lets take an example so that it makes you clear all the things.

You use PINB when you are checking if something is coming to microcontroller . eg: consider switch when you press a switch it sends a signal of 5v right so you need a application if you press a switch you should do some task lets assume toggle led. so you should be checking that pin right whether the pin is getting signal or not so at that time you use PINB (for checking incoming signal to microcontroller).

ACCESS 2:
PROGRAM:
             #include <avr/io.h>
              int main()
              {
                    DDRB = 0x00;     //configuring as inputs
                    DDRC = 0xff;      //configuring as outputs
                    while(1)
                     {
                           if(PINB & (1 << PB0)) //switch is connected to pinb 0
                           {
                                 PORTC = (1 << PC0);
                            }
                            PORTC = 0x00;
                      }
                }
as we connected switch to the Pinb0 so we are checking that pin continuoesly. 

And you may be thinking which i made PORTC = 0x00; in the program because in order to see whether it is blinking or not you should make it 0. try commenting that .you will get the output once.
ACCESS 3:
                    Replace (1<< PB0) with _BV(PB0).
Now i think you are quite familier with the access of ports.

some of the input devices to the microcontroller :
1. switch
2. Matrix keypad
3. Potency variation
4. ADC
5. Usart receiver etc..........
            _____________________________________________________
PINB  | PB7  | PB6  |  PB5  |  PB4  |  PB3|  PB2  | PB1  | PB0  |
           --------------------------------------------------------------------------------------
 This looks like this in the microcontroller. so , you got it right if you want to check that microcontroller is getting some input we use PINx .

 Though it may be looking as a simple concept for some of you but many don't understand at the beginning so this is for just them who are beginners.

ok, then lets meet in next session........................................

No comments:

Post a Comment