problem regarding building a header file

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

here is my main.c

#include 
#include 
#include "MrLCD.h"
int main(void)
{
InitializeMrLCD();
Send_A_StringToMrLCDWithLocation(1,1,"X:");
Send_A_StringToMrLCDWithLocation(1,2,"Y:");

ADCSRA |= 1<<ADPS2;
ADMUX |= 1<<REFS0 | 1<<REFS1;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;

sei();

ADCSRA |= 1<<ADSC;

while (1)
{
}
}
ISR(ADC_vect)
{
uint8_t theLow = ADCL;
uint16_t theTenBitResult = ADCH<<8 | theLow;

switch (ADMUX)
{
case 0xC0:
Send_An_IntegerToMrLCD(4, 1, theTenBitResult, 4);
ADMUX = 0xC1;
break;
case 0xC1:
Send_An_IntegerToMrLCD(4, 2, theTenBitResult, 4);
ADMUX = 0xC0;
break;
default:
//Default code
break;
} ADCSRA |= 1<<ADSC;
}

microcontroller used is ATMEGA32

this code is for reading two axis of accelerometer and displaying on LCD.

apart from that i have a header file MrLCD.h Which i am placing below

#ifndef MrLCD
#define MrLCD
#include 
#include 
#include 

#define MrLCDsCrib PORTB
#define DataDir_MrLCDsCrib DDRB
#define MrLCDsControl PORTD
#define DataDir_MrLCDsControl DDRD
#define LightSwitch 5
#define ReadWrite 7
#define BiPolarMood 2

char firstColumnPositionsForMrLCD[4] = {0, 64, 20, 84};

void Check_IF_MrLCD_isBusy(void);
void Peek_A_Boo(void);
void Send_A_Command(unsigned char command);
void Send_A_Character(unsigned char character);
void Send_A_String(char *StringOfCharacters);
void GotoMrLCDsLocation(uint8_t x, uint8_t y);
void InitializeMrLCD(void);

void Check_IF_MrLCD_isBusy()
{
DataDir_MrLCDsCrib = 0;
MrLCDsControl |= 1<<ReadWrite;
MrLCDsControl &= ~1<<BiPolarMood;

while (MrLCDsCrib >= 0x80)
{
Peek_A_Boo();
}

DataDir_MrLCDsCrib = 0xFF; //0xFF means 0b11111111
}

void Peek_A_Boo()
{
MrLCDsControl |= 1<<LightSwitch;
asm volatile ("nop");
asm volatile ("nop");
MrLCDsControl &= ~1<<LightSwitch;
}

void Send_A_Command(unsigned char command)
{
Check_IF_MrLCD_isBusy();
MrLCDsCrib = command;
MrLCDsControl &= ~ ((1<<ReadWrite)|(1<<BiPolarMood));
Peek_A_Boo();
MrLCDsCrib = 0;
}

void Send_A_Character(unsigned char character)
{
Check_IF_MrLCD_isBusy();
MrLCDsCrib = character;
MrLCDsControl &= ~ (1<<ReadWrite);
MrLCDsControl |= 1<<BiPolarMood;
Peek_A_Boo();
MrLCDsCrib = 0;
}

void Send_A_String(char *StringOfCharacters)
{
while(*StringOfCharacters > 0)
{
Send_A_Character(*StringOfCharacters++);
}
}

void GotoMrLCDsLocation(uint8_t x, uint8_t y)
{
Send_A_Command(0x80 + firstColumnPositionsForMrLCD[y-1] + (x-1));
}

void InitializeMrLCD()
{
DataDir_MrLCDsControl |= 1<<LightSwitch | 1<<ReadWrite | 1<<BiPolarMood;
_delay_ms(15);

Send_A_Command(0x01); //Clear Screen 0x01 = 00000001
_delay_ms(2);
Send_A_Command(0x38);
_delay_us(50);
Send_A_Command(0b00001110);
_delay_us(50);
}

#endif

but i am getting 4 errors while building in AVRSTUDIO4 kindly help me out so that i can build this code

Quote:
C:\Users\apoorva\Desktop\uartfromcomp\bhadyblast\default/../bhadyblast.c:31: undefined reference to `Send_An_IntegerToMrLCD'
C:\Users\apoorva\Desktop\uartfromcomp\bhadyblast\default/../bhadyblast.c:35: undefined reference to `Send_An_IntegerToMrLCD'
bhadyblast.o: In function `main':
C:\Users\apoorva\Desktop\uartfromcomp\bhadyblast\default/../bhadyblast.c:7: undefined reference to `Send_A_StringToMrLCDWithLocation'
C:\Users\apoorva\Desktop\uartfromcomp\bhadyblast\default/../bhadyblast.c:8: undefined reference to `Send_A_StringToMrLCDWithLocation'
make: *** [bhadyblast.elf] Error 1
Build failed with 4 errors and 3 warnings...

Last Edited: Tue. May 7, 2013 - 06:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After having typed in all your source code, would it have been too much trouble to present the four errors you got from the compiler?

You've defined actual executable code in a "dot h" header file, which is not a good practice in general. In this case, so long as no other module in your project includes MrLCD.h, things will still work.

I'd guess that two of your errors are complaints about never having provided a "Send_A_StringToMrLCDWithLocation()" declaration (or definition, either), and that the other two complaints are that you never declare or define a "Send_An_IntegerToMrLCD".
Though these aren't the cause of your problems, I'd suggest some improvements:

1) Indent your code
2) Use the 16-bit ADCW register to read the ADC's conversion results
3) Add a "MrLCD.c" module to your project that contains all the executable code you now
have in "MrLCD.h". In "MrLCD.h" you should only have function declarations, such as

extern void Send_A_Character(unsigned char character);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I'd guess that two of your errors are complaints about never having provided a "Send_A_StringToMrLCDWithLocation()" declaration (or definition, either), and that the other two complaints are that you never declare or define a "Send_An_IntegerToMrLCD".
can you please tell me the correct code i should write for MrLCD.h

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

The LCD code you are using appears to be code that was originally written by a user here called yogeshpatel. So you might want to search out all the prior threads to understand it better (see for example this and this). What you will learn was that he was clearly just a beginner and the code isn't very good. There are many, many quality libraries for LCD support so I don't see the point in putting too much effort into getting something that's not very good to work?

The first clue was all this "send a command to Mr. LCD" nonsense. Normal programmers don't write code like a 10 year old child.

Save yourself a lot of hassle and just Google for something like "fleury avr lcd" and use what you find there.

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

Quote:

Save yourself a lot of hassle and just Google for something like "fleury avr lcd" and use what you find there.

A good starting point for using character LCDs with AVRS, including a link to Fleurys stuff: http://www.johanekdahl.se/rwiki/...

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]