Monday, 13 June 2011

Reading Digital input from Atmega32 Ports


In this blog we'll see how to read digital data from PORTx of atmega32.

We have two programs - reading one input and reading two inputs.


The code for reading only one input is as follows

DDRB = 0x01 sets the first bit of PORTB as output port. I have done is because my led is connected at PORTB.

DDRD = 0x00 sets all the bits of PORTD as input port. But we are using only the first bit.

The if conditional statement uses the function bit_is_set(PIND,x) which returns 1 in case if the bit x of PORTD is given digital 1 else 0. Same goes for bit_is _clear(PIND,x).

  PORTD0 is given digital 1

                                                   PORTD0 is given digital 0



Then moving on to reading two digital inputs.This might not be difficult to understand.


No comments:

Post a Comment

Popular Posts