Electronics > Beginners

ASM to Arduino

<< < (3/5) > >>

metrologist:

--- Quote from: darrellg on January 17, 2019, 04:26:07 pm ---That's not how you do it. A ten second search on Google will show you the right way to use asm in the Arduino IDE:
https://ucexperiment.wordpress.com/2016/03/04/arduino-inline-assembly-tutorial-1/

--- End quote ---

Yes, knowing that something exists and finding it takes 10 seconds.


--- Quote ---Learning inline assembly language on the Arduino AVR 8-bit platform is a daunting task for many (at least it was for me). Besides the cryptic syntax and the high level of understanding the semi-official documentation assumes, there exists very little information about GCC inline assembler coding.
--- End quote ---

I tried working with the tutorial and here is where I ended up.


--- Code: ---#include <m32def.inc>

void setup(){
asm (
"init: \n"
"LDI R16,0xFF \n"
"OUT DDRA,R16 \n"
"CLR R15 \n"
"CLR R14 \n"
"CLR R13 \n"
"CLR R12 \n"
"CLR R11 \n"
"CLR R10 \n"
"CLR R9 \n"
"CLR R8 \n"

"loop: \n"
  "LDI R16,0x0A \n"
        "INC R15 \n"
"CP R15,R16 \n"
"BRNE nd1 \n"
"CLR R15 \n"
"nd1: BRNE nd1w \n"
"INC R14 \n"
"nd1w: CP R14,R16 \n"
"BRNE nd2 \n"
"CLR R14 \n"
"nd2: BRNE nd2w \n"
"INC R13 \n"
"nd2w: CP R13,R16 \n"
"BRNE nd3 \n"
"CLR R13 \n"
"nd3: BRNE nd3w \n"
"INC R12 \n"
"nd3w: CP R12,R16 \n"
"BRNE nd4 \n"
"CLR R12 \n"
"nd4: BRNE nd4w \n"
"INC R11 \n"
"nd4w: CP R11,R16 \n"
"BRNE nd5 \n"
"CLR R11 \n"
"nd5: BRNE nd5w \n"
"INC R10 \n"
"nd5w: CP R10,R16 \n"
"BRNE nd6 \n"
"CLR R10 \n"
"nd6: BRNE nd6w \n"
"INC R9 \n"
"nd6w: CP R9,R16 \n"
        "BRNE cready \n"
"CLR R9 \n"
"cready: CLT \n"
"BLD R8,0 \n"
"OUT PORTA,R8 \n"
        "LDI  R17,08 \n"
"WLP0:  DEC  R17 \n"
        "BRNE WLP0 \n"
"CLR R8 \n"
        "LDI R16,0x05 \n"
"SET \n"
"BLD R8,0 \n"
"CP R15,R16 \n"
"BRCS d2 \n"
"BLD R8,1 \n"
"d2: CP R14,R16 \n"
"BRCS d3 \n"
"BLD R8,2 \n"
"d3: CP R13,R16 \n"
"BRCS d4 \n"
"BLD R8,3 \n"
"d4: CP R12,R16 \n"
"BRCS d5 \n"
"BLD R8,4 \n"
"d5: CP R11,R16 \n"
"BRCS d6 \n"
"BLD R8,5 \n"
"d6: CP R10,R16 \n"
"BRCS d7 \n"
"BLD R8,6 \n"
"d7: CP R9,R16 \n"
"BRCS ok \n"
"BLD R8,7 \n"
"ok: OUT PORTA,R8 \n"
        "LDI     R17,03 \n"
"WLP1:   DEC      \n"
        "BRNE    WLP1 \n"
"NOP \n"
"RJMP  \n"
);
}

void loop(){}



==========================

Error compiling:

C:\Users\\AppData\Local\Temp/ccYDtlBP.s: Assembler messages:
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:31: Error: constant value required
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:78: Error: constant value required
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:79: Error: garbage at end of line
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:107: Error: constant value required
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:109: Error: constant value required
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:112: Error: missing operand
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:124: Error: symbol `loop' is already defined
C:\Users\\AppData\Local\Temp/ccYDtlBP.s:133: Error: operation combines symbols in different segments

--- End code ---

My favorite error is the "garbage at the end of line"  :-DD

My objective, however, is not to learn asm. And as a matter of fact, I have resigned myself from any sort of programming expectations. I just don't seem to be able to do it.

fsr:

--- Quote from: metrologist on January 17, 2019, 03:51:04 pm ---Arduino IDE is not happy with the ASM code.

fsr, I simply want to load the PPSDiv code to arduino. I think it works "out of the box" so I do not expect to have to modify it, I just want to get the code onto a 328p chip. I think there is a way to burn the hex file which is included. I recall burning the bootloader onto bare chips so I may review how I did that, so many years ago... But to take a step back, I don't really need this code, but any code that will do the same thing. I could also just order some pic chips and try the picdiv code, but I don't have those chips and I have plenty of Arduinos.


This is the ASM code I tried to compile in Arduino IDE.

[...]


--- End quote ---

I see, so you want to get the .HEX into an atmega328p. I suppose that you don't have an AVR programmer, but you can see how to use one Arduino as a programmer for an stand-alone AVR in this link: https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all

Or you could buy a cheap-ass usbasp programmer to do the same. I use one of them, and the commands for avrdude that i use most often are the following:

This line sets the fuses (normally you only need to do this once). Check the attached libreoffice document with details about the fuses settings (those are for 5v operation with full-swing crystal oscillator, and some other miscellaneous options, YMMV):
avrdude -p m328p -c usbasp -U lfuse:w:0xf7:m -U hfuse:w:0xd9:m -U efuse:w:0xfc:m

And this line is to upload the hex file:
avrdude -p m328p -c usbasp -U flash:w:YOURHEXFILE.hex

Note that the AVR won't function as an Arduino anymore after doing that. If you want to make it work again, you possibly will need to reprogram the fuses, and upload another HEX file with the Arduino bootloader to the AVR.

metrologist:
Oh yeah, that's right, I used an Arduino to program the bootloader. I also bought one of those AVRASP devices but could never get it to work in windows.

I also had AVR studio set up and used it a couple times, but it seemed to have so much overhead that I stopped using it.

I'll breadboard up a chip and if I get it working I'll make this a dedicated divider module.

fsr:
Did you use avrdude with the usbasp? I used it quite a lot of times under windows, and no problems. Should work.

metrologist:
I think it was that Windows did not see the ASP device. That might be another topic.

Because I was reading about it and that I found a vendor 10 miles away, I ordered 10 of PIC12F675. This seems a bit better for my application, and I have a pickit2 that needs to be used at least twice.

Thanks  :-+

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod