Go Down

Topic: ATTINY Beacon (Read 1 time) previous topic - next topic

Coding Badly

#5
Dec 07, 2012, 12:30 am Last Edit: Dec 07, 2012, 12:33 am by Coding Badly Reason: 1
Code: [Select]
void broadcast(int N_cycles)
{
  unsigned int portvalue;
...
}


...the variable portvalue is assigned to a pair of registers.


Code: [Select]
      PORTB=portvalue;

...the least significant eight bits of portvalue are written to the I/O register for PORTB.


Code: [Select]
      ASM_INC(portvalue);

...which becomes...

Code: [Select]
asm volatile ("inc %0" : "=r" (portvalue) : "0" (portvalue))

...which becomes something like...

Code: [Select]
asm volatile ("inc r24")

...which just increments the value in the register used to store the least significant eight bits of portvalue.


The whole thing is a silly replacement for this (no assembly required)...

Code: [Select]
void broadcast( int N_cycles )
{
  uint8_t portvalue;

  for ( int i=0; i < N_cycles; i++ )
  {
    portvalue = 0;

    do
    {
      PORTB = portvalue;

      ++portvalue;
    }
    while( portvalue < 255 );
  }
}


armadillo

Coding Badly, that's very generous from your part.
I'm looking fwd to test it, will report back.

Go Up