[solved] #include <avr/pgmspace.h> [convert GCC to CV]

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

Hai all, What is the equivalent function for "#include " in codevision avr.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Fri. Oct 10, 2014 - 09:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

There is no equivalent.
Codevision handles flash and eeprom transparently.
So you don't need any specific #include

You do need to convert the GCC pgmspace.h macros. e.g.

#include              //uint8_t etc
#define PGM_P  			char flash *
#define PROGMEM			flash
#define PSTR(x)			x
#define pgm_read_byte(x)	(*((uint8_t flash *)(x)))
#define pgm_read_word(x)	(*((uint16_t flash *)(x)))
#define EEMEM			eeprom
#define eeprom_read_byte(ads)	(*((uint8_t eeprom *)(ads)))
#define eeprom_write_byte(ads,x) (*((uint8_t eeprom *)(ads))) = x
#define eeprom_write_word(ads,x) (*((uint16_t eeprom *)(ads))) = x

Please can you delete your duplicate post(s) before anyone replies to it. Otherwise people will get very upset.

David.

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

2 extra posts deleted.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

hai all,

Thanks david. now i will try with this. if i got any doubt then i will ask you.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

hai david.prentice ,

I hereby attach uart routines header file and source file. this is in avr studio 4(winavr). I want to adapt this one to Codevision avr. How to adapt it from avr studio to codevision.

// **************************************************************
// *** UART_ROUTINES HEADER FILE ********
// **************************************************************

#define TX_NEWLINE {transmitByte(0x0d); transmitByte(0x0a);}

void uart0_init(void);
unsigned char receiveByte(void);
void transmitByte(unsigned char);
void transmitString_F(char*);
void transmitString(char*);

//**************************************************************UART_ROUTINES SOURCE FILE
//******** FUNCTIONS FOR SERIAL COMMUNICATION USING UART *******
//**************************************************************
//Controller: ATmega128 (Crystal: 16Mhz)
//Compiler: winAVR (AVR-GCC)
//Author: CC Dharmani, Chennai (India)
// www.dharmanitech.com
//Date: April 2009
//********************************************************

#include
#include
#include "UART_routines.h"

//**************************************************
//Function initialize UART0
//desired baud rate: 19200
//actual: baud rate:19231 (0.2%)
//char size: 8 bit
//parity: Disabled
//**************************************************
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x33; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x98;
}
//**************************************************
//Function to receive a single byte
//*************************************************
unsigned char receiveByte( void )
{
unsigned char data, status;

while(!(UCSR0A & (1<<RXC0))); // Wait for incomming data

status = UCSR0A;
data = UDR0;

return(data);
}

//***************************************************
//Function to transmit a single byte
//***************************************************
void transmitByte( unsigned char data )
{
while ( !(UCSR0A & (1<<UDRE0)) )
; /* Wait for empty transmit buffer */
UDR0 = data; /* Start transmition */
}

//***************************************************
//Function to transmit a string in Flash
//***************************************************
void transmitString_F(char* string)
{
while (pgm_read_byte(&(*string)))
transmitByte(pgm_read_byte(&(*string++)));
}

//***************************************************
//Function to transmit a string in RAM
//***************************************************
void transmitString(char* string)
{
while (*string)
transmitByte(*string++);
}

Thanks & Regards,
Sasi

Attachment(s): 

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

All of that code is completely standard C and should work the same in either compiler apart from this one routine:

#include  
...
//***************************************************
//Function to transmit a string in Flash
//***************************************************
void transmitString_F(char* string)
{
while (pgm_read_byte(&(*string)))
transmitByte(pgm_read_byte(&(*string++)));
} 

CodeVision uses "flash" for data that is in flash but does not require a dereference function to access the data so this should be as simple as:

//***************************************************
//Function to transmit a string in Flash
//***************************************************
void transmitString_F(flash char* string)
{
 while (*string)
  transmitByte(*string++);
} 

The rest of the code is unchanged. (apart from the #include's).

BTW when you have a foo.h and a foo.c then any headers foo.c relies on should be in foo.h not foo.c and foo.c then just includes foo.h

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

Ah-ha. I have just replied to a PM.

Cliff has given an excellent reply and shows why it is always wise to ask your questions on the public forum.

PM should really be used for private or personal messages.

David.

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

hai all,

Thanks david. Sorry for PM messege.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Semi-OT:

Quote:

Ah-ha. I have just replied to a PM.

Whenever I get a PM like that I always (with the very odd exception, one in a thousand) point them back to the forums. I give them the reasons:
1) No special treatment
2) Special treatment makes the PMer look spoiled
3) Forums are for future readers to prosper from

I always end those replies with "I will not answer any further PMs on this subject. See you in the forums!".

It is my opinion that all us residents should do this.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

hai david,

This is my code. i am getting some junk as a result. how to clear junk and get a result.

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 7/31/2014
Author : Dev6
Company : sass
Comments:

Chip type : ATmega128
Program type : Application
AVR Core Clock frequency: 14.745600 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 1024
*****************************************************/

#include
//#include
#include
#include "UART_routines.c"

// Declare your global variables here

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

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;

// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;

// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;

// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
//UCSR0A=0x00;
//UCSR0B=0x18;
//UCSR0C=0x06;
//UBRR0H=0x00;
//UBRR0L=0x5F;

//puts("\nsriram");
//delay_ms(500);

uart0_init();
delay_ms(1500);
transmitByte('s');
delay_ms(500);
transmitString("\nnamasivaya");

while (1)
{
// Place your code here

}
}

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

hai david,
i got a result. I am using atmega128 with 14.7456mhz frequency.
if i changed uart0_init() like below in UART_routines.c

UCSR0A=0x00;
UCSR0B=0x18;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x5F;

NOW i am getting a result. Thanks alot david. Today i learned something clearly. thanks to all.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Quote:

if i changed uart0_init() like below

But isn't that exactly what was in main() (commented):

// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
//UCSR0A=0x00;
//UCSR0B=0x18;
//UCSR0C=0x06;
//UBRR0H=0x00;
//UBRR0L=0x5F; 

??

if the code was lifted from main() and put into uart0_init() instead then how did it actually change in the process? form above it looks like it became:

//**************************************************
//Function initialize UART0
//desired baud rate: 19200
//actual: baud rate:19231 (0.2%)
//char size: 8 bit
//parity: Disabled
//**************************************************
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x33; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x98;
} 

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

Well, is your mega128 running at 14.74MHz rather than 16MHz ?
Obviously the UART needs to use the correct UBRR value.

Regarding the large-ish program, all you actually need is:

#include             // it knows mega128 from the Project
#include          // so it knows printf() etc
#include 

// Declare your global variables here

void main(void)
{
    // USART0 initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART0 Receiver: On
    // USART0 Transmitter: On
    // USART0 Mode: Asynchronous
    // USART0 Baud Rate: 9600
    UCSR0A=0x00;
    UCSR0B=0x18;
    UCSR0C=0x06;
    UBRR0H=0x00;
    UBRR0L=0x5F;

    printf("\nsriram");

    while (1)
    {
        // Place your code here
        delay_ms(500);
        putsf("namasivaya");
    }
}

Seriously, this looks pretty simple. I would actually use printf() because it is more flexible.
Note that CV treats "quoted string constant" as being in flash memory. So you use putsf() instead of puts().
GCC insists on putting anonymous strings into SRAM even though it is wasteful. (you need to use PSTR() to make GCC put "anonymous string" into flash)

David.

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

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

hai clawson,

in UART_routines.c instead of first one i used second one. because first one is for 19.231mhz frequency.

void uart0_init(void) 
{ 
UCSR0B = 0x00; //disable while setting baud rate 
UCSR0A = 0x00; 
UCSR0C = 0x06; 
UBRR0L = 0x33; //set baud rate lo 
UBRR0H = 0x00; //set baud rate hi 
UCSR0B = 0x98; 
} 
void uart0_init(void)
{
UCSR0A=0x00;
 UCSR0B=0x18;
 UCSR0C=0x06;
 UBRR0H=0x00;
 UBRR0L=0x5F;
}

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Hai david,

#include             // it knows mega128 from the Project 
#include          // so it knows printf() etc 
#include  

// Declare your global variables here 

void main(void) 
{ 
    // USART0 initialization 
    // Communication Parameters: 8 Data, 1 Stop, No Parity 
    // USART0 Receiver: On 
    // USART0 Transmitter: On 
    // USART0 Mode: Asynchronous 
    // USART0 Baud Rate: 9600 
    UCSR0A=0x00; 
    UCSR0B=0x18; 
    UCSR0C=0x06; 
    UBRR0H=0x00; 
    UBRR0L=0x5F; 

    printf("\nsriram"); 

    while (1) 
    { 
        // Place your code here 
        delay_ms(500); 
        putsf("namasivaya"); 
    } 
} 

yes it looks very simple. But my task is to convert and making own library and using it without initialising uart0. So only i made it like a library.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

hai js,
Thanks. Really you gave a great comment to post a code. Thanks alot js.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Quote:
yes it looks very simple. But my task is to convert and making own library and using it without initialising uart0. So only i made it like a library.

[rant]
This sounds like a school project from an ill-informed and arrogant teacher.

In my day, my school teachers tried to educate rather than make things difficult for their pupils.
So they would show you the easiest and best methods for solving Maths problems.
They would show you how to read a textbook or write an essay.

Nowadays, with the internet you have access to the best teaching materials in the world. Some teachers resent this, and want to show that they are clever after learning the hard way.

In my personal opinion, since the round wheel has already been invented, humankind should make full use of it.
[/rant]

If you have any coding problem in any language, you should first look at the standard features / libraries of the language. e.g. the C Standard Library

In answer to your 'problem', you must initialise the USART. It is not possible for an AVR to 'know' the value of an external crystal or clock. You have to tell the Compiler whether it is 8MHz, 14MHz, 16MHz, ...

In fact, for most common USART baud rates and clock speeds, you only need two lines:

    UCSR0B = (1<<TXEN0)|(1<<RXEN0);               //0x18;
    UBRR0L = _MCU_CLOCK_FREQUENCY_/16/9600 - 1; //0x5F;

The 'other' statements are the power-up default values.

All other 'USART' comms can use the library functions.

David.

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

hai david,

yes. I got it. now i am using i2c_routines and EEPROM_routines.
while compiling i am getting error in .asm

Error

Quote:

Error: C:\Documents and Settings\Dev5\Desktop\avr_studio_codevision\dharmani_31_07\List\dharmani_31_07.asm(2410): Duplicate label: '_i2c_start'

Error: C:\Documents and Settings\Dev5\Desktop\avr_studio_codevision\dharmani_31_07\List\dharmani_31_07.asm(2427): Duplicate label: '_i2c_stop'

i2c_routines

#include 
#include "i2c_routines.h"
#include "UART_routines.h"

//*************************************************
//Function to start i2c communication
//*************************************************
unsigned char i2c_start(void)
{

	TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); 	//Send START condition

    while (!(TWCR & (1<<TWINT)));   		//Wait for TWINT flag set. This indicates that the
		  								//START condition has been transmitted
    if ((TWSR & 0xF8) == START)			//Check value of TWI Status Register
 	   return(0);
	else
	   return(1);
}

//*************************************************
//Function for repeat start condition
//*************************************************
unsigned char i2c_repeatStart(void)
{

    TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); 		//Send START condition
    while (!(TWCR & (1<<TWINT)));   		//Wait for TWINT flag set. This indicates that the
		  								//START condition has been transmitted
    if ((TWSR & 0xF8) == REPEAT_START)			//Check value of TWI Status Register
 	   return(0);
	else
	   return(1);
}
//**************************************************
//Function to transmit address of the slave
//*************************************************
unsigned char i2c_sendAddress(unsigned char address)
{
   unsigned char STATUS;

   if((address & 0x01) == 0)
     STATUS = MT_SLA_ACK;
   else
     STATUS = MR_SLA_ACK;

   TWDR = address;
   TWCR = (1<<TWINT)|(1<<TWEN);	   //Load SLA_W into TWDR Register. Clear TWINT bit
   		  			 				   //in TWCR to start transmission of address
   while (!(TWCR & (1<<TWINT)));	   //Wait for TWINT flag set. This indicates that the
   		 		   					   //SLA+W has been transmitted, and
									   //ACK/NACK has been received.
   if ((TWSR & 0xF8) == STATUS)	   //Check value of TWI Status Register
   	  return(0);
   else
      return(1);
}

//**************************************************
//Function to transmit a data byte
//*************************************************
unsigned char i2c_sendData(unsigned char data)
{
   TWDR = data;
   TWCR = (1<<TWINT) |(1<<TWEN);	   //Load SLA_W into TWDR Register. Clear TWINT bit
   		  			 				   //in TWCR to start transmission of data
   while (!(TWCR & (1<<TWINT)));	   //Wait for TWINT flag set. This indicates that the
   		 		   					   //data has been transmitted, and
									   //ACK/NACK has been received.
   if ((TWSR & 0xF8) != MT_DATA_ACK)   //Check value of TWI Status Register
   	  return(1);
   else
      return(0);
}

//*****************************************************
//Function to receive a data byte and send ACKnowledge
//*****************************************************
unsigned char i2c_receiveData_ACK(void)
{
  unsigned char data;

  TWCR = (1<<TWEA)|(1<<TWINT)|(1<<TWEN);

  while (!(TWCR & (1<<TWINT)));	   	   //Wait for TWINT flag set. This indicates that the
   		 		   					   //data has been received
  if ((TWSR & 0xF8) != MR_DATA_ACK)    //Check value of TWI Status Register
   	  return(ERROR_CODE);

  data = TWDR;
  return(data);
}

//******************************************************************
//Function to receive the last data byte (no acknowledge from master
//******************************************************************
unsigned char i2c_receiveData_NACK(void)
{
  unsigned char data;

  TWCR = (1<<TWINT)|(1<<TWEN);

  while (!(TWCR & (1<<TWINT)));	   	   //Wait for TWINT flag set. This indicates that the
   		 		   					   //data has been received
  if ((TWSR & 0xF8) != MR_DATA_NACK)    //Check value of TWI Status Register
   	  return(ERROR_CODE);

  data = TWDR;
  return(data);
}
//**************************************************
//Function to end the i2c communication
//*************************************************
void i2c_stop(void)
{
  TWCR =  (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);	  //Transmit STOP condition
}

EEPROM_routines

#include "EEPROM_routines.h"
#include "UART_routines.h"
#include "i2c_routines.h"
#include 


//******************************************************************
//Function to read given number of bytes from EEPROM
//******************************************************************
unsigned char EEPROM_read(unsigned char highAddress, unsigned char lowAddress, unsigned char totalChar)
{
   unsigned char errorStatus, i, data;

   errorStatus = i2c_start();
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("i2c start failed.."));
   	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_sendAddress(EEPROM_W);

   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM sendAddress1 failed.."));
	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_sendData(highAddress);
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM write-1 failed.."));
	 i2c_stop();
	 return(1);
   }


   errorStatus = i2c_sendData(lowAddress);
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM write-2 failed.."));
	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_repeatStart();
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("i2c repeat-start failed.."));
	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_sendAddress(EEPROM_R);
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM sendAddress2 failed.."));
	 i2c_stop();
	 return(1);
   }

   for(i=0;i> 8) & 0x00ff);
  lowAddress  = (unsigned char)( pageAddress & 0x00ff);

  errorStatus = EEPROM_read(highAddress, lowAddress, 64);

  return(errorStatus);
 }

//******************************************************************
//Function to write one page of EEPROM
//******************************************************************
unsigned char EEPROM_writePage( unsigned int pageNumber )
{
  unsigned char highAddress, lowAddress, errorStatus;
  unsigned int pageAddress;

  pageAddress = pageNumber * 64;

  highAddress = (unsigned char)((pageAddress >> 8) & 0x00ff);
  lowAddress  = (unsigned char)( pageAddress & 0x00ff);

  errorStatus = EEPROM_write(highAddress, lowAddress);

  return(errorStatus);
}

//******************************************************************
//Erasing EEPROM (filling it with databyte 0xff)
//******************************************************************
unsigned char EEPROM_erase(void)
{

  unsigned char errorStatus;
  unsigned int i;

  TX_NEWLINE;
  TX_NEWLINE;
  transmitString_F(PSTR("Wait..."));
  TX_NEWLINE;

   errorStatus = i2c_start();
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("i2c start failed.."));
   	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_sendAddress(EEPROM_W);

   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM sendAddress1 failed.."));
	 i2c_stop();
	 return(1);
   }

   errorStatus = i2c_sendData(0x00);
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM write-1 failed.."));
	 i2c_stop();
	 return(1);
   }


   errorStatus = i2c_sendData(0x00);
   if(errorStatus == 1)
   {
     transmitString_F(PSTR("EEPROM write-2 failed.."));
	 i2c_stop();
	 return(1);
   }

    for(i=0;i<0x8000;i++)
   {
	  errorStatus = i2c_sendData(0xff);
   	  if(errorStatus == 1)
   	  {
       		transmitString_F(PSTR("EEPROM write data failed.."));
			i2c_stop();
	   		return(1);
   	  }
   }

   i2c_stop();

   return(0);

}

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

You do realise that all your 'work' could be done in a few lines with the Codevision libraries.

Bear in mind that if you #include then CV will link with its library. So if you are determined to use square wheels, you need to choose a local "squarewheel.h" header, and choose different names e.g. squarewheel_start()

Oh, and library is even more convenient than the library.

AS Cliff said earlier, the dharmani code is regular C. It should compile with any Compiler. Just make sure that if there is a dharmani "i2c.h" it is read from your local project directory and not the real system from the CV directory.

David.

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

hai David,

Error:Duplicate label: '_i2c_stop'
how to clear this error and what is it.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Quote:

Error:Duplicate label: '_i2c_stop'

Code in .h by any chance? Obviously multiply included .h should contain only declarations not definitions.

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

hai clawson,

i am getting this error in .asm file. but i am not including multiple .h file.

includes are:


#include
#include
#include "UART_routines.c"
#include "i2c_routines.c"
#include "EEPROM_routines.c"
Quote:

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

hai clawson,

i am getting this error in .asm file. but i am not including multiple .h file.

includes are:

#include 
#include 
#include "UART_routines.c"
#include "i2c_routines.c"
#include "EEPROM_routines.c"

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Fri. Aug 1, 2014 - 10:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Life would be simpler if you posted a link to the original dharmanitech.com project.

It is fairly trivial to port the code to CV.

IMHO, you should use the facilities provided by Codevision. e.g. library functions.
Likewise, the comms can use that is available with every C compiler in the civilised world.

Personally, I have rather a low opinion of the quality of the dharmani code. I found http://www.dharmanitech.com/2008/08/interfacing-rtc-serial-eeprom-using-i2c.html

I find it a mystery why you should want to build these examples with CV. After all, they should run straight out of the box with GCC.

And you could write the program for CV with just a few lines. After all, CV even has a specific library.

The reason that you see "Error:Duplicate label: '_i2c_stop'" is because you have included when you are using square wheels ("i2c_routines.c").

David.

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

yes david, but i am not included .

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

sasireka wrote:
hai clawson,

i am getting this error in .asm file. but i am not including multiple .h file.

includes are:

#include 
#include 
#include "UART_routines.c"
#include "i2c_routines.c"
#include "EEPROM_routines.c"

You don't include C files.
You should add a C file to the project.
This is what the Project Configuration is for.

Your "main.c" will include H files.
These will either be system headers like or
Or local headers like "i2c_routines.h"

But I still advise that you are choosing to use undocumented weird functions from dharmani rather than using the documented library functions provided by CV.

David.

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

hai David,

if i used like this #include "UART_routines.h", i got a error like below

Linker error: C:\Documents and Settings\Dev5\Desktop\avr_studio_codevision\dharmani_31_07\UART_routines.h(7): function 'uart0_init' declared, but never defined

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Quote:

if i used like this #include "UART_routines.h", i got a error like below

That's because you didn't add the .c files to the list of files in the project to be individually compiled then linked together.

When you are given a .c and a .h by someone else to be used in your own projects you add a "#include "header.h"" to your own C files where you access their data/functions AND you add the .c file to the list of files in the project so it will be built and the references you make to the functions can be resolved.

And as David says you never #include .c files!

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

clawson wrote:
Quote:

if i used like this #include "UART_routines.h", i got a error like below

hai clawson,

Okay. I will do like what u said.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

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

Hai all,
All your valuable points helped me alot. Its working fine. eeprom writing and reading fine. Thanks to David, Clawson, js and Thanks to all.

Thanks & Regards,
Sasi

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN