MCF52223 Direct Port Bit setting?

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

MCF52223 Direct Port Bit setting?

1,628 Views
newguy
Contributor I
I am trying to define each ports bit so i can address them individually is there a way do to this. Here is a copy of how i initializd each port I am using:

MCF_GPIO_PUAPAR = 0
| MCF_GPIO_PUAPAR_RXD0_RXD0
| MCF_GPIO_PUAPAR_TXD0_TXD0;
///////////////////////////////////////
//Set Port TA to initialize STEP0, Dir0, Home0, Limit0
    MCF_GPIO_PTAPAR = 0x00;
    MCF_GPIO_DDRTA = 0x0C;
/////////////////////////////////////
//Set Port TC to initialize STEP1, Dir1, Home1, Limit1
    MCF_GPIO_PTCPAR = 0x00;
    MCF_GPIO_DDRTC = 0xFF;
/////////////////////////////////////////
//Set Port UC to initialize STEP2, Dir2, Home2, Limit2
    MCF_GPIO_PUCPAR = 0;
    MCF_GPIO_DDRUC = 0x0C;
///////////////////////////////////
//Set Port UB to initialize LEDs
    MCF_GPIO_PUBPAR = 0;
    MCF_GPIO_DDRUB = 0x0F;
///////////////////////////////////////
//Set Port AN to initialize Analog Inputs
    MCF_GPIO_PANPAR = 0;
    MCF_GPIO_DDRAN = 0xFF;
////////////////////////////////////////
//Set Port NQ to initialize Switch Inputs
    MCF_GPIO_PNQPAR = 0;
    MCF_GPIO_DDRNQ = 0x00;
////////////////////////////////
 
I basically want to give each bit a name for example
 
#define LED0    PORTUB pin1
 
so later i can just say LED0=1; and so on.
 
I know this is possible with other microprocessor, but i have not been successful yet
 
Thank you
 
Labels (1)
0 Kudos
3 Replies

347 Views
newguy
Contributor I
Thanks for your help guys I figured it out.  This is what I did.
 
 
#define Step0on  MCF_GPIO_PORTTA |=0x01
#define Step0off    MCF_GPIO_PORTTA &=0xFE
#define Dir0CW  MCF_GPIO_PORTTA |=0x02
#define Dir0CCW  MCF_GPIO_PORTTA &=0xFD
#define READ_PORTTA MCF_GPIO_SETTA  &= 0xFF
#define Home0  READ_PORTTA //&0x04
#define Limit0  READ_PORTTA //&0x08
 
I am very new to Freescale.
I am use to using Pic controllers.
 
 
0 Kudos

347 Views
mjbcswitzerland
Specialist V
Hi

You can get pretty close by using the following defines (example on port TC and assumed to already be set up as output).

/******************* port defines - or use ones in your BSP ********************************/
#define PORT_MODULE_ADD   (IPSBAR + 0x100000)

#define PORTIN_SETTC       *(volatile unsigned char *)(PORT_MODULE_ADD + 0x37)
#define CLEARTC                  *(unsigned char *)(PORT_MODULE_ADD + 0x4b)
/*********************************************************************************************/
#define MY_LED                        0x02                                    // TC bit 1
#define LED_PORT_SET         PORTIN_SETTC
#define LED_PORT_CLEAR    CLEARTC

To turn on LED ('1')
LED_PORT_SET = MY_LED;
To turn off LED ('0')
LED_PORT_CLEAR = MY_LED;

Regards

Mark Butcher

www.uTasker.com

0 Kudos

347 Views
bkatt
Contributor IV


mjbcswitzerland wrote:

#define MY_LED                        0x02                                    // TC bit 1
#define LED_PORT_SET         PORTIN_SETTC
#define LED_PORT_CLEAR    CLEARTC

To turn on LED ('1')
LED_PORT_SET = MY_LED;
To turn off LED ('0')
LED_PORT_CLEAR = MY_LED;


The last line would clear all bits except 0x02 ("Clearing a CLRn register clears the corresponding bits in the PORTn register. Setting it has no effect.")

I tend to define 2 (or 3) function-style macros for each port bit:

#define WIDGET_ON()     SETF=2
#define WIDGET_OFF()   CLRF=~2
#define WIDGET()            (PORTF&2)

Note that to read an input pin, you must use the SETn address:

#define SENSOR()           (SETF&4)

0 Kudos