code optimalization
Hi
I have been working an a nice project for quite some time now. Everything is working nice but I have been waking against the memory limited space of the sx28. So I 'm now trying to optimise my code so that it fits all into the sx28.
I was wondering if somebody knows a simple way to set outputs on different pins high or low with one word.
ex.
I want to set ra.0 and rb.0 to high and ra.1 to low sometimes during my program flow. In some other time i need to set ra.0 low and rb.0 to high. Leaving the other pins unchanged.
Is thier a way to define that in a constant with a good name and use only the name afterwoods in the program flow? Is that gaining me program space then?
I 'm using sx/B.
Thanks for any suggestions.
stef
·
I have been working an a nice project for quite some time now. Everything is working nice but I have been waking against the memory limited space of the sx28. So I 'm now trying to optimise my code so that it fits all into the sx28.
I was wondering if somebody knows a simple way to set outputs on different pins high or low with one word.
ex.
I want to set ra.0 and rb.0 to high and ra.1 to low sometimes during my program flow. In some other time i need to set ra.0 low and rb.0 to high. Leaving the other pins unchanged.
Is thier a way to define that in a constant with a good name and use only the name afterwoods in the program flow? Is that gaining me program space then?
I 'm using sx/B.
Thanks for any suggestions.
stef
·
Comments
pinA0 var ra.0
To make the pin high use
· pinA0 = 1·· (this translates into setb ra.0)
To make the pin low use
· pinA0 = 0·· (this translates into clrb ra.0)
Without seeing your code·we cannot give good advice
on how to optimize your code.
regards peter
Thanks for your reaktion. Sorry I can not post the code. The end user wants his code private so I have to respect that.
The post you made is verry clear. I alraedy use that like that. The only thing I was wondering. Can you do that also for several pins at the same time.
Something like
pins VAR ra.0,rb.1,rb.6
pins = 1
Your example is using a one to one relation. Can it be a one to many? (but not the complete poort and/or different ports)
stef
pinA0 CON $001
pinA1 CON $002
pinA2 CON $004
pinA3 CON $008
pinB0 CON $101
pinB1 CON $102
pinB2 CON $104
pinB3 CON $108
pinB4 CON $110
pinB5 CON $120
pinB6 CON $140
pinB7 CON $180
pinC0 CON $201
pinC1 CON $202
pinC2 CON $204
pinC3 CON $208
pinC4 CON $210
pinC5 CON $220
pinC6 CON $240
pinC7 CON $280
You can combine pins of the same port like this:
pinsB = pinB0 OR pinB3
To set the pins specified by pinsB
rb = rb OR pinsB
To clear the pins specified by pinsB
pinsB = not pinsB
rb = rb AND pinsB
To automatically set pins of the·same port you can use a subroutine
SUB setPortPins· 'call this with a wordparameter like pinsB
pinmask = __PARAM1
port = __PARAM2
branch port,setA,setB,setC
return
setA:
ra = ra OR pinmask
return
setB:
rb = rb OR pinmask
return
setC:
rc = rc OR pinmask
return
ENDSUB
For clear, you can define something simular using AND instead of OR.
Question is if this really optimizes your code, because setting up pins
and calling the subroutine also takes quite some code.
Another option to optimize is changing some of the sxb code into assembly.
regards peter
You offen specify "same port ". So it is not possible to AND/OR on pins from different ports?
Stef
regards peter
- Sparks
I will look into it. thanks for the tip. I also use a lot of DATA arguments to store some static data. They seem to took also a lot off place. Has someone experiance (perhaps a schema and some examples) to connect memory to the sx28. I can then leave my program in the sx28 and place the data in the memory ic. The only problem then is that I have not mutch i/O pins free.
stef