BS2p40 Help please

Hello from the UK

I am a total newbie with regards to programming and have had a problem dropped onto me that I am hoping you could help me with.

We use a BS2p40 within a PCB that drives a paper handling machine - within the program on the machine is a life counter (stored in the BS2p40).

Is their a short program that I can use to completely erase the program within the BS2p40 so that I can reprogram the PCB and thus have a zero life count ?

Thank you in anticipation



  • Hello servo123,
    Welcome !

    To start with the simplest solution...

    Do you have the source code of the program running on that BS2p40 module.. ?

  • Hi
    Yes I have the source code for the program.

    I can post this tomorrow but what I am looking to do is just erase the eeprom and then reprogram.

    Do you want me to post the source code?

    And thank you for answering so quickly

  • As VonSzarvas said, it would be good to have the source to figure out the variable that needs to be reset.
    Should be an easy fix.
  • tomcrawfordtomcrawford Posts: 1,075
    edited 2019-01-16 - 00:15:02
    As I see it, you just need to use the Basic Stamp IDE to compile and re-load your software. Presumably that will zero any counters. Of course you need the cable with adapter that goes between your PC and your board.

    Edit: The cable is on the floor behind Juan's workbench. :D
  • VonSzarvas asked the perfect first question.

    Also, if the BS2P40 can utilize slots, so each slot may need to be wiped. As mentioned, the source code will tell how the variable is being saved as well as determine if just a reprogram would wipe out the variable.
  • I agree it would nice to see the Pbasic code. I'm thinking you could just reload it if you know your code has everything you want.
  • Hello again and thank you all for the comments

    As requested I have uploaded the main body of the code (it also calls several different language files Eng, Span, Fren etc... and a test program I did not upload those but can if you feel they are relevant)

    @tomcrawford - When I reprogram the EEprom with the default program it overwrite it but does not overwrite the life counter - I am assuming that this is because the life counter is stored in an area that is not over written.

    I was hoping for just a quick or simple program that I could upload to the eeprom to take it back to a 'virgin' chip so I could then reinstall the default program.

    Thanks again for all your help so far - my understanding of programming is very limited but I can follow the flow reasonably well.

  • I'm thinking the counter is in page 7 (because of the STORE 7 commands). But there are only 6 files (in addition) to the one you posted. That is, there isn't a file that gets loaded into page 7. I guess you could just temporarily add one to the first line, thus:
    ' {$STAMP BS2p,Test600_1p2.bsp,english_1p3.bsp,french_1p0.bsp,german_1p0.bsp,spanish_1p0.bsp,initialize.bsp, page7.bsp}

    page7.bsp would look like:
    {$STAMP BS2p}
    {$PBASIC 2.5}
    DATA 0 (2048)       'initialize to all zeroes
  • If that doesn't work, you could always
    {$STAMP BS2P
    {$PBASIC 2.5}
    Page  VAR  Byte
    Loc    VAR  WORD
    FOR Page = 1 TO 7
      STORE Page
      FOR Loc = 0 to 2047
        WRITE Loc, 0

    Kinda brute forcee, but it will get pages 1 through 7 back to where they were when they were shipped.
  • If that doesn't work, you could always
    {$STAMP BS2P
    {$PBASIC 2.5}
    Page  VAR  Byte
    Loc    VAR  WORD
    FOR Page = 1 TO 7
      STORE Page
      FOR Loc = 0 to 2047
        WRITE Loc, 0

    Kinda brute force, but it will get pages 1 through 7 back to where they were when they were shipped.

    Tom, That's a great solution. I just opened the BS2P file to look at it. I would have gone way overboard to fix it.
  • Good solution Tom, that will make it simple.

    In looking at the code, I want to clarify something that seems amiss. This is how I am interpreting the code:

    The variable "life_count" is a variable defined for the life count in thousands. The constant "msglen" is being used to define the maximum size of a message to be stored and any constant using the format "X*msglen" is essentially mapped to one of the 37 long pieces of the total 2047 locations. So, life_count goes in to the lifecounter location at 7*msglen, so it is stored starting at location 259.
    lifecounter    CON      7*msglen
    So far, it makes sense at seems to be a clever way of managing where things are stored in EEPROM.

    When I look for where life_count is used, I see it where it gets set to zero during initialization, line 193/194, and then gets set to the value from EEPROM at line 204 through a subroutine. However, in the subroutine called (read_life_count), it is referencing two other locations in memory for a low and high byte.
    read_life_count:                                                                         ' READ LIFE COUNTER DATA FROM EEPROM
     READ (15*msglen),life_count.LOWBYTE
     READ (16*msglen),life_count.HIGHBYTE

    For those locations, they are called out for "infeed_jam" and "folder_jam", but I don't see them actually being modified anywhere else in the program. They are called out to be displayed if an Infeed jam occurs or if a folder jam occurs, but then the LCD would just show the life count if that happened rather than something else useful.
    infeed_jam     CON      15*msglen                                                        ' PS600
    folder_jam     CON      16*msglen

    So, my conclusion is technically they can be used for life_count since they are not actually used for what they are called for in the CON section, but am I reading things correctly and is it true that something seem amiss?
  • Hi Tom,

    thank you for your assistance - almost there but a couple of problems.

    1. The life counter changes back to 00
    2. The life counter increments by 10 and not 1 (I suspect this is because of what it is displaying in point 1)
    3. If I run the program for a second time the life counter does not go back to 00 it stays on what I have just run.

    For your info I tried both programs and they both work but change the life count to 00 and have the same incremental issue.

    I really appreciate your help

  • Hi Tom

    Quick update - I have made two further changes to the code -

    1. In the main program (section attached) -In the code below I changed the <10 to <0 (highlighted)

    count_forms: ' ROUTINE TO ADD 1 TO FORMS COUNTER
    forms_low=forms_low+1//10000 ' add 1 to forms count upto 10000
    forms_high=forms_high+1 - (forms_low MAX 1)//10 ' add 1 to forms count high
    SEROUT 0,N9600,[16,80,18,"5",DEC forms_high,DEC4 forms_low,4] ' send count to LCD
    counter=counter+1 ' add 1 to life count
    IF counter<0 THEN missthis ' if counter>10 then allow life count to add 1
    life_count=life_count+1 ' add 1 to life count
    counter=0 ' reset counter
    missthis: RETURN

    2. I looked at the actual message in the language file and it displayed

    lifecounter DATA @7*msglen,cursor_pos,80,"Life: 0",0

    From the little I know I am aware that anything in between the quotes would display.

    So far, so good and I am testing the machine now and will give you some feedback later today.

    Thanks again :smiley:
  • @tomcrawford - Just a quick update to let you know that all is functioning correctly now using a combo of you short program and a bit of tweaking to the code.

    Thank you for your assistance and to all that had contributed ideas

  • Our pleasure. This is a good forum.
Sign In or Register to comment.