I have 12V, Use these 12V to power a device (that has a 12V output signal) and to power a 7805. After the 7805 there is a pic microcontroller where I would have to connect the output from my device. I was thinking of having 2 resistors in a 3/1 ratio in order to have about 4V at the pin of the pic. Can this be done, given that the ground is common, or will it give some sort of problem with the lm7805?
All you need is one resistor about 100k in sereis with the signal. the PIC has internal diodes that will protect it from the current that flows in the resistor. the input will appear high for voltages above about 2 to 3 volts, if you want to increase that threshold to around 6V then adding a 47K resisto from the GPIO to ground would do that.
LM7805 can swallow a few milliamperes of back-feed so if the pic isn't using the excess signal current the 7805 will deal with it for you, if you're worried put a 5.1V zener parallel with the PIC.
However I don't think 7805 is really suited to automotive applications, the voltages can be well above 40V
I was thinking of having 2 resistors in a 3/1 ratio in order to have about 4V at the pin of the pic. Can this be done, given that the ground is common,
Yes, you can do that. However it may not be safe if the device's 12V output has transients on it (due to EMI or an inductive load) and if the PIC is not powered then enough current might be injected into the IO pin to start it up.
To isolate the PIC from the signal source I use a bipolar transistor, which is much more robust than the MCU's CMOS input. The circuit looks like this:-
Of course this circuit inverts the signal, but that is easy to accommodate in software (just remember that logic 0 = 12V on).
R3 and R2 are chosen to produce ~0.6V on the Base of Q1 at around half the expected input voltage (6V in this case). D1 is only required if there is a possibility of large negative voltage spikes, which might be caused by a motor or relay across the input.
To further reduce the number of components you can use a 'digital' transistor (with built-in Base resistors) and the MCU's internal pullup in place of R1. However this may make the circuit more susceptible to EMI, and if the transistor breaks down it could feed high voltage into the MCU.
In one project I used a digital transistor with additional resistance in series with the Base, both to raise the input threshold and provide extra protection. The SOT-23 transistor and 1206 size resistor didn't take up much board space.