LPC2138 Pins - HEX

for example we set up a pin:

void RD(char stat)

{

IODIR0 |= 0x00040000; // RD is P0.18

if (stat)

IOSET0 |= 0x00040000;

else

IOCLR0 |= 0x00040000;

}

My question is:

how do i know that 0x00040000 is pin 18?

fgcity:
for example we set up a pin:

void RD(char stat)

{

IODIR0 |= 0x00040000; // RD is P0.18

if (stat)

IOSET0 |= 0x00040000;

else

IOCLR0 |= 0x00040000;

}

My question is:

how do i know that 0x00040000 is pin 18?

0x00040000 = 0100 0000 0000 0000 0000

The 1 is at the bit 18 position (P0.18). It’s not necessarily pin 18!

Leon

ok, then if i wanted to make pin 31 High what would the code be?

fgcity:
ok, then if i wanted to make pin 31 High what would the code be?

0x80000000

Leon

why is it like that and how do i figure this out by my selve?

fgcity:
why is it like that and how do i figure this out by my selve?

Just convert it to binary and count the bits from the LS bit (bit 0).

Leon

i have added the code to enable P31 to high and i don’t know why but what i was doing just became normal.

I was trying to preview an image on the CFAX LCD and it was kinda disorted.

By enabling the pin31 to high i was hoping to enable the backlight of the screen.

here is my post.

http://www.sparkfun.com/cgi-bin/phpbb/v … php?t=2995

if you can please reply to it.

Is P0.31 actually going high? If it is, you must have something wrong with the display, or it hasn’t got a backlight.

Leon

there can’t be something wrong with the display and it has a backlight.(it’s the CFAX LCD with the CFAX header board from Sparkfun)

The thing is that i don’t know what is the opereation on thecercuit of the backlight. But i am assuming by enabling the pin to high the light will turn on.

the code that i used to enable the pin 31 to high is:

////////////////

BL_ON(0); // Pin 31 is high

void BL_ON(char stat)

// BLON is P0.31

{

IODIR0 |= 0x80000000;

if (stat)

IOSET0 |= 0x80000000;

else

IOCLR0 |= 0x80000000;

}

/////////////

is this correct?

There is a much simpler way :-

void RD(char stat)
{
   IODIR0 |= (1 << 18); // RD is P0.18
   if (stat)
      IOSET0 |= (1 << 18);
   else
      IOCLR0 |= (1 << 18);
}

or even better

#define BIT18 (1 << 18)
void RD(char stat)
{
   IODIR0 |= BIT18; // RD is P0.18
   if (stat)
      IOSET0 |= BIT18;
   else
      IOCLR0 |= BIT18;
}

There you go, now you can see why it is 18.

so if i want to make pin 31 high i do the following?

#define BIT18 (1 << 31)

void RD(char stat)

{

IODIR0 |= BIT31; // RD is P0.31

if (stat)

IOSET0 |= BIT31;

else

IOCLR0 |= BIT31;

}

RD(0); //Pin 31 high

is this correct?

the way i do it is i put the following in a header file.

//bits

#define BIT0 0x00000001

#define BIT1 0x00000002

#define BIT2 0x00000004

#define BIT3 0x00000008

#define BIT4 0x00000010

#define BIT5 0x00000020

#define BIT6 0x00000040

#define BIT7 0x00000080

#define BIT8 0x00000100

#define BIT9 0x00000200

#define BIT10 0x00000400

#define BIT11 0x00000800

#define BIT12 0x00001000

#define BIT13 0x00002000

#define BIT14 0x00004000

#define BIT15 0x00008000

#define BIT16 0x00010000

#define BIT17 0x00020000

#define BIT18 0x00040000

#define BIT19 0x00080000

#define BIT20 0x00100000

#define BIT21 0x00200000

#define BIT22 0x00400000

#define BIT23 0x00800000

#define BIT24 0x01000000

#define BIT25 0x02000000

#define BIT26 0x04000000

#define BIT27 0x08000000

#define BIT28 0x10000000

#define BIT29 0x20000000

#define BIT30 0x40000000

#define BIT31 0x80000000

ok, i get it now.

Tnx for the help guys

sorry but ones again.

Lets say i want to make pin 2 high.

How do i know that 0x00000002 is pin one? and where does it say that

Just convert it to binary and count the bits from the LS bit (bit 0).

?

where is the LS bit? what is it?

could i find all this in one documentation to get familiar with it?

Is it the same with all the Microcontrollers? i mean would it be the same for a PIC micro?