typecasting on macro

"M. Fahmy F." <[email protected]> Sat, 24 May 2003 07:47:28 +0700
Newsgroups gmane.comp.hardware.avr.general
Message-ID <000c01c3218e$4be9ec00$6400a8c0@bengkel>
Hi all,

I need your time to tell me how come this does not work, meaning that I
can't get it work with HyperTerminal.
I defined macro THE_VALUE in my header file for initialising UBRRH and UBRRL
registers.
At my C source (line 24-25) I tried to split THE_VALUE and initiate UBRRH
and UBRRL.
By then it should be UBRRH = 0 and UBRRL = 12, BUT......
in the code listing the compiler tried to initiate UBRRL with 60 (look at
label .LM8).....
and UBRRH with -1 (look at label .LM9).

I guess it is the typecasting that generate warning at messege output.

Any comment?

Regards,
M. Fahmy F.



Header file:
============================
#include <avr\io.h>

#if defined(__AVR_ATmega8__)
 #define MCU_CLOCK 4000000
 #define BAUDRATE  19200
 #define THE_VALUE ((MCU_CLOCK/(16*BAUDRATE))-1)
 #define KB_DATA   PD4
 #define KB_CLK    PD3
#else
 #error "No Chip Selected"
#endif
============================


C source:
============================
20 void
21 uart_init( void ) {
22     #if defined(__AVR_ATmega8__)
23     /* setting baud rate */
24     UBRRL = ( unsigned char ) THE_VALUE;
25     UBRRH = ( unsigned char ) ( THE_VALUE >> 8 );
26     //outb( UBRRL, ( unsigned char ) THE_VALUE );           // DOES NOT
WORK
27     //outb( UBRRH, ( unsigned char ) ( THE_VALUE >> 8 ) );  // DOES NOT
WORK
28     //UBRRL = 12; // this works
29     //UBRRH = 0;  // this works
30
31     /* disable double speed async and MPCM */
32     //UCSRA = ; // using default
33
34     /* enable receiver and transmitter */
35     UCSRB = ( 1 << TXEN ) | ( 1 << RXEN );
36
37     /* UART frame format: 1,8,n,1 */
38     //UCSRC = 0x86; // default initial value after reset
39     #endif /* __AVR_ATmega8__ */
40 }
============================


Compiler messeges:
============================
Generating Object Files
avr-gcc -c -g -O3 -Wall -Wstrict-prototypes -Wa,-ahlms=my_uart.lst -mmcu=atm
ega8 -I. my_uart.c -o my_uart.o
my_uart.c: In function `uart_init':
my_uart.c:24: warning: integer overflow in expression
my_uart.c:25: warning: integer overflow in expression
============================


Code listing
============================
  20:my_uart.c     **** void
  21:my_uart.c     **** uart_init( void ) {
  86                 .stabn 68,0,21,.LM7-uart_init
  87                .LM7:
  88                /* prologue: frame size=0 */
  89                /* prologue end (size=0) */
  22:my_uart.c     ****     #if defined(__AVR_ATmega8__)
  23:my_uart.c     ****     /* setting baud rate */
  24:my_uart.c     ****     UBRRL = ( unsigned char ) THE_VALUE;
  90                 .stabn 68,0,24,.LM8-uart_init
  91                .LM8:
  92 0018 3CE3        ldi r19,lo8(60)
  93 001a 39B9        out 41-0x20,r19
  25:my_uart.c     ****     UBRRH = ( unsigned char ) ( THE_VALUE >> 8 );
  94                 .stabn 68,0,25,.LM9-uart_init
  95                .LM9:
  96 001c 2FEF        ldi r18,lo8(-1)
  97 001e 20BD        out 64-0x20,r18
  26:my_uart.c     ****     //outb( UBRRL, ( unsigned char ) THE_VALUE );
  27:my_uart.c     ****     //outb( UBRRH, ( unsigned char ) ( THE_VALUE >>
8 ) );
  28:my_uart.c     ****     //UBRRL = 12;
  29:my_uart.c     ****     //UBRRH = 0;
  30:my_uart.c     ****
  31:my_uart.c     ****     /* disable double speed async and MPCM */
  32:my_uart.c     ****     //UCSRA = ; // default
  33:my_uart.c     ****
  34:my_uart.c     ****     /* enable receiver and transmitter */
  35:my_uart.c     ****     UCSRB = ( 1 << TXEN ) | ( 1 << RXEN );
  98                 .stabn 68,0,35,.LM10-uart_init
  99                .LM10:
 100 0020 28E1        ldi r18,lo8(24)
 101 0022 2AB9        out 42-0x20,r18
  36:my_uart.c     ****
  37:my_uart.c     ****     /* UART frame format: 1,8,n,1 */
  38:my_uart.c     ****     //UCSRC = 0x86; // default initial value after
reset
  39:my_uart.c     ****     #endif /* __AVR_ATmega8__ */
  40:my_uart.c     **** }
============================




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.483 / Virus Database: 279 - Release Date: 5/19/03