# voltage level sent to a pin port on PIC18F

1. ## voltage level sent to a pin port on PIC18F

Hi guys, I am currently working on a project. I am using a PICF18 microcontroller, in addition I am using mikroC Pro to code. I need a bit of help with the coding.....i want to be able to turn on/off a BJT that will be connected to one of my pin ports. How can I send the needed dc voltage level to this pin port?? I am going to be using a keypad (i already wrote this code), so I would just need a function that sends this needed voltage to the pin when the user wants to activate the switch (send 1.5 Vots) and a function that will deactivate the BJT(send 0 volts to the pin port). Any ideas?? •

2. ## voltage level sent to a pin port on PIC18F

If you need to send a voltage different from VCC through io port, then you should need a da.
I think there is one more simpler way to implent you function then using da.

First, devide pin port output voltage, like this:  •

3. ## Re: voltage level sent to a pin port on PIC18F

I was thinking of doing that....I actually got the 5 volts that the PIC can supply....so i was thinking of just using voltage divider to get it to close to 1.5 V •

4. ## Re: voltage level sent to a pin port on PIC18F

If you are driving the output pin high and low (writing to the pin without changing TRIS) you can omit R2 in most cases. The transistor will always hold about 0.65V between base and emitter so all you have to do is choose R1 so the current through it is adequate. Choose R1 with the formula (Vpin - 0.65) / Ib. You can decide Ib by dividing the BJT collector current by its Hfe parameter which is on the data sheet.

For example, if the BJT collector current was 100mA and it's Hfe is 50, Ib would be (0.1/50) = 0.002A. If you assume the PIC pin is 5V when high, R1 would be (5-0.65)/.002 = 2175Ω. In practice you could use 2.2KΩ.

Your values might be different but you have not specified the real BJT or load current.

Brian. --[[ ]]--