Using USART with LCD program

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

I have been playing with Dean's USART tutorial and have it working nicely with Mega128 and bray's terminal.

The problem I have however, is when using danni's LCD code, I add the USART code to it and it wont compile. I get the following error:

main.c:23: error: invalid operands to binary >> (have 'double' and 'int')

The code looks like so:

#include 
#include 

#include 
#include 
#include "main.h"
#include "lcd_drv.h"
#include "lcd_drv.c"



#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)


int main (void) 
{
	char ReceivedByte;
	
	UCSR0B |= (1 << RXEN) | (1 << TXEN); //Turn on transmission and Reception
	UCSR0C |= (1 << UMSEL0) | (1 << UCSZ0) | (1 << UCSZ1); //8-bit Character size

	UBRR0H = ( BAUD_PRESCALE >> 8); // Load upper 8- bits of the baud rate value into the high byte of the UBRR register
	UBRR0L = BAUD_PRESCALE ;// Load lower 8- bits of the baud rate value into the low byte of the UBRR register

	for(;;)
	{
		while ((UCSR0A & (1 << UDRE0)) == 0) {};
		
		ReceivedByte = UDR0;
		
		while (( UCSR0A & (1 << UDRE0 )) == 0) {};
		
		UDR0 = ReceivedByte ;
		
	}
}

If I remove the following headers

#include "main.h"
#include "lcd_drv.h"
#include "lcd_drv.c"

It compiles fine.
Any ideas how to resolve this would be appreciated.

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

Why make people figure out which is the error line ?! Indicate it plainly... I don't see any of Danni's LCD code in the posted code .

Don't add *.c files like that ! In pjt. view right click on source files and add existing file. Read Dean's "Managing large C..."

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

sorry the error line is

UBRR0H = ( BAUD_PRESCALE >> 8);

danni's header files are in there I just haven't used his code for what I'm planning to do yet. I was trying to get the USART example to compile with the LCD headers first. Apologies for being unclear

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

What's in main.h ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#ifndef _main_h_
#define _main_h_


#include 
#include 
#include "mydefs.h"


#define	XTAL	8e6			// 8MHz

#define F_CPU   XTAL
#include 


#define	LCD_D4		SBIT( PORTC, 4 )
#define	LCD_DDR_D4	SBIT( DDRC, 4 )

#define	LCD_D5		SBIT( PORTC, 5 )
#define	LCD_DDR_D5	SBIT( DDRC, 5 )

#define	LCD_D6		SBIT( PORTC, 6 )
#define	LCD_DDR_D6	SBIT( DDRC, 6 )

#define	LCD_D7		SBIT( PORTC, 7 )
#define	LCD_DDR_D7	SBIT( DDRC, 7 )

#define	LCD_RS		SBIT( PORTC, 2 )
#define	LCD_DDR_RS	SBIT( DDRC, 2 )

#define	LCD_E0		SBIT( PORTC, 3 )
#define	LCD_DDR_E0	SBIT( DDRC, 3 )


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

I have added lcd_drv.c to my makefile rather than including it at the start of the program.

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

I assumed that the LCD files were from Danni's tut., but you do some of his code in main.h . So it's not really known what's in the LCD.* files. So now which of the two *.h files give that error ( comment one out at a time and see ) ?

Maybe it doesn't like how F_CPU is being done...( but I know that notation is supported in Winavr ) ?

When you take out all 3 files, then how do you define F_CPU ( if you do at all ) ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

after commenting out main.h it compiles with no errors

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

1) Try defining F_CPU by writing 8MHz with all the zeros instead of what you did.

2) You didn't answer my last question. :?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Your problem here is that you have optimisation set to -O0

Also while it should work it would be more "normal" to define F_CPU as:

#define F_CPU 8000000UL

rather than

#define F_CPU 8e6

(or indirectly via "XTAL" as done above).

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

Clawson, why does it throw an error for -O0 level ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

clawson wrote:
Your problem here is that you have optimisation set to -O0

Also while it should work ...

I don't think so. If XTAL is a float constant, then BAUD_PRESCALE is a float constant too. Optimization (no matter what level) won't change the type of anything.

Besides changing the #define of XTAL (or F_CPU) a type cast within the BAUD_PRESCALE macro would also help.

Stefan Ernst

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

It doesn't like F_CPU defined that way. I got the same error, but when I typecasted F_CPU as uint32_t in BAUDPRESCALE OR did it the normal way, the error goes away. :)

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

indianajones11 wrote:
It doesn't like F_CPU defined that way. I got the same error, but when I typecasted F_CPU as uint32_t in BAUDPRESCALE OR did it the normal way, the error goes away. :)

clawson wrote:
Also while it should work it would be more "normal" to define F_CPU as:

#define F_CPU 8000000UL

rather than

#define F_CPU 8e6

(or indirectly via "XTAL" as done above).


I could have sworn that there was a thread discussion about F_CPU causing problems when defined in Engineering notation. I believe it was Cliff that had mentioned that then too. Try as I might, a search for that netted no results.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

thanks for the replies guys, i defined F_CPU as so:

#define F_CPU 8000000UL

this seems to resolve the issue.

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

Quote:
main.c:23: error: invalid operands to binary >> (have 'double' and 'int')
When a constant is defined as a decimal number
#define X 1000.0

or in e-notation

#define X 1e3

than it becomes of type float (double).