I have many I/Os lines in my circuit and the current PIC16F877A can't fullfill the requirement. Currently, except the MCLR, OSC1, OSC2, PGD, PGC, PGM pins, all others are used. I also use multplexing method and input and output lines on the same port method. As I don't want to make the circuit and program so complicated and also now, still is of shortage five I/Os. Are there other MCU models which have more I/O pins that I can used instead of this one or some other methods?

There a lot of tips and tricks that are very useful. I confess I would have definitely progressed a lot if I read it some time ago. There are many
circuits and designs that I tried before and problems encountered before..

For the several keys on a port using RC charging time method, it is a bit difficult for me to write the program indeed...

It's hard to say without more detail.
Recently I made a project using a resistor ladder and one ADC pin to read ten buttons. Of course it only works if only one button is pressed, but sometimes that is all you need.

Every situation is different. There are no hard and fast rules on how to accommodate all your I/O needs.

The first step would be to make a list of all the I/O pins you need and their functions.
Some functions may be able to share I/O pins.

The first solution, of course, is to go with a chip with a higher pin count.
Sometimes this is not acceptable. In that case, you start looking at multiplexing and I/O expansion taking advantage of SPI, I2C, UART interfaces etc.

In a complex system integration design, it is possible to go to a RS-485 network. I have do this very successfully in industrial applications.

I'd say first of all see which functions you can multiplex (pushbuttons and LED indicators would be easiest) and if that doesn't help enough, the first thing to try would be SPI. That's very easy to use and interface with other hardware.

You need a second PIC for the I/O, which you can transfer via a 3-wire or 4-wire bus.

DAT - serial data
CLK - serial clock
RDY - strobe from the slave that it is ready to accept data (must cycle through 1-0-1 to avoid out of sync).
SEL - select chip line if you use more than one slave PIC, so you can share the 3-wire serial bus for more than one chip.

All this can be done in software.

If you use the hardware serial port, you can get away with less I/O even. But then you need to design interrupt handlers, and buffering.

Some time ago, i have sucessfully used resistor laddler method in a port to detect several input lines. However, I can apply it only in several positions type sliding switch. It stays on a position and have fixed voltage and then another position of another fixed voltage. I can't apply it in momentary buttons in which voltage rises back to high voltage (5V) when it is released, in the course, different voltages are sensed and make wrong judgement.

I did it a similar way to button debouncing:
Every 20ms read ADC
Convert ADC to button number
Compare to button number from 20ms ago
If it's the same the button is pressed, if not ignore it and save the button number for next time.
Here's the schematic:http://www.marksphotos.info/3w1.gif
Here' some scrappy, badly commented code (works fine though):

I have many I/Os lines in my circuit and the current PIC16F877A can't fullfill the requirement. Currently, except the MCLR, OSC1, OSC2, PGD, PGC, PGM pins, all others are used. I also use multplexing method and input and output lines on the same port method. As I don't want to make the circuit and program so complicated and also now, still is of shortage five I/Os. Are there other MCU models which have more I/O pins that I can used instead of this one or some other methods?

Thanks,

Click to expand...

Can you show us what your circuit looks like now? That is, what do you have connected to the microcontroller?

My circuit mainly consists a number of button switchs and LED indicators to do the logic functions to control two small DC voltage motors, in which one draws fairly large current that will be driven by relays or mosfets, 20A. Sorry that i can't post it because it was just sketched on paper. Actually, it is applied in industrial device. I may switch to 18F controller for the full-bridge PWM that it has, however, as the response is not so critical in my design, so I am still pending to do it.

BTW, I find PIC16F1526 from the Pagehandler of PIC website:

>it is SMD type, i need to upgrade my knowlegde and skill?? Yes, it is 2013, as an amateur like me, oh!?..
>will my debugger ICD2 be suitable for it? Any suggestion?
>I haven't any demonstration board for 18F and 16F in the past and usually assembling the trial boards on my own to do debugging.
>what type of demo board shall i need to purchase for this IC?
>I use MPLAB IDE v8.10 and PICCLITE and old version PIC18 complier, what types and version of softwares shall i need for it?
>will this 16F1526 be a suitable choice or any suggestions?

Sorry that i have limit knowlegde outside 16F877A, 677, 628 and 18F482 microcontrollers.

>it is SMD type, i need to upgrade my knowlegde and skill?? Yes, it is 2013, as an amateur like me, oh!?..
With a small iron tip and a magnifier, thin solder and some solder wick anyone can solder tiny SMD parts.

Adapter boards are essential to wire these. An adapter gets the close leads onto a 0.1" center which normal humans can handle. QUAD flatpacks have leads on all 4 sides and hence don't work in solderless breadboards. That's not an issue for anyone with a soldering iron and some wire.

>will my debugger ICD2 be suitable for it? Any suggestion?
Pick a PIC device, open MPLAB, and when you hit the menu for Configure | Select device you will see all the supported programmers & debuggers for that PIC. So pick a PIC your ICD works with.

>I haven't any demonstration board for 18F and 16F in the past and usually assembling the trial boards on my own to do debugging.
>what type of demo board shall i need to purchase for this IC?
I am not aware of any demo boards, I'm sure they exist but I toss mine together myself.

>I use MPLAB IDE v8.10 and PICCLITE and old version PIC18 complier, what types and version of softwares shall i need for it?
I use MPLAB (non-X) and like it, I keep hearing about quirks in MPLAB-X.
The C18 compiler is still a free download. You get 60 days free for the full version, after that it works but you get bigger code.

>will this 16F1526 be a suitable choice or any suggestions?
Selector guide says 55 I/O pins, best check that in the data sheet! If you're comfortable with PIC16 then stay with it, though I don't see much of a difference between PIC16 and 18 when working in C., except the PICs with more memory are PIC18's.

BTW I keep a stock of adapters such as this on hand:

Good thing I keep some around, as my favorite Chinese vendor (free shipping but takes 2 weeks) is closed till 2/15 for the Chinese New years. Some vendors from Thailand have PIC specific adapter boards with placed for decoupling caps and even the pins for a PICkit.

>it is SMD type, i need to upgrade my knowlegde and skill?? Yes, it is 2013, as an amateur like me, oh!?..
With a small iron tip and a magnifier, thin solder and some solder wick anyone can solder tiny SMD parts.

Click to expand...

I use all regular soldering wire, a broad tip, sometimes also a desoldering pump and a magnifying glass.

Putting a TQFP64 adapter board on flywires is a tedious work, but, it is even self supporting with so many wires

If you want a 32 keys pad, make a matrix like for LEDs, use a shifter for the columns if you like, and test each with a "1" on the columns and see if there is a "1" on the rows.

Flywires yes, it is a lot of work for 64 lines. Not even to think about 80 or 100 wires. Actually I also have the SMD chips here and tried with the layout. Interleaving the RAM chips requires a lot of PCB space, and latches are required as well.