【问题标题】:Dynamic C (Teso PC1620-PLC) controling LDCDynamic C (Teso PC1620-PLC) 控制 LDC
【发布时间】:2015-04-13 18:45:06
【问题描述】:

我是任何形式的 C 编程新手。

我有一个带有 LCD 屏幕(矩阵轨道 LK204-7T-1U-USB-WB)的 PLC (Teso PC1620)(使用兔子处理器)。 我正在尝试使用 LCD 的内置水平条形图/图表功能。

下面的代码有效,但我希望能够更改条的长度(“条”数组中的第 6 个值)。 我尝试使用注释掉的代码而不是“bar”的静态常量,这似乎不起作用,并在 LCD 上给出随机条。

是什么导致了这种情况,是否有一种更简单/更好的方法来分配“bar”数组。

#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 ();
}

动态 c 版本 9.62

链接:

液晶显示器: 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

【问题讨论】:

  • 更改条形长度是否适用于static 声明?并且auto 在 Rabbit 编译器中是否有特殊含义? auto 通常不需要。 stackoverflow.com/questions/2192547/…
  • “将其声明为静态的当然行不通” 我认为问题说是行得通,但不是auto local def。
  • 对不起,我之前的评论完全错误,所以我删除了它。不使用“auto”会有所不同,将条形声明为:char bar[6]; 使其工作。也像static char bar[6]; 一样声明它有效。我不知道auto在Rabbit编译器中是否有特殊含义,我正在学习自己,我所知道的就是我的代码不起作用。

标签: c arrays embedded lcd dynamic-c


【解决方案1】:

您的代码似乎是正确的。

您的堆栈空间是否可能非常短缺?这很可能是罪魁祸首,因为您添加了一个自动变量。

如果您将 bar 定义为全局/静态,请尝试它是否有效。

【讨论】:

  • 不使用“auto”会有所不同,像这样声明栏:char bar[6]; 使它起作用。也像static char bar[6]; 一样声明它有效。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2011-05-12
  • 1970-01-01
  • 2020-04-10
  • 2017-08-19
  • 1970-01-01
  • 2011-10-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多