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
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 !
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
Assume that initially in PORTA there is
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
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
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
XXXXXXX1-----to toggle value
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 .