View previous topic :: View next topic |
Author |
Message |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
Building statements? |
Posted: Wed Nov 14, 2007 2:36 pm |
|
|
I am looking at hooking up to a computer(That part is done) and build statements inside the code that are executed.These will be executed after compile time. Like building some if statements or more insticate. I am not really sure where to start. I have not used pointers much and not sure if it can be built from a string with a pointer. Let me know if you guys have any ideas. I have done a search but not much yet.. Thanx in advance.. TTY |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Wed Nov 14, 2007 2:59 pm |
|
|
Here is an example if it helps..
Statement1 :
taken from user: if input 1 is high then make output 4 low.
if(input(pin_a2))
output_low(pin_d4);
Statement 2:
Taken form user : if input2 is low or input 4 is greater than 3 then output 7 high and 4 low.
if((input(pin_a1) || (a2d_value > 3))
{
output_high(pin_c6);
output_low(pin_c3);
}
Keep in mind these are all fictional I just threw in some pin number.. Thanx.. TTY |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 10:05 am |
|
|
Bump....
Is this just really hard or is it so simple that I am missing so no one will respond? Let me know.. TTY
Just looking for some ideas.. Thanx |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Nov 16, 2007 11:08 am |
|
|
I don't think anyone has the faintest idea of what you are actually asking....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 11:16 am |
|
|
I will try to articulate.
I have 8 inputs and 8 outputs. I am taking information from the PC to let the pic know what to do.
I am looking for input from the user to build if statements from the input from the user.
So lets say the user inputs that he wants the output 9 to go high when inputs 4 and 5 are set high. I need to build that statement inside my code.
So the pic is running and it get an input for a new instruction.(Above) so now it must impliment the above statement in the code. So it must be able to execute the user defined staement somehow. I know I could do it with 1000 if and cases but I am looking to optomize it somewhat..
The user has the option or or's and's < > = and such..
I hope that spells it out a little better.. Basically building a staement from a string.. Thanx |
|
![](templates/subSilver/images/spacer.gif) |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Nov 16, 2007 11:22 am |
|
|
I think the poster is looking for a command interpreter? Where the command (string) can contain conditional execution statements. Create a syntax for your commands, then the code will follow from that.. |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 11:26 am |
|
|
Exactly... Sort of a query builder type thing but the code is exectued while running.. Thanx |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 11:33 am |
|
|
Would it be easier to do this part in assembly rather than in C? |
|
![](templates/subSilver/images/spacer.gif) |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Nov 16, 2007 11:37 am |
|
|
Well.. I would do it in C..
The complication as I see it is what happens if you assign conflicting conditions, say
Code: | if(input(pin_a2))
output_low(pin_d4); |
and
Code: | if(input(pin_a2) && 'something_else')
output_low(pin_d4); |
what should the micro do? You would have to do some sort of logic to sort this out.. |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 11:41 am |
|
|
Yeh it would be no problem if there was on a small number of possibilities but there is 8 inputs and 8 outputs and the use of < = > or and make the number of possibilities almost endless. That is where the problem is.
Thanx so far.. TTY |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Nov 16, 2007 12:18 pm |
|
|
You could look at it from the other direction. Each output could be assigned a conditional evaluation. When dealing with logic use logic operators. "< = >" are not logic operators.
Output1 = Input1 || (!Input2 && Input3);
This is inherently consistent. I think it's easier to read than an if statement. The only problem is how to encode, store, decode and evaluate the conditional statements. |
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 12:22 pm |
|
|
Sure that is fne but still stuck on how to build the statement.. TTY |
|
![](templates/subSilver/images/spacer.gif) |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Nov 16, 2007 12:46 pm |
|
|
Quote: | Output1 = Input1 || (!Input2 && Input3);
This is inherently consistent. I think it's easier to read than an if statement. The only problem is how to encode, store, decode and evaluate the conditional statements. |
I agree, and in this form is beginning to resemble logic equations. Note that the OP also wanted analog comparison:
Quote: | if((input(pin_a1) || (a2d_value > 3))
{
output_high(pin_c6);
output_low(pin_c3);
} |
So we could extend your syntax to, for example:
Code: | Output1 = Input1 || (!Input2 && Input3) || (AnInput4 > 3); |
|
|
![](templates/subSilver/images/spacer.gif) |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Nov 16, 2007 12:57 pm |
|
|
I still agree but that is the easy part. How do you build that equasion or statement whille the pic is running? Without using 10,000 if's.
TTY |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Nov 16, 2007 12:58 pm |
|
|
As was mentioned before what you want to build is called an interpreter. This is not related to the CCS compiler or PIC processor and from the minimal response you receive here it looks like the expertise you are looking for is not available in this forum.
My suggestion is to use Google and look for a better place to post your question. |
|
![](templates/subSilver/images/spacer.gif) |
|