Shop OBEX P1 Docs P2 Docs Learn Events
BS1 Code Help — Parallax Forums

BS1 Code Help

ArchiverArchiver Posts: 46,084
edited 2000-08-16 18:05 in General Discussion
Hello,

Can somebody more knowledgeable help me in understanding what's
happening with the code between two For... Next loops in the article
that I've attached?

The first few lines of code are for resetting the smartcard and start
reading the data contained in its EEPROM, after placing reset pin of the
smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
that allow reading more of the data. My problem in understanding is with
the code between Next... For loops, specially the codes for b1 and b2?

I'll appreciate any help in understanding the code.

Best regards,
Tayeb Habib

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-08-15 22:51
    The code in question reads:

    for b0 = 0 to 31
    b2 = 0
    for b1 = 0 to 7
    b2 = b2 * 2
    b2 = b2 + PIN4
    high 6
    low 6
    next b1
    write b0,b2
    next b0

    The gist is that the code reads 32 bytes of data from the
    smartcard and writes it to the stamps EEPROM.
    Heres a commented version that should help:

    for b0 = 0 to 31 'loop through the 32 bytes of internal stamp
    EEPROM
    b2 = 0 'clear b2
    for b1 = 0 to 7 'loop for 8 bits of data
    b2 = b2 * 2 'shift b2 left by 1 bit
    b2 = b2 + PIN4 'add a bit of data from the smartcard to b2
    high 6 'pull pin6 hi
    low 6 'pull pin6 low
    next b1 'next bit
    write b0,b2 'write data in b2 to stamp EEPROM location b0
    next b0 'next EEPROM location


    Original Message
    From: Tayeb Habib [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=EwBGukEtkuuaLP0dKz3pbpPtwzhUYFeFwlN3LwkWho6eLDCjoGzf52rIYIoFL-iKTL6j1xAbDikBwRASdQ]vendas@a...[/url
    Sent: Tuesday, August 15, 2000 12:09 PM
    To: BASICSTAMPS
    Subject: [noparse][[/noparse]basicstamps] BS1 Code Help


    Hello,

    Can somebody more knowledgeable help me in understanding what's
    happening with the code between two For... Next loops in the article
    that I've attached?

    The first few lines of code are for resetting the smartcard and start
    reading the data contained in its EEPROM, after placing reset pin of the
    smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
    that allow reading more of the data. My problem in understanding is with
    the code between Next... For loops, specially the codes for b1 and b2?

    I'll appreciate any help in understanding the code.

    Best regards,
    Tayeb Habib
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-15 23:12
    Tayeb,

    What the code between the FOR...NEXT loops is doing is this....

    The variable B0 holds the EEPROM location to which the data read from the
    smart card will be written (0 to 31) using the WRITE statement. This is
    advanced for each byte read from the card.

    The variable B1 holds the bit position in the byte being read (0 to 7), this
    is advanced by one for each bit read from the card.

    The variable B2 holds the (emerging) byte read from the card at pin 4. What
    the line B2=B2*2 is doing is in fact left-shifting the bit pattern
    previously read (eg. %00000001 * 2 = %000000010, etc.). The next line
    (B2=B2+pin4) is adding (bitwise ANDing) the bit read at pin 4 (so if pin 4
    was high, and assuming that B2 is now %00000010, we get B2 being equal to
    %00000011, etc.) The high 6 / low 6 are clock pulses as you know, and the
    rest should all be clear....

    Note that B2 is reset to %00000000 before each byte is "read" from the
    smart-card (top of outer loop).

    Hope that helps.

    Lance.

    >
    Original Message
    > From: Tayeb Habib [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ycTJinsTJgUe995i-CW6wp16Bd-wRTaW5qiMoYhcGaefORPzvMeikRvTWPizMHO87JYynTuQIpLg1g]vendas@a...[/url
    > Sent: Wednesday,16 August 2000 5:09
    > To: BASICSTAMPS
    > Subject: [noparse][[/noparse]basicstamps] BS1 Code Help
    >
    > Hello,
    >
    > Can somebody more knowledgeable help me in understanding what's
    > happening with the code between two For... Next loops in the article
    > that I've attached?
    >
    > The first few lines of code are for resetting the smartcard and start
    > reading the data contained in its EEPROM, after placing reset pin of the
    > smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
    > that allow reading more of the data. My problem in understanding is with
    > the code between Next... For loops, specially the codes for b1 and b2?
    >
    > I'll appreciate any help in understanding the code.
    >
    > Best regards,
    > Tayeb Habib
    > << File: SmartCard1.pdf >>
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-16 10:33
    Dear Andrew:

    Thank you for your help.

    That means that we could read the contents of the BS1 EEPROM using:

    read b0,b2

    correct?

    Best regards,
    Tayeb Habib

    Andrew Tucker wrote:

    > The code in question reads:
    >
    > for b0 = 0 to 31
    > b2 = 0
    > for b1 = 0 to 7
    > b2 = b2 * 2
    > b2 = b2 + PIN4
    > high 6
    > low 6
    > next b1
    > write b0,b2
    > next b0
    >
    > The gist is that the code reads 32 bytes of data from the
    > smartcard and writes it to the stamps EEPROM.
    > Heres a commented version that should help:
    >
    > for b0 = 0 to 31 'loop through the 32 bytes of internal stamp
    > EEPROM
    > b2 = 0 'clear b2
    > for b1 = 0 to 7 'loop for 8 bits of data
    > b2 = b2 * 2 'shift b2 left by 1 bit
    > b2 = b2 + PIN4 'add a bit of data from the smartcard to b2
    > high 6 'pull pin6 hi
    > low 6 'pull pin6 low
    > next b1 'next bit
    > write b0,b2 'write data in b2 to stamp EEPROM location b0
    > next b0 'next EEPROM location
    >
    >
    Original Message
    > From: Tayeb Habib [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=t0O3_buBPYAtwCz1XCVH5IK2ITChTULBh9RM9ig9WLiNQKgxpT9kBy1M4TUNhn8vIgZkL66C4vuJhGe_]vendas@a...[/url
    > Sent: Tuesday, August 15, 2000 12:09 PM
    > To: BASICSTAMPS
    > Subject: [noparse][[/noparse]basicstamps] BS1 Code Help
    >
    > Hello,
    >
    > Can somebody more knowledgeable help me in understanding what's
    > happening with the code between two For... Next loops in the article
    > that I've attached?
    >
    > The first few lines of code are for resetting the smartcard and start
    > reading the data contained in its EEPROM, after placing reset pin of the
    > smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
    > that allow reading more of the data. My problem in understanding is with
    > the code between Next... For loops, specially the codes for b1 and b2?
    >
    > I'll appreciate any help in understanding the code.
    >
    > Best regards,
    > Tayeb Habib
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-16 10:34
    Dear Lance:

    Thanks for your help.

    Best regards,
    Tayeb Habib

    Hobson, Lance wrote:

    > Tayeb,
    >
    > What the code between the FOR...NEXT loops is doing is this....
    >
    > The variable B0 holds the EEPROM location to which the data read from the
    > smart card will be written (0 to 31) using the WRITE statement. This is
    > advanced for each byte read from the card.
    >
    > The variable B1 holds the bit position in the byte being read (0 to 7), this
    > is advanced by one for each bit read from the card.
    >
    > The variable B2 holds the (emerging) byte read from the card at pin 4. What
    > the line B2=B2*2 is doing is in fact left-shifting the bit pattern
    > previously read (eg. %00000001 * 2 = %000000010, etc.). The next line
    > (B2=B2+pin4) is adding (bitwise ANDing) the bit read at pin 4 (so if pin 4
    > was high, and assuming that B2 is now %00000010, we get B2 being equal to
    > %00000011, etc.) The high 6 / low 6 are clock pulses as you know, and the
    > rest should all be clear....
    >
    > Note that B2 is reset to %00000000 before each byte is "read" from the
    > smart-card (top of outer loop).
    >
    > Hope that helps.
    >
    > Lance.
    >
    > >
    Original Message
    > > From: Tayeb Habib [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=miM4n70xtRY_dXIhpAAoVhArn7UIzYKTrXNCNc15CDm1jRBBTj6tZxF-M3jNNg5yn-h7vcvvmyUzWg]vendas@a...[/url
    > > Sent: Wednesday,16 August 2000 5:09
    > > To: BASICSTAMPS
    > > Subject: [noparse][[/noparse]basicstamps] BS1 Code Help
    > >
    > > Hello,
    > >
    > > Can somebody more knowledgeable help me in understanding what's
    > > happening with the code between two For... Next loops in the article
    > > that I've attached?
    > >
    > > The first few lines of code are for resetting the smartcard and start
    > > reading the data contained in its EEPROM, after placing reset pin of the
    > > smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
    > > that allow reading more of the data. My problem in understanding is with
    > > the code between Next... For loops, specially the codes for b1 and b2?
    > >
    > > I'll appreciate any help in understanding the code.
    > >
    > > Best regards,
    > > Tayeb Habib
    > > << File: SmartCard1.pdf >>
  • ArchiverArchiver Posts: 46,084
    edited 2000-08-16 18:05
    I have to check the manual to be sure, but yes I think that's correct.

    Original Message
    From: Tayeb Habib [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=vs4dkQlJRfiNqx0qWIvcG6aMzSKD3scGURl0krROP-pTGkCWarPR0j5lAYapoP3ZQY1y7qNives]vendas@a...[/url
    Sent: Wednesday, August 16, 2000 2:33 AM
    To: basicstamps@egroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] BS1 Code Help


    Dear Andrew:

    Thank you for your help.

    That means that we could read the contents of the BS1 EEPROM using:

    read b0,b2

    correct?

    Best regards,
    Tayeb Habib

    Andrew Tucker wrote:

    > The code in question reads:
    >
    > for b0 = 0 to 31
    > b2 = 0
    > for b1 = 0 to 7
    > b2 = b2 * 2
    > b2 = b2 + PIN4
    > high 6
    > low 6
    > next b1
    > write b0,b2
    > next b0
    >
    > The gist is that the code reads 32 bytes of data from the
    > smartcard and writes it to the stamps EEPROM.
    > Heres a commented version that should help:
    >
    > for b0 = 0 to 31 'loop through the 32 bytes of internal
    stamp
    > EEPROM
    > b2 = 0 'clear b2
    > for b1 = 0 to 7 'loop for 8 bits of data
    > b2 = b2 * 2 'shift b2 left by 1 bit
    > b2 = b2 + PIN4 'add a bit of data from the smartcard to b2
    > high 6 'pull pin6 hi
    > low 6 'pull pin6 low
    > next b1 'next bit
    > write b0,b2 'write data in b2 to stamp EEPROM location b0
    > next b0 'next EEPROM location
    >
    >
    Original Message
    > From: Tayeb Habib [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=vs4dkQlJRfiNqx0qWIvcG6aMzSKD3scGURl0krROP-pTGkCWarPR0j5lAYapoP3ZQY1y7qNives]vendas@a...[/url
    > Sent: Tuesday, August 15, 2000 12:09 PM
    > To: BASICSTAMPS
    > Subject: [noparse][[/noparse]basicstamps] BS1 Code Help
    >
    > Hello,
    >
    > Can somebody more knowledgeable help me in understanding what's
    > happening with the code between two For... Next loops in the article
    > that I've attached?
    >
    > The first few lines of code are for resetting the smartcard and start
    > reading the data contained in its EEPROM, after placing reset pin of the
    > smartcard as low. Within the loop, high 6 and low 6 are the clock pulses
    > that allow reading more of the data. My problem in understanding is with
    > the code between Next... For loops, specially the codes for b1 and b2?
    >
    > I'll appreciate any help in understanding the code.
    >
    > Best regards,
    > Tayeb Habib
Sign In or Register to comment.