making a 'C' function
gregfox
Posts: 68
in Propeller 1
Hi all, I’m trying to craft together a function for the following code to put in my library. I tried several methods but each and every one failed. I want the counter to return seconds for a LCD stopwatch I’m making. I know the ‘pause(1000)’ will not give me true seconds but I can deal with that later using some spin code, but for now I’m using C.
So to make this question more clear, I want a function I could call from main like ‘int counter()’ or something like that, that would output seconds. When I put the main body in a function if fails, and so I’m at a loss.
Any help would be most appreciated.
So to make this question more clear, I want a function I could call from main like ‘int counter()’ or something like that, that would output seconds. When I put the main body in a function if fails, and so I’m at a loss.
Any help would be most appreciated.
#include "simpletools.h" #include "lcd.h" int main() { inithd44780(); //init LCD hd44780 function from my lib // Main counter for(int t = 0; t >= -1; t++) //count to ~ { seconds = t; char str[80] ; hours = seconds / 3600; minutes = seconds / 60; mins_left = minutes % 60; secs_left = seconds % 60; sprintf(str, " Time %d:%d:%d ",hours, mins_left, secs_left ); //above 20 line LCD must have 20 spaces after %d LCDline(2); //go to line 2 on the LCD function from my lib for(int i = 0; i < 20; i++) //allow only 20 characters { data(); //following this command is data function from my lib set_outputs (lsbpin,msbpin, (str[i])); //one character at a time from msbit to lsbit pause(TW); //wait 1 mS strobe(); //latch the data function from my lib } pause(947); //wait 947mS } }
Comments
If the body of MyFunction came before main(), I wouldn't need the forward declaration (that's what that thing is called).
If that isn't what's happening, post the code that's not compiling and someone here will surely be able to point in the right direction.
We call that "box" a "struct".
or