Go Down

Topic: command digitalWrite (); (Read 1 time) previous topic - next topic


Rd's address : d dddd = 1 1011 = 0x1B (27) //What is this register with address 1B?
Well, that's the absurd bit.  Register 0x1B is the PCIFR - Pin Change Interrupt Flag Register

And the REAL point is STILL that to set those two pins, this line:
Code: [Select]
PORTB = 0b00000011;
is wrong and it should be
Code: [Select]
PORTB |= 0b00000011;
Yeah, well you keep pointing that out, I keep pointing that out ...  :smiley-roll:


Sep 30, 2018, 01:56 am Last Edit: Sep 30, 2018, 01:57 am by GolamMostafa
Well, that's the absurd bit.  Register 0x1B is the PCIFR - Pin Change Interrupt Flag Register. [...].
We are expecting PORTB Register with address 0x05 to have been covered by ddddd bits of the LD Rd, Y+q instruction; but, it is not obvious in the code 85B9 which the IDE has produced against the PORTB = 0b000011; instruction.

LD Rd, Y+q instruction loads the Rd Register (address range: 0x00 - 0x1F) with an 8-bit value which resides in a RAM location whose address is being pointed by Y (+q) Register. This instruction is almost to support the validity of the code 85B9 except that we have not yet been able to trace the address of PORTB Register in this code.


Sep 30, 2018, 02:09 am Last Edit: Sep 30, 2018, 02:15 am by Southpark
O.P. if you want pretty much simultaneous activation of the LED pair..... then use port manipulation methods.... where you can set the states of a bunch of pins in one hit. Otherwise .... if you just want relatively nearly simultaneous turn-on of two leds..... then just do what some people suggested..... use digitalWrite two times in succession. To your eyes....... the functioning LEDs will always look like they light up at the same time.

Also ... you can even make your own sub function that invovles digitalWrites.... where your function accepts two different pin numbers ... plus another number to be as a codeword for the states.... eg. binary 0 or 00 would mean both of.... and 10 would mean first led on and second led off..... etc.


Sep 30, 2018, 10:44 am Last Edit: Sep 30, 2018, 10:50 am by GolamMostafa
The machine code 85B9 generated by IDE for the instruction PORTB = 0b000011; could be validated by the following assembly instructions under Atmel Studio 7.

Code: [Select]
                                 #define PORTB r27
000000 e013                      ldi r17, 0b000011 ; data for PB0 and PB1
000001 9310 0129                 sts $0129, r17    ; data saved in RAM location 0x0129
000003 e0d1                      ldi r29, 0x01
000004 e2c0                      ldi r28, 0x20     ; Y register contains 0x0120
000005 85b9                      ldd r27, Y+9      ; r27 holds 000011 which eneters into PORTB throgh #define directive?
000006 cff9                      rjmp start

Now, the PORTB register could be seen in the LDD r27, Y+9 instruction provided that the r27 register has been equated to PORTB register using #define directive?


This really has you worried, hasn't it?

The trouble seems to be that PORTB is in fact, register 0x25, not 27.

And why the compiler would do all of that is difficult to comprehend.   :smiley-eek:


The following two lines would be just enough to activate PB0 and PB1 simultaneously; instead, an indirect addressing is being used using pointer register Y?
Code: [Select]
000007 e0b3                      ldi r27, 0b000011
000008 2fbb                      mov PORTB, r27

Go Up