### Different methods of programming

Now modify your code code as

Now upload the hex file to your microcontroller or to your proteus microcontroller Then the output will be same , Here you have did just hex form of the binary number 0b00000001 which is same as hex 01 so below is relationship between binary hex and decimal number system . you can use this table for future reference as well

DECIMAL |
BINARY |
HEX |

0 |
0000 | 0 |

1 |
0001 | 1 |

2 | 0010 | 2 |

3 | 0011 | 3 |

4 | 0100 | 4 |

5 | 0101 | 5 |

6 | 0110 | 6 |

7 | 0111 | 7 |

8 | 1000 | 8 |

9 | 1001 | 9 |

10 | 1010 | A |

11 | 1011 | B |

12 | 1100 | C |

13 | 1101 | D |

14 | 1110 | E |

15 | 1111 | F |

The main purpose of using hexadecimal system is you can represent more numbers using less digits for example you can represent fiveteen in decimal it is ‘15’ and in binary it is ‘1111’ and in hex it is ‘F’ similarly you can do it for others . Of course you can try it in your calculator .

In fact there are 8 pins in data direction register A . In the case of above example the value of DDRA0 is set as 1 and rest are zero . because we are going to make that pin as output pin . rest of the pin are ignored !

DDRA7 |
DDRA6 |
DDRA5 |
DDRA4 |
DDRA3 |
DDRA2 |
DDRA1 |
DDRA0 |

0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |

Ignored ? how can we ignor the pin that might be used as input or output but you simply ignored ? what does that mean ? !! yeah right you should not ignore the rest of pin you have to do simply XOR operation to the value so that the previous value of the pin does not alter So modify your code as follows

** **What we did

**DDRA****|=(1<PINA0);**

Assume that initially in PORTA there is

DDRA7 |
DDRA6 |
DDRA5 |
DDRA4 |
DDRA3 |
DDRA2 |
DDRA1 |
DDRA0 |

X | X | X | X | X | X | X | X |

So in PORTA we don’t know what there is so we assume initial value XXXXXXXX where X can be zero or one .

Now **OR** with 1 in DDRA0

DDRA7 |
DDRA6 |
DDRA5 |
DDRA4 |
DDRA3 |
DDRA2 |
DDRA1 |
DDRA0 |

X | X | X | X | X | X | X | 1 |

XXXXXXXX

XXXXXXX1

----**OR**---

XXXXXXX1

So the value in PORTA will not alter with previous value . I think it is good method of programming .Similarly if we did the **AND** operation with initial value

XXXXXXXX----initial value

XXXXXXX0----changing PINO

---**AND**---

XXXXXXX0

SO there is zero in particular pin without changing previous value

Similarly to toggle(to change 1 to zero and zero to one ) the Pin value we can do **XOR **operation with the initial value

XXXXXXXX------initial value

XXXXXXX1-----to toggle value

--**XOR---**

XXXXXXX0--- the value is toggled

If you are not understanding what I m trying to say lets modify your code as follows

So you have got the exact output,but you did programming on a particular pin without changing rest pins in this case it is PINA0;

In fact there is just ones and zeros in the case of microcontroller .All you have to do is binary operation and some mathematical calculation .So that the desired output will be obtained .