Need 16 outputs!

Graham Ogle

New Member
I am generating a 16 bit number, upto 15999, and want to address 16 output pins to programme a frequency synthesiser. I'm sure the answer is in the archives, but after 2 days of looking, I can't find it. Sorry if it only came up last week.

Question 1
How do I split the number into 2 8 bit numbers and then use the Let Pins command?

I was planning to use a 40X chip, but with a LCD display taking one output, I need to send one of the 8 bit numbers to a 18X to give 16 output pins.

Question 2
What is the best way of sending the 8 bit number to the 18X chip? Use another output and use Serout on the 40X and Serin on the 18X?

Any help, much appreciated.
Thanks
Graham
 

andrewpro

New Member
If I were in your shoes, I would get an MCP23017 from microchip. They're less than $1US or not much more, have 16 outputs (or inputs if you want) and are addressable via I2C. Which means you only need to use 2 pins on your X series picaxe.

--Andy P
 

Graham Ogle

New Member
Thanks for the tip and that chip will do what I want. But the only problem is that I'm having difficulty understanding the datasheet, let alone get it working!
 

hippy

Ex-Staff (retired)
With your 16-bit number in a word variable, the two component 8-bit parts ( most significant 8 bits and least significant 8 bits ) are already held in overlayed byte variables. For w0, lsb is b0, msb is b1. For w1, lsb is b2, msb is b3 and so on.

If you wanted to be more explict in doing the maths, then ...

- w0 = <16-bit number>
- msb = w0 / 256
- lsb = w0 & $FF

If you wanted to put the lsb of w0 out to the pins, both of these would achieve it ...

- w0 = <16-bit number>
- pins = b0

- w0 = <16-bit number>
- pins = w0 & $FF
 
Last edited:

womai

Senior Member
Another option is the Maxim 7300 I/O expander. It gives you 20 outputs in the same DIP package (28 pin) as the Microchip one. I have some working code I can send you once you are there (also make a search for &quot;7300&quot; on the forum, that will produce several hits.

For I2C, two things are worth mentioning:

- first, read the I2C tutorial on the Picaxe website, and look at the desrciption for the Basic commands readi2c, writei2c, and i2cslave.

- don't forget the 4.7 kOhm pullup resistors on the SDA and SCL lines. The exact value is not very critical, everything between 2 and 5 kOhm will work.

- the slave address is 7 bits long, but it's the seven most significant bits of the address byte (the least significant bit is used to specify a read or write and is set by the Picaxe commands automatically). I.e.. the address byte in binary notation is %aaaaaaar where &quot;a&quot; are the address bits and &quot;r&quot; is the read/write flag. The data sheet usually gives only the address bits, you have to add a zero (or one) to get the correct parameter for i2cslave.

Wolfgang


Edited by - womai on 05/04/2006 03:58:29
 

SD2100

New Member
Possibly another option is the 8255 ppi (programmable peripheral interface) 40 pin
chip. Has 24 i/o pins in 3 8 bit ports,
each port can be setup as either inputs or
outputs, the chip is setup by sending it a
control byte, very easy to use. This chip
has been around for a long time and can be
salvaged from old computer gear.

 
Top