The contents of DDR decide whether a particular pin of the microcontroller acts as an INPUT pin, that is, it’ll be used to get an input from the outside world, or as an output, that is, it’ll be used to give an output to the outside world.
For DDR register,
1 --> Output
0 --> Input
If I set a particular bit of the DDR register as 1, it means that the pin number, corresponding to that bit number will work as an output pin. If a bit is made 0, the pin number corresponding to that particular bit will act as in input.
Please note that pin number and bit number count starts from 0. That means, PA0 is the 1st pin and PA7 is the 8th pin.
Let’s say we want the 3rd pin ( that means, PA2) of Port A to function as an output pin. This is what the DDRA register will look like
Thus, while writing the program in WinAVR, we can simply write the statement as
DDRA=0x80; // this statement will make PA2 an output pin
Similarly, PORTA is used for assigning a HIGH (1) or a LOW (0) signal to an output pin.
When we want to check whether an input pin is receiving a HIGH (1) or a LOW (0) we use PIN.
No comments:
Post a Comment