Program Editor Language and serial bit output.

PNeil

New Member
Hello everyone, I am new to PICAXE programming. I would like to know if it is possible to create an array of bits (not bytes) and send them serially out of one of the micro-controller pins. I explore the eeprom and serout command and they seem to work with only bytes, not bits.

I have a LED display with (built in) led driver chip ST2225A. It requires 36 bits at a time to be sent to the chip. (1 start bit and 35 others).

I am a MFC and C++ programmer, I did BASIC years.. ago.

thanks.
 

hippy

Ex-Staff (retired)
It should be possible. This is called "bit-banging" where the software sets an output line high or low for however long it needs to be then moves onto the next bit, or, instead of fixed-time periods per bit a separate line is pulsed high or low to 'clock the data out'.
 

moxhamj

New Member
That chip would work perfectly with a picaxe. It has a data and a clock line, so it does not matter whether you clock the data in slow or fast. You could write the code slow initially with pauses then speed it up by removing the pause statements.

You will need to build your group of 36 bits but because timing is not an issue, you could build them in (say) groups of 8 and send out 8, then build the next group.
 

westaust55

Moderator
Which PICAXE do you have?

If it is the 28X1 or the 40X1 life should be easier. The SHIFTOUT command (see manual 2 at page 166 in Rev 6.5b) allows you to define the number of bits to transfer from each byte.

For 35 bits you could try:

Code:
SHIFTOUT sclk, sdata, mode, (b1, b2, b3, b4, b5/3)
so 4 bytes at 8 bits each then 3 bits from the 5th byte to get 35 bytes in total.

Note: may need b5/4 if start bit needs to be the first bit of b1 and part of the data stream


otherwise if your PICAXE is not an X1 part then you need to look at the code example given in manual 2 immediately after the SHIFTOUT commands details for an example of "Bit Bashing".

EDIT:
Looking at the datasheet seems the first bit is pushed through the ST2225A internal shift register to:
1. Activate a loading of the data into the internal Latches, and then
2. reset the shift register so that it is clear for the next block of data.

If 2. did not happen, then any "1" in the shift register would be pushed through and load the latches with incorrect data during the next data transfer.
So b5/4 is the sugegsted option for the last byte in an X1 part.
 
Last edited:

PNeil

New Member
PICAXE Serial bit output

The part I am using is a 18X.

The program editor gives a syntax error on the following line. I check the manual and found the command.

SPIOUT pin_used_as_clock, pin_used_as_data, mode, (bits_to_send/how_much)

SPIOUT 0, 1, 1, (b1 / 8) ‘ clock 8 bits from b1

also try

SPIOUT 0, 1, MSBFirst_L, (b1)
 

moxhamj

New Member
SPIOUT would be perfect. The only catch, as described in the manual, is that it only works on the X1 and X2 parts. Picaxe nomenclature can be a bit confusing - the 18X is not an X1 nor an X2. So it will give a syntax error. But... the good news is on the next page of the manual, where it gives the equivalent code in a few lines of standard instructions. So it should be quite possible to do this with maybe 10-15 lines of code.

In general, you have a binary number eg %0101010100001110. You want to know the value of the bit on the end - either the left end or the right end. So you 'mask' it with a number eg %0000000000000001 by doing a logical 'and'. If the answer is a 1, then the right bit was a 1. If a 0, then it was a 0. Then send out this byte. Then finally, you want to shift all the bits along one. Eg if you want to move them all to the right, then divide the number by 2. If to the left, then multiply by 2.

If you understand these principles, then the code in the manual will make a lot more sense.

I like to do this with very slow code and with 'high' and 'low commands and pauses of several seconds between each output. Put a led on a pin, put in a 'debug' statement and watch the number come out slowly in binary.
 

PNeil

New Member
PICAXE serial bit out...

Thanks, Dr_Acula,

I change the chip to a 28X1 part #PIC16F886 and it works. The LED display is a Lite-On LTM-Y2K19JF-03.

Each bit control one LED segment, now I have to figure out which segment is turned on and which one is off, based on the bits sent.

The following program produce 00000 ' ' -- on the display.

b0 = %11111110
b1 = %00000000
b2 = %00000000
b3 = %00000000

high 3 ' reset the ST2225A
pause 10
low 3

for b5 = 1 to 8

spiout 0,1,1, (b0/8) ' clock 8 bits from b0
spiout 0,1,1, (b1/8) ' clock 8 bits from b1
spiout 0,1,1, (b2/8) ' clock 8 bits from b2
spiout 0,1,1, (b3/4) ' clock 4 bits from b3 (MSB side)

next b5
 
Top