Aduino to WinAVR lib port

Hi everyone!

I'm familiar with Arduino but have a project where most of the libraries are in WinAVR with the exception of one: LEDCONTROL.h

When I attempt to compile my project, I get the following error:

h:/winavr-20100110/lib/gcc/../../avr/include/avr/ledcontrol.h:30: error: expected '=', ',', ';', 'asm' or ' before 'B01111110'

Here is line 30 (and after) from the ledcontrol.h file:

#define const static byte charTable[128] = {
    B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
    B01111111,B01111011,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B10000000,B00000001,B10000000,B00000000,
    B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
    B01111111,B01111011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
    B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
    B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001000,
    B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
    B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
    B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
};

This compiles fine in the Arduino environment but apparently WinAVR has issues with it.

I'm a long-time Pascal programmer trying to come up to speed with C so any help would be appreciated!

Hi,
the problem lies in setting the value of the elements of the array with binary constants (Bxxxxxxx) which are defined in file binary.h from the arduino core.

You can either add this file (arduino/hardware/core/binary.h I think) to your project, or replace the 128 bytes in charTable with values in hex or decimal notation. I used the binary notation because there is a clear connection between a '1' in a value and a lit segment on a 7-segment display.

Eberhard

Thanks for the info. It now understands the definitions but now returns a new error similar to the old one:

h:/winavr-20100110/lib/gcc/../../avr/include/avr/ledcontrol.h:30: error: expected '=', ',', ';', 'asm' or ' before numeric constant

with "numeric constant' being the operative word here.

It's almost like Arduino and WinAVR have a different method for setting Byte Arrays (?). I'm sure it's something minor.

Thanks again for any help

#define const static byte charTable[128] = {

"#define" there is ... wrong. It should be just
const static byte charTable[128]= {(and it IS, in the version of ledcontrol.h I just downloaded from the playground...) Is that a transcription error into your posting, or into your program?

Thanks West but still no joy. This is maddening and my lack of understanding of C dialects certainly makes this no easier. Pascal is looking better by the moment :wink:

Here is the short code snippet of LEDControl.h leading up to the errors:

#include <WProgram.h>
#include <binary.h>

#ifndef LedControl_h
#define LedControl_h

/*
   Segments to be switched on for characters and digits on
   7-Segment Displays
*/


const static byte charTable[128]= {
    B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
    B01111111,B01111011,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B10000000,B00000001,B10000000,B00000000,
    B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,
    B01111111,B01111011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
    B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
    B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001000,
    B00000000,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,B00000000,
    B00110111,B00000000,B00000000,B00000000,B00001110,B00000000,B00000000,B00000000,
    B01100111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
    B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
};



class LedControl {
 private :
    /* The array for shifting the data to the devices */
    byte spidata[16];
    /* Send out a single command to the device */
    void spiTransfer(int addr, byte opcode, byte data);

    /* We keep track of the led-status for all 8 devices in this array */
    byte status[64];
    /* Data is shifted out of this pin*/
    int SPI_MOSI;
    /* The clock is signaled on this pin */
    int SPI_CLK;
    /* This one is driven LOW for chip selectzion */
    int SPI_CS;
    /* The maximum number of devices we use */
    int maxDevices;

. . .

which gives me the following error on Make:

Compiling C: example.c
avr-gcc -c -mmcu=at90usb1286       -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsign
ed-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./example.lst  -std=gnu99 -MMD -MP -MF .dep/example.o.d example.c -o example.o

In file included from example.c:30:

h:/winavr-20100110/lib/gcc/../../avr/include/avr/ledcontrol.h:32: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'charTable'

h:/winavr-20100110/lib/gcc/../../avr/include/avr/ledcontrol.h:53: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'LedControl'
make: *** [example.o] Error 1

I'm sure one day in the future I'll look back at this post and laugh (after looking at my early Delphi examples) and slap myself.

Any help is appreciated. I've about worn Google out trying to fix this seemingly simple problem. Whew!

Hi,
I can't spot anything directly, but this is the Arduino-IDE commandline when an LedControl example is compiled :

avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L

Yours look much more restrictive with things like "-std=gnu99". I dont know if this makes a difference but maybe its worth a try?

Also
#include "WProgram.h"
will bring the whole Arduino-Core into your project. A lot of code in the core is processor-specific and will not run or even compile on you at90usb1286 processor.

My advice would be to remove the
#include "WProgram.h"
and recreate the functions from the Arduino-Core that are used by LedControl for your processor/board.
This shouldn't be too much works since the library uses only "pinMode,digitatlWrite,shiftOut" from the core.

Eberhard