Registers - DDR , PORT , PIN | EMBEDDED AND ROBOTICS

Registers - DDR , PORT , PIN

All the configurations in microcontroller is set through 8 bit (1 byte) locations in RAM (RAM is a bank of memory bytes) of the microcontroller called as Registers.

Input Output functions are set by Three Registers for each PORT.
• DDRX (DATA DIRECTION REGISTER)‐‐‐‐> Sets whether a pin is Input or Output of PORTX.
• PORTX ‐‐‐> Sets the Output Value of PORTX.
• PINX ‐‐‐‐‐> Reads the Value of PORTX.

DDR:  

First of all we need to set whether we want a pin to act as output or input. DDRX register sets this.

• To make Input set bit 0
• To make Output set bit 1

example  DDRB=11010001
(PORT‐B)
PB7   Output     1
PB6   Output     1
PB5   Input       0
PB4   Output     1
PB3   Input       0
PB2   Input       0
PB1   Input       0
PB0   Output     1


to make a whole 8 bit port as input or output:
DDRA=255   (FOR OUTPUT PORT: 255 IS USED AS IT IS 8PIN ie  8 BIT PORT{2^8})
DDRA=0       (FOR MAKING INPUT PORT)

To make an individual pin of port as input or output:
syntax    DDRA.X=0;  (INPUT)               // WHERE X IS THE PIN NO. starting from 0 to 7
             DDRA.X=1;  (OUTPUT)

example: DDRC.5=1;                //IT MAKES 5TH PIN OF PORT C AS OUTPUT PIN
-----------------------------------------------------------------------------------------------------------------------

PORT:

  This register sets the value to the corresponding PORT. Now a pin can be Output or Input. So let’s discuss both the cases.

• Output Pin
If a pin is set to be output, then by setting bit 1 we make output High that is +5V and by setting bit 0 we make output Low that is 0V.

SYNTAX:
PORTX ‐‐‐‐> to set value of PORTX with a byte.
PORTX.y ‐‐> to set value of yth pin of PORTX with a bit (works only with CVAVR)

example: PORTA.4=0;                       //GIVE 0 VOLT AT OUTPUT OF PIN 4 OF PORT A
PORTB=255;                             //GIVE 5 VOLT AT OUTPUT OF ALL PINS OF PORT B


• Input Pin

If a pin is set to be input, then by setting its corresponding bit in PORTX register will make it as follows, Set bit 0 ‐‐‐> Tri‐Stated Set bit 1 ‐‐‐> Pull Up
Tristated means the input will hang (no specific value) if no input voltage is specified on that pin.
Pull Up means input will go to +5V if no input voltage is given on that pin. It is basically connecting
PIN to +5V through a 10K Ohm resistance.
----------------------------------------------------------------------------------------------------------------------

PIN register:



This register is used to read the value of a PORT. If a pin is set as input then corresponding bit on PIN register is,
• 0 for Low Input that is V < 2.5V
• 1 for High Input that is V > 2.5V (Ideally, but actually 0.8 V ‐ 2.8 V is error zone!)

SYNTAX:

• PINX ‐‐‐‐> Read complete value of PORTX as a byte.
• PINX.y ‐‐> Read yth pin of PORTX as a bit (works only with CVAVR).

example  if(PINA.1==1)
              {
             ___                      
             ___
              }
    // READ IF VALUE AT PIN 1 OF PORT A IS 1 OR NOT, IF IT IS 1 THEN IT EXECUTES INSTRUCTIONS UNDER if STATEMENT

-------------------------------------------------------------------------------------------------------------------------------------------




1 comment:

  1. Thanks for sharing this complete information about ddr port pin tutorial.
    embedded course

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...

Popular Posts