Optimizing code for BS1
PeterH
Posts: 21
Hi There
·
I have connected a BS1 Project Board and a LCD app Mod display to a IR sensor, in order to count people passing through a door and display the total on the LCD.
·
I have written a small program to count and display how many people pass:
There are two registers -· a daily and· a periodic register. The daily register can be reset by activating a button. Both the daily and the periodic registers are shown on the display and the registers are written to the Eprom every time they change. I have also added a feature of only counting every other time the IR sensor is activated, presuming that all the people entering the room/shop will also exit through the same door.
The program is working fine but I have (again) run out of space, because I would like exchange the IR sensor with and ultrasonic sensor . Using an ultrasonic sensor requires a bit more coding, since I have to make two measurements ( pings) and compare them to see If anybody has passed through the door
·
·
·
Running out of space ·has happened many times with this· program but now I have run out of ideas to shorten the size of the code.
I am therefore looking for ideas to tighten up my code and free some space.
·
I hope you have some ideas
·
·
Best regards
·
PeterH
·
I have connected a BS1 Project Board and a LCD app Mod display to a IR sensor, in order to count people passing through a door and display the total on the LCD.
·
I have written a small program to count and display how many people pass:
There are two registers -· a daily and· a periodic register. The daily register can be reset by activating a button. Both the daily and the periodic registers are shown on the display and the registers are written to the Eprom every time they change. I have also added a feature of only counting every other time the IR sensor is activated, presuming that all the people entering the room/shop will also exit through the same door.
The program is working fine but I have (again) run out of space, because I would like exchange the IR sensor with and ultrasonic sensor . Using an ultrasonic sensor requires a bit more coding, since I have to make two measurements ( pings) and compare them to see If anybody has passed through the door
·
·
·
Running out of space ·has happened many times with this· program but now I have run out of ideas to shorten the size of the code.
I am therefore looking for ideas to tighten up my code and free some space.
·
I hope you have some ideas
·
·
Best regards
·
PeterH
Comments
There is limited program memory available on the BS1. If your application is text intensive, which using an LCD might imply, then you may need to move to a BS2 or other BASIC Stamp with more memory. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
btnc = %1
btnc = btnc & PIN6
can become:
btnc = PIN6
That is just what I need!
You freed up 3 bytes. I really appreciate suggestions like that.
I have spent quite som time looking af mny subroutine to display the character on screen. Does anybody see a posibillity of makiing that shorter?
/Peter
===========================
WRITE_To_Lcd:
· GOSUB LCD_Command
· 'char = DisplayVar/10000· +$30
· Dividevar = 10000
· FOR idx =1 TO 4
·· char = DisplayVar/dividevar//10· +$30········· ' Parse the value of DisplayVar
·· GOSUB LCD_Write_Char·························· ' Display· each digit of DisplayVar
·· Dividevar = Dividevar /10
· NEXT
· char = DisplayVar//10· + $30
· GOSUB LCD_Write_Char
RETURN
I may be wrong about this, but I think that you can save some space by deleting that subroutine, and simply putting that command itself into your code wherever you'd been calling the subroutine. In other words, try replacing all the
GOSUB LCD_Command
with
LOW RS
and then deleting the LCD_Command subroutine.
Post Edited (sylvie369) : 11/6/2008 1:12:12 PM GMT
Thanks for the tip, but LCD_command: falls through to LCD_Write_Char: so in fact the effective subroutine is longer and combining the two does not free up space.
But I appreciate your effort
/Peter