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.
How to use Port P as an output pin?
Started by ●September 5, 2009
Reply by ●September 5, 20092009-09-05
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 6..., "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.
>
Good Luck
Justin
--- In 6..., "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.
>
Reply by ●September 5, 20092009-09-05
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: t...@almy.us
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.
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: t...@almy.us
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.
Reply by ●September 6, 20092009-09-06
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&p256.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: 6... [mailto:6...] De la part de
justin.lucas134
Envoy samedi 5 septembre 2009 14:26
: 6...
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 6..., "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.
>
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&p256.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: 6... [mailto:6...] De la part de
justin.lucas134
Envoy samedi 5 septembre 2009 14:26
: 6...
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 6..., "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.
>
Reply by ●September 6, 20092009-09-06