0

I'm new to programming in any form of C.

I have a PLC (Teso PC1620) (using a rabbit processor) with an LCD screen (matrix orbital LK204-7T-1U-USB-WB). I'm trying to use the build in horizontal bar/graph function of the LCD.

The code below works but I want to be able to change the length of the bar (6th value in the "bar" array). I tried this with the code commented out instead of the static constant for "bar" this appears not to work and gives random bars on the LCD.

What could cause this and is there maybe an easier/better way to assign the "bar" array.

#use "oempc16xxdrivers.elib"                            //Include the OEM pro-teso PC16XO driver library
#define DINBUFSIZE 31                                   //Defining the serial IN buffer size
#define DOUTBUFSIZE 31                                  //Defining the serial OUT buffer size

void main()
{

static const char clear[] = {254,88};         //Clear LCD command
static const char load[] = {254,104};             //Initialize horizontal bar
static const char bar[] = {254,124,1,1,0,54};  //Place horizontal bar(245,124) column,Row,Direction,Length

auto int percentage;
auto int rxKey;
//auto char bar[6];

IOInit();                                         //Initialises the PC1600 (PLC).
serDopen(19200L);                                 //Setting the baudrate of the serial port
serDrdFlush();                                    //Flushes the serial port D input buffer
serDwrFlush();                                        //Flushes the serial port D transmit buffer

serDwrite(clear,sizeof(clear));                //Clear LCD
serDwrite(load,sizeof(load));                  //Initialize horizontal bar

 //  bar[0] = 254;
 //  bar[1] = 124;
 //  bar[2] = 1;
 //  bar[3] = 1;
 //  bar[4] = 0;
 //  bar[5] = 54;

    for(;;)
    {
   rxKey = serDgetc();

   percentage = 10;
   //bar[5] = percentage;

    if (0x42 == rxKey)
    {
    serDwrite(bar,sizeof(bar));
    }
   }

serDclose ();
}

Dynamic c Version 9.62

Links:

LCD: https://www.matrixorbital.com/advanced_search_result.php?keywords=LK204-7T-1U+usb&search.x=0&search.y=0

PLC: http://www.teso.com.au/pro-teso/PC1-Controllers/PC1600-Controller.aspx

Weather Vane
  • 33,872
  • 7
  • 36
  • 56
CookieB
  • 3
  • 2
  • Did changing the bar length work with the `static` declaration? And does `auto` have a special meaning in the Rabbit compiler? `auto` is not usually necessary. http://stackoverflow.com/questions/2192547/where-is-the-c-auto-keyword-used – Weather Vane Apr 13 '15 at 19:20
  • *"Declaring it static won't work of course"* I thought the question said is does work, but not `auto` local def. – Weather Vane Apr 14 '15 at 22:12
  • Sorry, my previous comment was completely wrong, so I removed it. Not using "auto" made the difference, declaring the bar like: `char bar[6];` made it work. Also declaring it like `static char bar[6];` works. I don't know if `auto` has a special meaning in the Rabbit compiler, I'm learning myself, all I know it made that my code didn't work. – CookieB Apr 15 '15 at 09:48

1 Answers1

0

Your code seems to be correct.

Is it possible that you are very short on stack space? This could very well be the culprit since you added an automatic variable.

Try if it works if you define bar as a global/static.

mfro
  • 3,286
  • 1
  • 19
  • 28
  • Not using "auto" made the difference, declaring the bar like: `char bar[6];` made it work. Also declaring it like `static char bar[6];` works. thanks for the help! – CookieB Apr 15 '15 at 09:54