Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

12f675: Trisio & Gpio

Status
Not open for further replies.

Cagao

New Member
This stuff is completely losing me.

but lets start with just the TRISIO register on the 12F675 for now.

As i understand (which is apparently wrong), the TRISIO register sets which pins are for output.

I'm using the PICKit1 so hopefully you know of it.

from the example (state machine) source file, press the button and it rotates through the LEDs. To turn on any of the 8 LEDs on the board, the TRISIO is set to different values for different pairs of LEDs. That's the bit that's confusing me. if all you're doing is output, why not just set TRISIO to b'00000000'? OK, perhaps you need a bit ON (high?) for the input switch, pin 3 i believe.

Instead it is given as....

#define TRIS_D0_D1 B'00001111' ; TRISIO setting for D0 and D1
#define TRIS_D2_D3 B'00101011' ; TRISIO setting for D2 and D3
#define TRIS_D4_D5 B'00011011' ; TRISIO setting for D4 and D5
#define TRIS_D6_D7 B'00111001' ; TRISIO setting for D6 and D7

How does this relate to the GPIO register? Given in the code as ....

#define D0_ON B'00010000' ; D0 LED
#define D1_ON B'00100000' ; D1 LED
#define D2_ON B'00010000' ; D2 LED
#define D3_ON B'00000100' ; D3 LED
#define D4_ON B'00100000' ; D4 LED
#define D5_ON B'00000100' ; D5 LED
#define D6_ON B'00000100' ; D6 LED
#define D7_ON B'00000010' ; D7 LED

that 2nd lot is put in GPIO, which is fine, but why? why is it using the same value for D3, D5, and D6.

Sorry for such basic dumb questions, but this just isn't sinking in yet.

Thanks,

Rob
 
How's this?

TRISIO sets which pins are to be used as output. 0 for output, 1 for input, so assume an LED (D5) is connected to pins 4(+ve) and pin 7(-ve), and another LED (D4) is on the same pins but the other way round. To set those pins as output, set TRISIO to b'00011011' (pins for +5 and GND are not included right?)

or to be a bit clearer, b'xx0xx0xx', so I can ignore the other pin values, obviously they'd just be left as 0, but i'm messing with my code right now.

GPIO sets which pins are HI and LOW. Pin 4 is +ve for D5, so GPIO should be set as b'xx0xx1xx' to light D5, and b'xx1xx0xx' to light D4?

Would be greatly appreciated if someone can just double-check that and tell me if i've got it all horribly wrong, or if i'm bang on the money.
 
You've just totally confused me?.

It's simple, in the TRIS register a '1' means an input, and a '0' means an output - which you already know, and the bits are labelled D0 to D7, with D0 being the right hand bit of your binary values.

In the GPIO register (called PORT on larger PIC's) a '1' makes the output high, and a '0' makes it low.

Bear in mind you should disable the analogue inputs if you're not using them, or it messes things up if you're not careful.
 
Cagao said:
on pages 31 and 32 of https://www.electro-tech-online.com/custompdfs/2007/01/40051D-1.pdf look at the three LEDs D7, D5, and D1.

Is there any possible way to have them 3 on at the same time?

In reality NO, but practically 'yes', you turn them on in turn at a fast rate, and they give the appearance of all been ON. It's called multiplexing.

if so, what would the TRISIO and GPIO registers store?

This is the last bit of confusion I have over these 2 registers.

You're confusing yourself by trying to understand a fairly complex process, it's not possible 'static' only 'dynamic' - you would be better off starting with a PIC with more pins, so you don't have to resort to such complicated tricks.

As all the pins remain as outputs, then TRIS wouldn't change (all 0's), but the GPIO would be changing all the time.
 
That's perfectly the answer I was looking for.

It's not something i 'want' to do, but curious as to why it's not possible.

setting all pins as output, then pin 2 as HI, and pin 6 LO. The LEDs are in series, so why wouldn't they all light up? is it due to the pins inbetween each LED, if so, what sort of impact are they having being set HI or LO.
 
Last edited:
Cagao said:
The LEDs are in series, so why wouldn't they all light up?

If you looks closely, the LEDs are connected back-to-back.

When connected in this way, current in one direction will only go through one LED and the remaining LED will not light. Don't forget LED are diode too.

IF they are ordinary bulbs, then this connection method would not work.
 
Hmmmm, the LEDs D7, D5, and D1 are in series, not back-to-back, so i would expect them all to light up.

I'm aware of LEDs and how they only work one way round, but from the diagram in that document, they are all in the same direction.
 
So that's all that's stopping them all from lighting? the I/O of the pins in between don't affect? (apart from the obvious)

it's just that the current can't get that far?

I'm surprised an LED eats up so much current???
 
Cagao said:
So that's all that's stopping them all from lighting? the I/O of the pins in between don't affect? (apart from the obvious)

If the I/O pins in between are set as outputs, this will stop them being in series anyway - you would have to set them as inputs for the LED's to be in series.

it's just that the current can't get that far?

I'm surprised an LED eats up so much current???

It's NOT the current, an LED takes a certain voltage to light - roughly 2V or so, so three in series would need 6V in order to light at all.
 
The current flowing through more direct path of one led, which drops only 1.8V, would prevent other series LEDs in parallel from turn ON as they need a higher total voltage to do so. If this is the answer you want to know.

SO D11 lights and in doing so, prevent D1, D5 and D7 lights.
 

Attachments

  • LEDx.gif
    LEDx.gif
    5.4 KB · Views: 412
Last edited:
LEDs D7, D5, D1 are not in series across RA1 -> RA4?

Am I missing something? (obviously you beat me in the edit! :) )

If the I/O pins in between are set as outputs, this will stop them being in series anyway - you would have to set them as inputs for the LED's to be in series.

That bits got me. Now correct me if i'm wrong...

set 2 pins as output, one as +ve, one as -ve to get the current through them?

So any pins in between obviously want to be set as output, but as LO?
 
Cagao said:
set 2 pins as output, one as +ve, one as -ve to get the current through them?

Exactly.

Cagao said:
So any pins in between obviously want to be set as output, but as LO?

NO. They should be set as INPUT to put all unwanted LEDs *in series*.

Remember, between two points, only that one path with one LED will lights.
 
Perhaps I've had too many beers, but here's the situation...


RA4 ---+
LED (D1)
RA5 ---+
LED (D5)
RA2 ---+
LED (D7)
RA1 ---+


Setting RA1 to HI, and RA2, 5, and 4 to LO, should, in theory, pass current through all the LEDs?

I see what you're saying about setting pins to Input to 'disable' them, but if i wanted them all to light, is it simply the consumption of each LED stopping the next to light?

I think we've already decided this, but would like to be sure.

Also, why the big pull away from 'current'? surely they're eating up the current rather than the voltage? true, it's been a while since I did electronics like this, bit of a refresher course would be nice.

Thanks for all the info and help, I thought it was cos of the current/voltage that was stopping further LEDs from lighting, just been looking for the clarification.

Very much appreciated... I'll have a space-rocket built in days at this rate! :)
 
Cagao said:
Perhaps I've had too many beers, but here's the situation...


RA4 ---+
LED (D1)
RA5 ---+
LED (D5)
RA2 ---+
LED (D7)
RA1 ---+


Setting RA1 to HI, and RA2, 5, and 4 to LO, should, in theory, pass current through all the LEDs?

No, I've already explained the LED's aren't in series at all, UNLESS RA2 and RA5 are set as inputs (and still wouldn't light anyway). Your connection above connects D7 across the supply, and the other LED's nowhere.

I see what you're saying about setting pins to Input to 'disable' them, but if i wanted them all to light, is it simply the consumption of each LED stopping the next to light?

I think we've already decided this, but would like to be sure.

Also, why the big pull away from 'current'? surely they're eating up the current rather than the voltage? true, it's been a while since I did electronics like this, bit of a refresher course would be nice.

LED's aren't resistors, ohms law doesn't apply - I've already explained that you can't light three LED's in series across a 5V supply, it's too low a voltage. If you place two LED's in series then they will both blow, as you need a current limiting resistor to stop them taking enough current to destroy themselves - the PIC circuit above crudely relies on the current capability of the PIC to limit it.

Thanks for all the info and help, I thought it was cos of the current/voltage that was stopping further LEDs from lighting, just been looking for the clarification.

Very much appreciated... I'll have a space-rocket built in days at this rate! :)
 
Think I've got all the info I need for now.

I'll quit while i'm ahead, and before i receive a big slap on the back of the head. :)

Thanks again for everyones input.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top