How to use Port P as an output pin?

View: New views
5 Messages — Rating Filter:   Alert me  

How to use Port P as an output pin?

by deniz_kerimoglu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone,

I got a simple question. I need to use port p as general purpose output, I need to take 0V or 5V output from any of pp0-pp5 pins? How can I achieve it in C?

Regards.




Re: How to use Port P as an output pin?

by justin.lucas134 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You will have to configure the DDRP (Data Directional Register P) to output.  Pending on the HC12 you are using, you will have to set the bits [0-7] of the DDRP address to logic 1.  Not sure how to do it in C, but I have seen examples in this group on how to do that.

Good Luck

Justin

--- In 68HC12@..., "deniz_kerimoglu" <deniz.kerimoglu@...> wrote:
>
> Hi everyone,
>
> I got a simple question. I need to use port p as general purpose output, I need to take 0V or 5V output from any of pp0-pp5 pins? How can I achieve it in C?
>
> Regards.
>



Re: How to use Port P as an output pin?

by Tom Almy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There will be a header file that defines the port registers which you  
use as unsigned char or in some cases unsigned short variables. What  
you would write in assembler as:

        movb #$3f DDRP
         movb data PTP

you write in C as:

        DDRP = 0x3f;
        PTP = data;



Tom Almy
Tualatin, Oregon USA
Internet: tom@...
Website: almy.us



On Sep 5, 2009, at 2:27 AM, deniz_kerimoglu wrote:

> Hi everyone,
>
> I got a simple question. I need to use port p as general purpose  
> output, I need to take 0V or 5V output from any of pp0-pp5 pins? How  
> can I achieve it in C?
>
> Regards.
>
>


RE: Re: How to use Port P as an output pin?

by jpdi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How, it's quite easy in C !!!

If you want to put all bits of port P as output, just write :
DDRP = 0xff;

And to write datas on port P :

char c;
.../...
PORTP = c;

This suppose DDRP and PORTP are defined in your include file corresponding
to your processor. For 9s12dp256 and 9s12xdp512 :

This is in the very beginning of mcçS&édp256.h
#define _IO_BASE        0
#define _ADDR(off)      (unsigned char volatile *)(_IO_BASE + off)
#define _P(off)         *(unsigned char volatile *)(_IO_BASE + off)
#define _LP(off)        *(unsigned short volatile *)(_IO_BASE + off)

.../...
And this is how the P port is defined in the same .h file :
#define PORTP   PTP
#define PTP     _P(0x0258)
.../...
#define DDRP    _P(0x025A) // Data Direction Register

That means, in fine, PORTP and DDRP are defined as below :
#define PORT *(unsigned char volatile *) 0x0258
#define DDRP *(unsigned char volatile *) 0x025A

Hope this helps.
Joel


-----Message d'origine-----
De : 68HC12@... [mailto:68HC12@...] De la part de
justin.lucas134
Envoyé : samedi 5 septembre 2009 14:26
À : 68HC12@...
Objet : [68HC12] Re: How to use Port P as an output pin?

You will have to configure the DDRP (Data Directional Register P) to output.
Pending on the HC12 you are using, you will have to set the bits [0-7] of
the DDRP address to logic 1.  Not sure how to do it in C, but I have seen
examples in this group on how to do that.

Good Luck

Justin

--- In 68HC12@..., "deniz_kerimoglu" <deniz.kerimoglu@...>
wrote:
>
> Hi everyone,
>
> I got a simple question. I need to use port p as general purpose output, I
need to take 0V or 5V output from any of pp0-pp5 pins? How can I achieve it
in C?
>
> Regards.
>




------------------------------------

Yahoo! Groups Links







Re: Re: How to use Port P as an output pin?

by deniz_kerimoglu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks everyone it works!


[Non-text portions of this message have been removed]