Flipping the port

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a parallel DAC that is hooked up to my mega32's PORTC. The problem I am having is that the MSB of the DAC is connected(via PCB) to PC0 the next MSB is connected to PC1 and so on. So I need to "flip the port" to output the correct value. Here is an example: after a conversion of the internal ADC the result is stored in a general purpose register. If the result is 0101 1001 I need to flip this number to 1001 1010 and output it on PORTC. any suggestions :?: would be helpful.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why cant you just connect the data lines correctly instead of backwards? and is this in C or assembly?

in assembly the easiest way to do it would probably be to do 8 ROR/ROL instructions.

ROR data
ROL flippedData
ROR data
ROL flippedData
ROR data
..
ROR data
ROL flippedData
ROR data
ROL flippedData

or use a simple loop

/* John Butera */

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This has been discussed on the Forum in gory detail in the past. The straightforward solution is shown by Pepsi. You can also follow-up on
http://2313.avrfreaks.net/phpBB2...
leading you to
http://2313.avrfreaks.net/phpBB2...

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

works great :D . I simulated it in AVR Studio 4 with a few test variables and it seems to do what I want. But how does it work? Does it shift the carry bit into the fliped data register?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes

Keep it simple it will not bite as hard

Last Edited: Mon. Oct 11, 2004 - 03:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Yes
_________________
Lets make this a negative comment free zone!

No.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John_A_Brown wrote:
Quote:
Yes
_________________
Lets make this a negative comment free zone!

No.

Maybe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The unrolled loop of eight sets of

       
        ROR     data 
        ROL     flippedData 

requires 16 words of instruction memory and 16 clock cycles to execute.

The minimum loop

        ldi	flippedData,low (0xFE)
loop:
        ror        data 
        rol        flippedData 
        brcs  loop

requires 4words of instruction memory and 32 clock cycles to execute.

An example of the usual size/time tradeoff.