Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

make programming easy by using structures

Status
Not open for further replies.

h.galeh

Member level 3
Member level 3
Joined
Apr 16, 2008
Messages
66
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Tehran, Iran, Iran
Visit site
Activity points
1,690
most of the times we need to work with specified bits of registers . most of the times I see in examples the use of masking
its an unreadable way . now see the form below:
masking for setting GPIO2.1 as output
Code:
LPC_GPIO2->FIODIR |= 0x2;
equivalent of the form above with structures
Code:
#include "myGPIO.h"
GPIO2->DIR1 = 1; // more readable
you see its really more readable and convenient. now add its library
Code:
typedef struct
{
  union {
    __IO uint32_t FIODIR;
    struct {
      __IO uint16_t FIODIRL;
      __IO uint16_t FIODIRH;
    };
    struct {
      __IO uint8_t  FIODIR0;
      __IO uint8_t  FIODIR1;
      __IO uint8_t  FIODIR2;
      __IO uint8_t  FIODIR3;
    };
    struct{
      unsigned DIR0:1;
      unsigned DIR1:1;
      unsigned DIR2:1;
      unsigned DIR3:1;
      unsigned DIR4:1;
      unsigned DIR5:1;
      unsigned DIR6:1;
      unsigned DIR7:1;
      unsigned DIR8:1;
      unsigned DIR9:1;
      unsigned DIR10:1;
      unsigned DIR11:1;
      unsigned DIR12:1;
      unsigned DIR13:1;
      unsigned DIR14:1;
      unsigned DIR15:1;
      unsigned DIR16:1;
      unsigned DIR17:1;
      unsigned DIR18:1;
      unsigned DIR19:1;
      unsigned DIR20:1;
      unsigned DIR21:1;
      unsigned DIR22:1;
      unsigned DIR23:1;
      unsigned DIR24:1;
      unsigned DIR25:1;
      unsigned DIR26:1;
      unsigned DIR27:1;
      unsigned DIR28:1;
      unsigned DIR29:1;
      unsigned DIR30:1;
      unsigned DIR31:1;
    };
  };
  uint32_t RESERVED0[3];
  union {
    __IO uint32_t FIOMASK;
    struct {
      __IO uint16_t FIOMASKL;
      __IO uint16_t FIOMASKH;
    };
    struct {
      __IO uint8_t  FIOMASK0;
      __IO uint8_t  FIOMASK1;
      __IO uint8_t  FIOMASK2;
      __IO uint8_t  FIOMASK3;
    };
        struct{
      unsigned MASK0:1;
      unsigned MASK1:1;
      unsigned MASK2:1;
      unsigned MASK3:1;
      unsigned MASK4:1;
      unsigned MASK5:1;
      unsigned MASK6:1;
      unsigned MASK7:1;
      unsigned MASK8:1;
      unsigned MASK9:1;
      unsigned MASK10:1;
      unsigned MASK11:1;
      unsigned MASK12:1;
      unsigned MASK13:1;
      unsigned MASK14:1;
      unsigned MASK15:1;
      unsigned MASK16:1;
      unsigned MASK17:1;
      unsigned MASK18:1;
      unsigned MASK19:1;
      unsigned MASK20:1;
      unsigned MASK21:1;
      unsigned MASK22:1;
      unsigned MASK23:1;
      unsigned MASK24:1;
      unsigned MASK25:1;
      unsigned MASK26:1;
      unsigned MASK27:1;
      unsigned MASK28:1;
      unsigned MASK29:1;
      unsigned MASK30:1;
      unsigned MASK31:1;
    };
  };
  union {
    __IO uint32_t FIOPIN;
    struct {
      __IO uint16_t FIOPINL;
      __IO uint16_t FIOPINH;
    };
    struct {
      __IO uint8_t  FIOPIN0;
      __IO uint8_t  FIOPIN1;
      __IO uint8_t  FIOPIN2;
      __IO uint8_t  FIOPIN3;
    };
        struct{
      unsigned PIN0:1;
      unsigned PIN1:1;
      unsigned PIN2:1;
      unsigned PIN3:1;
      unsigned PIN4:1;
      unsigned PIN5:1;
      unsigned PIN6:1;
      unsigned PIN7:1;
      unsigned PIN8:1;
      unsigned PIN9:1;
      unsigned PIN10:1;
      unsigned PIN11:1;
      unsigned PIN12:1;
      unsigned PIN13:1;
      unsigned PIN14:1;
      unsigned PIN15:1;
      unsigned PIN16:1;
      unsigned PIN17:1;
      unsigned PIN18:1;
      unsigned PIN19:1;
      unsigned PIN20:1;
      unsigned PIN21:1;
      unsigned PIN22:1;
      unsigned PIN23:1;
      unsigned PIN24:1;
      unsigned PIN25:1;
      unsigned PIN26:1;
      unsigned PIN27:1;
      unsigned PIN28:1;
      unsigned PIN29:1;
      unsigned PIN30:1;
      unsigned PIN31:1;
    };
  };
  union {
    __IO uint32_t FIOSET;
    struct {
      __IO uint16_t FIOSETL;
      __IO uint16_t FIOSETH;
    };
    struct {
      __IO uint8_t  FIOSET0;
      __IO uint8_t  FIOSET1;
      __IO uint8_t  FIOSET2;
      __IO uint8_t  FIOSET3;
    };
        struct{
      unsigned SET0:1;
      unsigned SET1:1;
      unsigned SET2:1;
      unsigned SET3:1;
      unsigned SET4:1;
      unsigned SET5:1;
      unsigned SET6:1;
      unsigned SET7:1;
      unsigned SET8:1;
      unsigned SET9:1;
      unsigned SET10:1;
      unsigned SET11:1;
      unsigned SET12:1;
      unsigned SET13:1;
      unsigned SET14:1;
      unsigned SET15:1;
      unsigned SET16:1;
      unsigned SET17:1;
      unsigned SET18:1;
      unsigned SET19:1;
      unsigned SET20:1;
      unsigned SET21:1;
      unsigned SET22:1;
      unsigned SET23:1;
      unsigned SET24:1;
      unsigned SET25:1;
      unsigned SET26:1;
      unsigned SET27:1;
      unsigned SET28:1;
      unsigned SET29:1;
      unsigned SET30:1;
      unsigned SET31:1;
    };
  };
  union {
    __O  uint32_t FIOCLR;
    struct {
      __O  uint16_t FIOCLRL;
      __O  uint16_t FIOCLRH;
    };
    struct {
      __O  uint8_t  FIOCLR0;
      __O  uint8_t  FIOCLR1;
      __O  uint8_t  FIOCLR2;
      __O  uint8_t  FIOCLR3;
    };
        struct{
      unsigned CLR0:1;
      unsigned CLR1:1;
      unsigned CLR2:1;
      unsigned CLR3:1;
      unsigned CLR4:1;
      unsigned CLR5:1;
      unsigned CLR6:1;
      unsigned CLR7:1;
      unsigned CLR8:1;
      unsigned CLR9:1;
      unsigned CLR10:1;
      unsigned CLR11:1;
      unsigned CLR12:1;
      unsigned CLR13:1;
      unsigned CLR14:1;
      unsigned CLR15:1;
      unsigned CLR16:1;
      unsigned CLR17:1;
      unsigned CLR18:1;
      unsigned CLR19:1;
      unsigned CLR20:1;
      unsigned CLR21:1;
      unsigned CLR22:1;
      unsigned CLR23:1;
      unsigned CLR24:1;
      unsigned CLR25:1;
      unsigned CLR26:1;
      unsigned CLR27:1;
      unsigned CLR28:1;
      unsigned CLR29:1;
      unsigned CLR30:1;
      unsigned CLR31:1;
    };
  };
} defLPC_GPIO;

#define GPIO2             ((defLPC_GPIO      *) LPC_GPIO2_BASE    )
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top