【发布时间】: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
链接:
PLC: http://www.teso.com.au/pro-teso/PC1-Controllers/PC1600-Controller.aspx
【问题讨论】:
-
更改条形长度是否适用于
static声明?并且auto在 Rabbit 编译器中是否有特殊含义?auto通常不需要。 stackoverflow.com/questions/2192547/… -
“将其声明为静态的当然行不通” 我认为问题说是行得通,但不是
autolocal def。 -
对不起,我之前的评论完全错误,所以我删除了它。不使用“auto”会有所不同,将条形声明为:
char bar[6];使其工作。也像static char bar[6];一样声明它有效。我不知道auto在Rabbit编译器中是否有特殊含义,我正在学习自己,我所知道的就是我的代码不起作用。
标签: c arrays embedded lcd dynamic-c