C program to toggle all the bits of PortC in ATmega 16
Write an ATmega16 C program to toggle all the bits of Port C continuously.
Key Points :
- DDRC - DDR(Data Direction Register)
It is 8-bit register which sets the pins either input or
output. Each bit of the register corresponds to a
pin.
0 - Sets the corresponding pin INPUT
1 - Sets the corresponding pin OUTPUT
- PORT Register -
PORT is also an 8 bit register. The bits on the PORT
register correspond to the pins of the associated port in
the same manner as in the case of the DDR register.
PORT is used to set the output value.
CODE :
#include<avr/io.h>
int main(void)
{
DDRC = 0*FF; //This will set PORT C as output
PORTC = 0*AA; //This will set the value 10101010 at PORTC
for(;;) //infinite for loop
{
PORTC =~PORTC;//This will toggle the value 10101010 to 01010101
}
return 0;
}
Ref: Prof.Gaurav Verma
Comments
Post a Comment