help translate code from ATTiny2313 to PIC16F57 ..

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

Hi. I have some problem . I want translate existing program (in ASM) for ATTiny2313 and translate to PIC16F57 . exist any way , is there some one help with this??

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

Basically, forget it.

The devices are so different in design that there's no sensible way of automating the translation at the machine code level.

Ignoring the aspects of the different internal peripheral devices and interrupt format, the small PICs are severely restricted in RAM and the way it's accessed.

Your only real hope is to rewrite the original algorithm and start afresh.

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

yes. but instruction set are only few detail different like instruction for attiny . I try compare.

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

no sorry , avr have more instruction , and pic have only 33 instruction set, avr have more then 123 .hmmm is it possible but. step by step convert...

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

What can the PIC16F57 do that the ATtiny2313 can't do?

If you are determined to port your program, you just re-write the algorithms from scratch.
Or pay someone to do it for you.

How much are you prepared to pay?

David.

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

heh. I have two project , one (bad design) but perfect firmware. and second is nice design but scrap firmware. I write firmware for small keyboard alarm, relay control. is good and work well . but other project used PIC (nice plastic case) but engineer what write firmware must more drink . I want use my firmware in existing PCB board.

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

As has already been stated (in sightly different terms) the two chip architectures are completely different. It is not going to be possible to port firmware from one to the other *without* recompiling the source tree which will need to be rewritten for the new (other) architecture.
In short, forget it. You are wasting your time even attempting to do this.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

gregsmithcts wrote:
In short, forget it. You are wasting your time even attempting to do this.
I doubt it would take much more than several hours to port AVRASM Tiny2313 to MPASM PIC16F57 provided the porter :) is fluent in both assemblers/architectures.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

I think that this is the point.
Re-writing from scratch is a lot quicker than writing an automated translator.

I would also guess that dzairo's colleague would do the job for a suitable number of vodka bottles.

Everything has a price !

David.

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

"I doubt it would take much more than several hours to port AVRASM Tiny2313 to MPASM PIC16F57 provided the porter is fluent in both assemblers/architectures."

Indeed, however the OP is not. Hence his asking for help. That's why I said forget it.
I wonder how long it would take to become fluent in both assemblers/architectures?
:)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Long ago it took me a couple of hours to move from ASM51 to AVRASM, and then I've rewritten dozens of my ASM51 projects to AVRASM roughly with a speed of typing/copypasting/editing. Since all these 8-bit architectures (x51/AVR/PIC16) are just primitive, it's not a big deal at all to rewrite in any combination.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

Quote:

avr have more then 123

Two things:

1) 123 is a marketing lie

2) what does the number of opcodes really matter anyway? Pretty much all CPUs can AND/OR/EOR/ADD/SUB/LSL/LSR/ROL/ROR/CP/cod-branch/etc.

Dare I even mention this but if the code were written in C then porting it could be far far easier. OTOH I'll bet a lot of it is hardware specific like DDRB=n, PORTC=m, etc. and I guess whether that's C o9r Asm it still needs "porting".

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

Quote:

1) 123 is a marketing lie

2) what does the number of opcodes really matter anyway?


Aaahh--NOW we 'freaks have something to get our teeth into.

First, Cliff, define an "opcode" for the purpose of this discussion. As the AVR instruction word(s) is kind of 'microcoded"--not real orthogonal in the bit usage--we can't just say e.g. "instructions have 6 bit opcode and 10 bit operand(s)" or the like.

Lessee, IIRC from previous discussions just the BSET/BCLR family ends up to be 16 "duplicates".

Now, if the AVR is a RISC and has 100+ "opcodes", then how many does a CISC have?

[edit] Oh, yeah--if an enterprising 'Freak can write an ARM simulator on an AVR running at an effective 60kHz, then surely one could be done for a small PIC.

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

Don't think you'll have any luck translating. Best bet is to find out what your program does, and write one for the pic. This isn't a class assignment, is it? Seems like the useless kind of exercise a teacher would come up with.

The largest known prime number: 282589933-1

Without adult supervision.

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

Writing as one who is competent in both architectures I'll say again: they are totally different in both architecture and programming practice.

In particular:
- The AVR has sixteen target registers any of which can be an 'accumulator'; the PIC has one.
- The AVR can perform conditional jumps; the PIC can only skip one instruction conditionally.
- The AVR has individual vectors for each interrupt; the PIC has a single interrupt for all.
- The AVR has a contiguous RAM memory space; the RAM on the PIC is accessed either by setting one or two bits in the status register to select the required bank or by using an indirection register (and potentially another selector bit).
- AVR registers are accessible through specialised instructions or as direct memory addressing; PIC registers are available only through the paged memory system.
- AVR completes one instruction per clock cycle; the PIC requires four cycles.
- The AVR has a stack available to the program and potentially as large as the internal RAM; the PIC has eight levels, with no user stack.
- The PIC peripherals are generally not as useful as those of the AVR, in particular the timers (though the PIC can offer interrupts on more pins (I think) than the AVR).
In general, on the AVR you generate code which targets the 'accumulator' registers; on the PIC most operations target memory directly.

It is of course *possible* to emulate an AVR on a PIC, memory allowing - but it's going to run like a dog an frankly it's not the best idea.

Rewrite the AVR algorithm in C. Sort out the interrupt issues, if any. Run it through the PIC C compiler. If it fits, sorted. But an automated translation between machine codes? Nah.

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

hey barnacle if read your post than I'm really happy so use avr not PIC , I thinks so more easy will be draw new PCB like rewrite code for other platform. thanks all.

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

Quote:
on the AVR you generate code which targets the 'accumulator' registers; on the PIC most operations target memory directly.

This is probably the key philosophical difference. The AVR has "many" general purpose "registers" used for most math/etc, and "memory" that is (mostly) only accessible via load/store operations. The PIC has an accumulator ("W") that must be one operand of some operations, but has "many" "file registers" ("memory" and peripheral registers) that it can be the other operand, or be source/target for other operations.

That makes it difficult to translate assembly code "automatically"; the "architecture FAMILY" is different between the two. (Sort of like translating from C to Fortran vs translating from C to Pascal.) (Ignore the marketing literature that claims they're both "RISC.")

The 16F57 is also a member of the oldest and most primitive of microchip's sub-architectures. Paged flash and paged SFRs; things that might have been designed to annoy new assembly language programmers.
This particular PIC also has significantly less memory than the AVR (72bytes + W for the PIC, 128b + 32 registers for AVR.) OTOH, the Pic has room for about twice as many instructions (2k words of flash vs 2kbytes...)

Quote:
Rewrite the AVR algorithm in C.

That was my thought as to strategy as well. AVRASM-->C-->PICASM might be easier than AVRASM-->PICASM even if you have to do it manually.

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

Or use an intermediate macro language as a common language. Something like english. "move byte from register file to accumulator" can be expressed as a c statement in both processors.

Imagecraft compiler user

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

I believe the OP stated that it was an alarm driving a relay.

I'm not sure where the discussion ever got off on the tangent of an "automated" program for the conversion from avr to pic.

Not much info was given, but with the info that was provided, and the small capacity of the chips involved, it would seem to be a system on the lower complexity end of the scale.

I think, therefore, the conversion was more a question of how to set/reset an output (relay driver) bit, how does one debounce the push buttons, and how does one read the sensors?, (in pic-speak).

That said, it sounds like the OP is going to respin the board and stick with the AVR.

Good decision.

JC

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

Even if you are an experienced avr programmer some times it takes a long to set up correctly some registers.If you are not familiar with the architecture and instruction set of the mcu a couple of months or more however is needed.

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

dzairo, We agree. Much easier with AVR than PIC.;)

The largest known prime number: 282589933-1

Without adult supervision.

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

Hi all. I draw new PCB , no language translation...
thanks.
PS: I'm search partner to cooperate in some project funded in KickStart. I can't do it because I'm from Slovakia and can't receive funds from KickStart.

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

Quote:

Lessee, IIRC from previous discussions just the BSET/BCLR family ends up to be 16 "duplicates".

Now, if the AVR is a RISC and has 100+ "opcodes", then how many does a CISC have?


The "marketing lie" I'm talking about is simply the fact that almost every tiny and mega datasheet starts with a "Features" first page that generally includes a comment such as (mega16):
Datasheet wrote:
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single-clock Cycle Execution

(the number varies - sometimes 133, sometimes 135). Yet if one takes a list of the opcode set and weeds out the duplicates you arrive at these (75 in this case) lines:

0000 0000 0000 0000   nop				1
0000 0001 dddd rrrr   movw    v,v		1
0000 0010 dddd rrrr   muls    d,d		1
0000 0011 0ddd 0rrr   mulsu   a,a		1
0000 0011 0ddd 1rrr   fmul    a,a		1
0000 0011 1ddd 0rrr   fmuls   a,a		1
0000 0011 1ddd 1rrr   fmulsu  a,a		1
0000 01rd dddd rrrr   cpc     r,r		1
0000 10rd dddd rrrr   sbc     r,r		1
0000 11rd dddd rrrr   add     r,r		1
0001 00rd dddd rrrr   cpse    r,r		1
0001 01rd dddd rrrr   cp      r,r		1
0001 10rd dddd rrrr   sub     r,r		1
0001 11rd dddd rrrr   adc     r,r		1
0010 00rd dddd rrrr   and     r,r		1
0010 01rd dddd rrrr   eor     r,r		1
0010 10rd dddd rrrr   or      r,r		1
0010 11rd dddd rrrr   mov     r,r		1
0011 KKKK dddd KKKK   cpi     d,M		1
0100 KKKK dddd KKKK   sbci    d,M		1
0101 KKKK dddd KKKK   subi    d,M		1
0110 KKKK dddd KKKK   ori     d,M		1
0111 KKKK dddd KKKK   andi    d,M		1
100! 000d dddd ee-+   ld      r,e		1
100! 001r rrrr ee-+   st      e,r		1
10o0 oo0d dddd booo   ldd     r,b		1
10o0 oo1r rrrr booo   std     b,r		1
1001 000d dddd 0000   lds     r,i		2
1001 000d dddd 010+   lpm     r,z		1
1001 000d dddd 011+   elpm    r,z		1
1001 000r rrrr 1111   pop     r			1
1001 001d dddd 0000   sts     i,r		2
1001 001r rrrr 1111   push    r			1
1001 0100 0000 1001   ijmp				1
1001 0100 0001 1001   eijmp				1
1001 0100 0SSS 1000   bset    S			1
1001 0100 1SSS 1000   bclr    S			1
1001 0101 0000 1000   ret				1
1001 0101 0000 1001   icall				1
1001 0101 0001 1000   reti				1
1001 0101 0001 1001   eicall			1
1001 0101 1000 1000   sleep				1
1001 0101 1001 1000   break				1
1001 0101 1010 1000   wdr				1
1001 0101 1100 1000   lpm     ?			1
1001 0101 1101 1000   elpm    ?			1
1001 0101 1110 1000   spm				1
1001 010h hhhh 110h   jmp     h			2
1001 010h hhhh 111h   call    h			2
1001 010r rrrr 0000   com     r			1
1001 010r rrrr 0001   neg     r			1
1001 010r rrrr 0010   swap    r			1
1001 010r rrrr 0011   inc     r			1
1001 010r rrrr 0101   asr     r			1
1001 010r rrrr 0110   lsr     r			1
1001 010r rrrr 0111   ror     r			1
1001 010r rrrr 1010   dec     r			1
1001 0110 KKdd KKKK   adiw    w,K		1
1001 0111 KKdd KKKK   sbiw    w,K		1
1001 1000 pppp psss   cbi     p,s		1
1001 1001 pppp psss   sbic    p,s		1
1001 1010 pppp psss   sbi     p,s		1
1001 1011 pppp psss   sbis    p,s		1
1001 11rd dddd rrrr   mul     r,r		1
1011 0PPd dddd PPPP   in      r,P		1
1011 1PPr rrrr PPPP   out     P,r		1
1100 LLLL LLLL LLLL   rjmp    L			1
1101 LLLL LLLL LLLL   rcall   L			1
1110 KKKK dddd KKKK   ldi     d,M		1
1111 00ll llll lsss   brbs    s,l		1
1111 01ll llll lsss   brbc    s,l		1
1111 100d dddd 0sss   bld     r,s		1
1111 101d dddd 0sss   bst     r,s		1
1111 110r rrrr 0sss   sbrc    r,s		1
1111 111r rrrr 0sss   sbrs    r,s		1

My point is that listing "131 Powerful instructions" when there are only realyl 75 distinct operations looks a lot like marketing BS to me.

As is often said "it's quality not quantity that counts" ;-)

PS Oh and for the record these are the duplicates I removed from the list:

        =             lsl     r
        =             rol     r
        =             tst     r
        =             clr     r
        =             sbr     d,M
        =             cbr     d,n
        =             sec
        =             sez
        =             sen
        =             sev
        =             ses
        =             seh
        =             set
        =             sei
        =             clc
        =             clz
        =             cln
        =             clv
        =             cls
        =             clh
        =             clt
        =             cli
	    =			  ser     d (K=FF)
        =             brcs    l
        =             brlo    l
        =             breq    l
        =             brmi    l
        =             brvs    l
        =             brlt    l
        =             brhs    l
        =             brts    l
        =             brie    l
        =             brcc    l
        =             brsh    l
        =             brne    l
        =             brpl    l
        =             brvc    l
        =             brge    l
        =             brhc    l
        =             brtc    l
        =             brid    l

There are 41 of those. 75 + 41 = 116 which still doesn't get us to "131 Powerful Instructions" ?

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

this is for big discussion ..