[SOLVED] Code worked OK in Arduino IDE but gives errors in Atmel Studio 7

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

Hello,

 

It's my starting with Atmel Studio 7, I just copied my LCD1602_I2C whole code from Arduino to my project in AS7, but I got different errors. I solved some but I couldn't do the rest because I can't find the error source.

 

This is my AS7 files, LCD1602_I2C.h, LCD1602_I2C.c and main.c

 

Regards,

Attachment(s): 

This topic has a solution.

Last Edited: Fri. May 19, 2017 - 09:54 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You're biggest problem is that you are defining and initializing variables in a header file and then including your header file in multiple c files.  Also, your definitions are outside of your header guard.  That's not causing any build errors, but it's a bad habit to get in to.

 

Your header file should look more like this:

#ifndef LCD1602_I2C_H_
#define LCD1602_I2C_H_

extern uint8_t arr[] , arr_size;

// the rest of your code goes here

#endif

The actual declarations and initialization of those extern variables should be in your LCD1602_I2C.c file something like this:

 

uint8_t i, bitmask = 0x08;

uint8_t arr[]={0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x41, 0x72,
	0x64, 0x75, 0x69, 0x6e, 0x6f, 0x20, 0x3a, 0x29, 0x20, 0x57,
	0x68, 0x61, 0x74, 0x27, 0x73, 0x20, 0x75, 0x70, 0x21, 0x20,
	0x48, 0x6f, 0x77, 0x27, 0x73, 0x20, 0x63, 0x6f, 0x64, 0x69,
	0x6e, 0x67, 0x20, 0x74, 0x6f, 0x64, 0x61, 0x79, 0x20, 0x3a,
0x29}, arr_size=sizeof(arr);

Lastly, you are missing a return statement in your BF function.

 

Hope that helps.

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

Oh yeah :)

 

You absolutely right!

 

Thank you very much,