Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Codevision Compiler Errorz(AVR/io.h)

Status
Not open for further replies.

decapitary

Banned
Member level 3
Joined
Jul 16, 2014
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
0
Code:
#include <C:\cvavr2\inc\io.h>
#include <stdlib.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#define BAUDRATE 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)
 
uint16_t adc_value;            //Variable used to store the value read from the ADC
char buffer[5];                //Output of the itoa function
uint8_t i=0;                //Variable for the for() loop
 
void adc_init(void);            //Function to initialize/configure the ADC
uint16_t read_adc(uint8_t channel);    //Function to read an arbitrary analogic channel/pin
void USART_init(void);            //Function to initialize and configure the USART/serial
void USART_send( unsigned char data);    //Function that sends a char over the serial port
void USART_putstring(char* StringPtr);    //Function that sends a string over the serial port
 
int main(void){
adc_init();        //Setup the ADC
USART_init();        //Setup the USART
 
for(;;){        //Our infinite loop
 for(i=0; i<6; i++){
 USART_putstring("Reading channel ");
 USART_send('0' + i);            //This is a nifty trick when we only want to send a number between 0 and 9
 USART_putstring(" : ");            //Just to keep things pretty
 adc_value = read_adc(i);        //Read one ADC channel
 itoa(adc_value, buffer, 10);        //Convert the read value to an ascii string
 USART_putstring(buffer);        //Send the converted value to the terminal
 USART_putstring("  ");            //Some more formatting
 _delay_ms(500);                //You can tweak this value to have slower or faster readings or for max speed remove this line
 }
 USART_send('\r');
 USART_send('\n');                //This two lines are to tell to the terminal to change line
}
 
return 0;
}
 
void adc_init(void){
 ADCSRA |= ((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0));    //16Mhz/128 = 125Khz the ADC reference clock
 ADMUX |= (1<<REFS0);                //Voltage reference from Avcc (5v)
 ADCSRA |= (1<<ADEN);                //Turn on ADC
 ADCSRA |= (1<<ADSC);                //Do an initial conversion because this one is the slowest and to ensure that everything is up and running
}
 
uint16_t read_adc(uint8_t channel){
 ADMUX &= 0xF0;                    //Clear the older channel that was read
 ADMUX |= channel;                //Defines the new ADC channel to be read
 ADCSRA |= (1<<ADSC);                //Starts a new conversion
 while(ADCSRA & (1<<ADSC));            //Wait until the conversion is done
 return ADCW;                    //Returns the ADC value of the chosen channel
}
 
void USART_init(void){
 
 UBRR0H = (uint8_t)(BAUD_PRESCALLER>>8);
 UBRR0L = (uint8_t)(BAUD_PRESCALLER);
 UCSR0B = (1<<RXEN0)|(1<<TXEN0);
 UCSR0C = (3<<UCSZ00);
}
 
void USART_send( unsigned char data){
 
 while(!(UCSR0A & (1<<UDRE0)));
 UDR0 = data;
 
}
 
void USART_putstring(char* StringPtr){
 
while(*StringPtr != 0x00){
 USART_send(*StringPtr);
 StringPtr++;}
 
}
}


Codevision errors when i press BUILD :

cant open #include file:avr\io.h
must declare first in block
undefuned symbol 'uint8_t' or 'itoa' or 'i' or ....



can anyone help me?
 

I have AVRstudio 4 installed, never upgraded to v6. Have you tried that?

- - - Updated - - -

What mcu is the code for and which codevision version do you have?

- - - Updated - - -

AVRstudio 4.18 sp2 can be found http://www.atmel.com/tools/studioarchive.aspx
and winavr http://winavr.sourceforge.net/

winavr as standalone will be able to compile the code if you can setup the make file
 
AVR studio 4 still error for avr/io.h and #pragma used+ ( error:unexpected +)
 

I assume you have installed winavr.

The code seems to be modified, a standard avrgcc code looks like

Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/cvavr_compat.h>


int main(void)
{
    while(1)
    {
     
    }
}

while the codevision looks like

Code:
#include <mega328p.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

while (1)
      {
      // Place your code here

      };
}

Try changing the first line to
Code:
#include <avr/io.h>
 

I assume you have installed winavr.

The code seems to be modified, a standard avrgcc code looks like

Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/cvavr_compat.h>


int main(void)
{
    while(1)
    {
     
    }
}

while the codevision looks like

Code:
#include <mega328p.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

while (1)
      {
      // Place your code here

      };
}

Try changing the first line to
Code:
#include <avr/io.h>


some errorz For STDLIB.h for unknown TYPEDEF in its code
 

I have made a couple of changes (the first line I mentioned plus removed a curly bracket) and the following code compiles fine for me in AVRstudio 4.18+winavr using mega168 (or m88 or m328 etc)

Code:
#include <avr/io.h>
#include <stdlib.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#define BAUDRATE 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)

uint16_t adc_value;            //Variable used to store the value read from the ADC
char buffer[5];                //Output of the itoa function
uint8_t i=0;                //Variable for the for() loop

void adc_init(void);            //Function to initialize/configure the ADC
uint16_t read_adc(uint8_t channel);    //Function to read an arbitrary analogic channel/pin
void USART_init(void);            //Function to initialize and configure the USART/serial
void USART_send( unsigned char data);    //Function that sends a char over the serial port
void USART_putstring(char* StringPtr);    //Function that sends a string over the serial port

int main(void) {
    adc_init();        //Setup the ADC
    USART_init();        //Setup the USART

    for(;;) {       //Our infinite loop
        for(i=0; i<6; i++) {
            USART_putstring("Reading channel ");
            USART_send('0' + i);            //This is a nifty trick when we only want to send a number between 0 and 9
            USART_putstring(" : ");            //Just to keep things pretty
            adc_value = read_adc(i);        //Read one ADC channel
            itoa(adc_value, buffer, 10);        //Convert the read value to an ascii string
            USART_putstring(buffer);        //Send the converted value to the terminal
            USART_putstring("  ");            //Some more formatting
            _delay_ms(500);                //You can tweak this value to have slower or faster readings or for max speed remove this line
        }
        USART_send('\r');
        USART_send('\n');                //This two lines are to tell to the terminal to change line
    }

    return 0;
}

void adc_init(void) {
    ADCSRA |= ((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0));    //16Mhz/128 = 125Khz the ADC reference clock
    ADMUX |= (1<<REFS0);                //Voltage reference from Avcc (5v)
    ADCSRA |= (1<<ADEN);                //Turn on ADC
    ADCSRA |= (1<<ADSC);                //Do an initial conversion because this one is the slowest and to ensure that everything is up and running
}

uint16_t read_adc(uint8_t channel) {
    ADMUX &= 0xF0;                    //Clear the older channel that was read
    ADMUX |= channel;                //Defines the new ADC channel to be read
    ADCSRA |= (1<<ADSC);                //Starts a new conversion
    while(ADCSRA & (1<<ADSC));            //Wait until the conversion is done
    return ADCW;                    //Returns the ADC value of the chosen channel
}

void USART_init(void) {

    UBRR0H = (uint8_t)(BAUD_PRESCALLER>>8);
    UBRR0L = (uint8_t)(BAUD_PRESCALLER);
    UCSR0B = (1<<RXEN0)|(1<<TXEN0);
    UCSR0C = (3<<UCSZ00);
}

void USART_send( unsigned char data) {

    while(!(UCSR0A & (1<<UDRE0)));
    UDR0 = data;

}

void USART_putstring(char* StringPtr) {

    while(*StringPtr != 0x00) {
        USART_send(*StringPtr);
        StringPtr++;
    }

}
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top