GPIO pins for input and output to LED circuit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPIO pins for input and output to LED circuit

2,014 Views
SyaZ
Contributor I

Greetings all.

 

I am using MC9S08GT60 MCU and from the manual I understand that there are lots of pins that I can use as GPIO if I don't use their intended function.

 

What I'm trying to do is, connect the GPIO to a custom built circuit with relays and LEDs (those will represent devices that I want to control remotely) so my question is, how do I give output and receive input from the circuit with GPIO? Is it as simple as directly connecting the pin to a demultiplexer on the LED circuit assuming there will be volt emitted when output pin is set to high?

 

I'd appreciate on any advice.

 

Thanks in advance.

Labels (1)
0 Kudos
3 Replies

708 Views
Joel69003
Contributor IV

Hi Ahmad,

Yes, GPIOs can drive some LED directly and relays using some transistors. See the attachments. You only have to take care to the Electrical Characteristics of the MCU (see datasheet - the total current supplied by all the pins of the MCU is limited).

Regarding the program, I think you are just beginning with this kind of devices. Thus I recommend you to use CodeWarrior and to write in C language, not in assembly like shown by Ross.

Here are some few lines of code, with a LED connected on pin PTA0 (for example):

/* Initialize pin as output, set low (LED is switched OFF) */

PTAD_PTAD0 = 0;

PTADD_PTADD0 = 1;

/* Set pin hight (LED is switched ON) */

PTAD_PTAD0 = 1;

/* Set pin low (LED is switched OFF) */

PTAD_PTAD0 = 0;

Enjoy !

Regards,

Joel Guittet


0 Kudos

708 Views
Bloodhound
Contributor I

I've never been a fan of connecting CPU pins directly to the outside world.

If your design is budget conscious then you might have no choice, but something like a logic FET's are very nice for driving LED's, I've used BSS138's in many projects.

The CPU ports turn on the BSS138 by driving the port pin high (set the Port direction as an output, then change port state to 1).

 

Eg - 

mov   #%00000000,PORTB   ; Set up Port B values before changing to output.

mov   #%11111111,DDRB    ; Set up Port B Data Direction values (1=Outputs).

bset  1,PORTB            ; Turn on Bit 1 of Port B   

bclr  1,PORTB            ; Turn off Bit 1 of Port B    

 

The above sets all of PORTB as an output with the default state of off '0'.

To turn on the output you 'bset' the bit you want on and bclr to turn it off.

 

For inputs it depends on what voltage you are using, if a 12V input then at minimum you need a resistive divider and change the DDR register to be used as inputs.

The Reference manual for the HC08's covers port configuration commands.

 

Note, I have not used the MC9S08GT60 so I don't know if the same rules apply.

 

Cheers,
Ross

Message Edited by Bloodhound on 2009-03-22 11:37 PM
0 Kudos

708 Views
victorrod
Contributor I

Hello

I am using Kinetis KLO M0 family as requirement and I have to drive a relay that is supplying 277VAC @ 5A to the load.

I also need to be turning it ON and OFF every 9 seconds.

I am wondering which micro controller outputs should I be using? ( like you mention GPIO here)

I can design the power conversion needed, but I am not much

familiar with Microcontroller.

Thanks

0 Kudos