How to use a previous C programming at arduino?

Hello,

I did a C program in AVRStudio, and i have a arduino atmega 2650. I want to use this C program at arduino.. Can I? And another question, i didn't know how to use the ADC at C code, but it's easy at arduino compiler. Can I mix codes and do the adc's part at arduino compiler ???

Sorry about the poor english :/ :grin:

Thank's

Hard to say without seeing the code, but I'd guess that you can at least re-use some of it.

Mostly you just have to 'unwind' it from it's main function, as the arduino uses a 'hidden' main function. What you also have to determine is if your existing code uses any includes that aren't part of the arduino platform.

Can I mix codes and do the adc's part at arduino compiler ???

Yes you can.

Lefty

My code is somethig like that… i wont show the full thing because it will be a ver large post…

#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <util/delay.h>
int i=0;
int k=0;
int j=0;

void ataque() {
i++;
if (i>3) {
PORTG = 0x1;
_delay_us(10);
PORTG = 0x0;
TCCR1B = 0x8;
i=0;
}
}
void ataque1() {
k++;
if (k>3) {
PORTG = 0x2;
_delay_us(10);
PORTG = 0x0;
TCCR3B = 0x8;
k=0;
}
}
void ataque2() {
j++;
if (j>3) {
PORTG = 0x4;
_delay_us(10);
PORTG = 0x0;
TCCR4B = 0x8;
j=0;
}
}

void conversao() {
PORTC = 0x0;
_delay_us(2);
PORTC = 0x2;
_delay_us(10);
OCR1AH = PINB;
OCR1AL = PINA;
OCR3AH = OCR1AH;
OCR3AL = OCR1AL;
OCR4AH = OCR1AH;
OCR4AL = OCR1AL;
TCCR1B = 0x9; // inicia o timer da fase A
}

ISR(INT0_vect)
{
conversao();
}

ISR(INT1_vect)
{
TCCR3B = 0x9; // inicia o timer da fase B
}

when i put this code at arduino, it rejected the registers, but i thought about putting the avr libraries at arduino… can i do that ?
will it fix my problem?

You do have access to all the low level registers in Arduino sketches - we need to see compiler error messages to know what the problem is.

Those messages make me think you have the wrong board selected, in the Tools menu.

The first think I see that's wrong with the code is:

#define F_CPU 1000000UL

Arduino runs on 16MHz, and it has this defined on the Makefile, so it may be one of the problems you're having.

Next, like PaulS referred, it sounds like you've got the wrong board selected. Did it reject PORTC registers?

Hey guys, thanks for the help... it really was the board :sweat_smile: i compiled and it did any error.. i still didnt tested at the board yet but i think that's ok... about the CPU_L, whats the clock frequency for arduino atmega 2650?

Thanks!

about the CPU_L, whats the clock frequency for arduino atmega 2650?

Same as the Uno board, 16Mhz.