Help with seven segment display code

Hi, I am using an 18m2 picaxe and i need to use it to control two 7 segment displays (so i can go to 0-99 instead of just 0-9).
I have read manual 3 pg.21 that explains the setup and code, but i am confused about the code.
I plan on using the same circuit and CMOS 4511B as the manual.

The code is:

main: for b1 = 0 to 9 ‘ Set up a for...next loop using variable b1
let pins=b1 ‘ Output b1 onto the four data lines
pause 1000 ‘ Pause 1 second
next b1 ‘ Next
goto main ‘ Loop back to start

the part that i dont understand is the "let pins = b1" part

how does it know which 4 pins to send the data too?

obviously i need 4 pins sending data to one CMOS 4511B and then to one display, and another four sending to another.

So how do i tell the program to send data out the pins i want?

Could someone write me code to count from 1-20 or something and tell me what 8 pins should the two displays be connected too to go with this code?

much appreciated!
-james
 

inglewoodpete

Senior Member
The command let "pins=b1" is for older PICAXE chips. Refer to manual 2 "Let PinsB" for outputting a byte to Port B of an 18M2

You were asking about driving 2 displays, so that you could count from 0 to 99.

If you understand binary counting, you will know that the number %1010 (10 decimal) follows %1001 (9 decimal). However, if driving a 4-bit counter chip like the CD4511, there is no "carry" generated to the upper 4 bits of the counter that you would want to drive your second CD4511. So, if driven by simple binary, the display would not show a "1" in the upper 7-segment display until the binary counter has reached %10000 (16 decimal). Not what you want.

Some of the more powerful PICAXE chips have the Bin2BCD command to convert an 8-bit binary number to a 2 digit "binary coded decimal" number. Not so the 18M2. However, it can be done with code.

Remember, the PICAXE only uses integers, so it discards any remainder from a division. So, you could use some code like this:
Code:
#PICAXE 18M2
#Terminal 4800        'Handy for debugging
Do
   For b1 = 0 to 99   'Binary counting
      Pause 1000
      b2 = b1 / 10    'Get the hundreds part of the number
      b2 = b2 * 16    'Move the hundreds value into the upper 4 bits of b2
      b3 = b1 // 10   'Get the units part of the number (the remainder as an integer)
      b4 = b2 Or b3   'Combine the upper and lower BCD digits into one byte
      SerTxd("b1 (Bin) = ", #b1, "  b2 (BCD) = ", #b2, CR, LF)
      PinsB = b4      'Output the value to the CD4511 7-segment driver chips
   Next b1
Loop
Edit: Oh yes: which pins do you use. Have a look and the 18M2 Pinout diagram in Manual 1. You will see that Port B has 8 pins, numbers B.0 through to B.7. These correspond to the 8 bits in the byte that is output in the command "Let PinsB = Bx".
 
Top