Need help with simple serial functions
Hal Albach
Posts: 747
Using "Hello LCD.c" in the Example folder as a guide, I am trying to incorporate a LCD display into a clock/calender program I'm developing mainly to better learn C. The problem I have run up against is that that after 288 screen updates the propeller just stops. I'm using a serial LCD and this freezing/stopping occurs consistently. I think it may have to do with the fact that in the function that writes to the LCD I have to open a serial module before I can use dprint to display the information. I have tried to use the close function for the open modules but the compiler will not accept the statement. The error message is that an expression is expected before the word Serial in the parameter portion. x marks the spot the compiler is pointing to... serial_close(xserial *lcd); I have looked up the function in the library and I can't find anything requiring an expression at that point.
In the above function code the dprint line, the editor keeps dropping the percent 02 in front of the d's in the formatting, it accepts 2 of them but the actual code has only one for each.
/*---------------------------------------------------------------------------------------------- convert bcd to binary and print time */ void show_time() { char sec, min, hour; serial *lcd = serial_open(11, 11, 0, 9600); // Ex. BCD 53 is binary 83, to convert... sec = ((bytes[0] >> 4) * 10) + (bytes[0] & 0x0F); // BCD 53 >>4 = 05 * 10 = 50 + 03 = bin 53 min = ((bytes[1] >> 4) * 10) + (bytes[1] & 0x0F); hour = ((bytes[2] >> 4) * 10) + (bytes[2] & 0x0F); dprint(lcd, "?x00?y0%%02d:%%02d:%%02d\n", hour, min, sec); // %%02d prints a 0-padded 2 digit number serial_close(serial *lcd); } /*----------------------------------------------------------------------------------------------Here's the compiler messages...
Project Directory: I:/Users/Admin/My Documents/simpleide/My Projects/PCF8583_RTC/ propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2090) propeller-elf-gcc.exe -I . -L . -I I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Utility/libsimpletools -L I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Text Devices/libsimpletext -L I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Text Devices/libsimpletext/cmm/ -I I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Protocol/libsimplei2c -L I:/Users/Admin/My Documents/simpleide/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -o cmm/PCF8583_RTC.elf -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 PCF8583_RTC.c -lm -lsimpletools -lsimpletext -lsimplei2c -lm -lsimpletools -lsimpletext -lm -lsimpletools -lm PCF8583_RTC.c: In function 'show_time': PCF8583_RTC.c:52:16: error: expected expression before 'serial' Done. Build Failed! Click error or warning messages above to debug.When I try to move the open statement outside of Main I get an error stating that "an initializer is not constant". I am obviously doing something wrong, but am at a loss as to what it is.
In the above function code the dprint line, the editor keeps dropping the percent 02 in front of the d's in the formatting, it accepts 2 of them but the actual code has only one for each.
Comments
serial *lcd;
int main()
{
lcd = serial_open(...
...
}
...
void show_time()
{
char sec, min, hour;
...
dprint(lcd, "?x00?y0%%02d:%%02d:%%02d\n", hour, min, sec); // %%02d prints a 0-padded 2 digit number
}
Made the changes per your suggestion, unfortunately the LCD screen now remains blank. Compiles without error but does generate a warning re unused lcd variable. I added a dprint statement in Main and no more warning. Any dprint statement within Main outputs normally to the lcd but nothing from dprint in called functions. Doesn't the open statement lose scope outside of Main?
Can you post your new code?
and the .h file
[/code]
By re-declaring lcd inside of main and opening to that, your other functions won't have access.
Anything you declare inside of a function becomes local to the function ... like in spin.
Anything you declare outside of a function will be global.