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.

ARM7 GPIO and port selection

Status
Not open for further replies.

manvindar

Member level 1
Joined
Jun 10, 2012
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Banglore
Activity points
1,529
hi i am newbie for ARM Microcontrollers....

i want to know how can i select a particular pin for making it high or low

like what should i do to make port 0.22 high...

IOSET0 = 0x00FF0000 <-what should be the value for pin 0.22 and how to select any other pins

how to make a port i/p or o/p
like in this command "IODIR0 = 0x00FF0000"

and how to read a port if its a input port


thanks
 

You didn't mention the specific device but these should work

Code:
IODIR0 |=  (1UL<<22) ;  // set bit 22 of the direction register to 1, this makes P0.2 an output
IODIR0 &=  ~(1UL<<22) ;  // clear bit 22 of the direction register (set to 0), this makes P0.2 an input

//You can also set multiple pins
IODIR0 |=  (1UL<<22) | (1UL<<5) | (1UL<<10) ;   // set P0.5, P0.10, P0.22 to output

IOSET0 = (1UL<<22);  // set P0.2 high 

To read a specific bit

if (IOPIN0 & (1<<22)) {}  // true when P0.22 is high

There should also be a clear register to clear a bit
IOCLR0 = (1UL<<22); // set P0.2 low [/CODE]
 
  • Like
Reactions: pasicr

    pasicr

    Points: 2
    Helpful Answer Positive Rating
i am using lpc2129....do i need to #define something?

and how to calculate the port number like IOSET0 = 0x00001001 <-how this is calculated,,,
 

Sorry, I don't read previous post,
ARM Wiz is very useful app's (I attach for you), but your ARM model LPC2129 is not supported,
but maybe you will find some help in the future,
best regards
 

Attachments

  • ARMwizard_v1.3.rar
    855.2 KB · Views: 87

#include <LPC21xx.H>
Code:
int main()
{
  int i;
  PINSEL0=0x00000000; //port 0 set to GPIO
  IO0DIR=0x00000001; // 0th bit of port 0 will act as o/p
    while(1)
     {
      IO0SET=0x00000001;   // LED will glow
           for(i=0;i<100000;i++); //to create some delay
      IO0CLR=0x00000001; //Led will off
          for(i=0;i<100000;i++); //to create some delay
     

     }
}

what change should i make to glow pins which i desire



MOD: Please use code tags in the future
 
Last edited by a moderator:

ARM Wiz is very useful app's (I attach for you)

That version is very old, I have added several new features since then.
For the latest version (v3.3.0) download from the homepage **broken link removed**

- - - Updated - - -

Maybe your delay is small and need to increase it.

How exactly are you using the pin?
The pins can't provide much current (specs are for about 4mA) so how is the led connected?
 
  • Like
Reactions: pasicr

    pasicr

    Points: 2
    Helpful Answer Positive Rating
Code:
#include <LPC21xx.H>                       /* LPC21xx definitions */
void delay_sec(unsigned int x)
{
	T0MR0 = x;
	T0MCR = 2;	        // Clear on match
	T0PR = 0x00E4E1C0; // Prescaler for 1 sec
	T0TCR = 0x1;	   // Enable
	while(T0TC < T0MR0);  // wait till match
	T0TCR = 0x0;	   // Disable
	T0TC = 0x0;		   // Precautionally clear the counter
}

/*void delay (int value) 
{                        // Delay function 
  unsigned int cnt;
  unsigned int val;
  for(val=0;val<value;val++)
  for (cnt = 0; cnt < 1500; cnt++);         // Delay 
}*/


int main (void) 
{
  unsigned int n; 
  IODIR1 = 0x00FF0000;                     /* P1.16..23 defined as Outputs  */
  while (1) {                              /* Loop forever */
    for (n = 0x00010000; n <= 0x00800000; n <<= 1) {
      /* Blink LED 0, 1, 2, 3, 4, 5, 6, 7 */
      IOSET1 = 0x00FF0000;                          /* Turn on LED */
      delay_sec(1);                             /* Delay */
      IOCLR1 = 0x00FF0000;                 /* Turn off LEDs */
      delay_sec(1); 
    }
  }
}

this code is working and led 1.16-1.23 are glowing sequentially.....

how to change the code to glow 0.16 to 0.23

- - - Updated - - -

Code:
#include <LPC21xx.H>                       /* LPC21xx definitions */
void delay_sec(unsigned int x)
{
	T0MR0 = x;
	T0MCR = 2;	        // Clear on match
	T0PR = 0x00E4E1C0; // Prescaler for 1 sec
	T0TCR = 0x1;	   // Enable
	while(T0TC < T0MR0);  // wait till match
	T0TCR = 0x0;	   // Disable
	T0TC = 0x0;		   // Precautionally clear the counter
}

/*void delay (int value) 
{                        // Delay function 
  unsigned int cnt;
  unsigned int val;
  for(val=0;val<value;val++)
  for (cnt = 0; cnt < 1500; cnt++);         // Delay 
}*/


int main (void) 
{
  unsigned int n; 
  IODIR1 = 0x00FF0000;                     /* P1.16..23 defined as Outputs  */
  while (1) {                              /* Loop forever */
    for (n = 0x00010000; n <= 0x00800000; n <<= 1) {
      /* Blink LED 0, 1, 2, 3, 4, 5, 6, 7 */
      IOSET1 = 0x00FF0000;                          /* Turn on LED */
      delay_sec(1);                             /* Delay */
      IOCLR1 = 0x00FF0000;                 /* Turn off LEDs */
      delay_sec(1); 
    }
  }
}

this code is working and led 1.16-1.23 are glowing sequentially.....

how to change the code to glow 0.16 to 0.23
 

Replace the port direction and pin registers with the ones for port 0.

IODIR1, IOSET1 , IOCLR1 should be replaced
 
  • Like
Reactions: pasicr

    pasicr

    Points: 2
    Helpful Answer Positive Rating
not working i changed IODIR1, IOSET1 , IOCLR1 to IODIR0, IOSET0 , IOCLR0 but still cant glow pins 0.16-0.22

- - - Updated - - -

not working i changed IODIR1, IOSET1 , IOCLR1 to IODIR0, IOSET0 , IOCLR0 but still cant glow pins 0.16-0.22
 

there is no other change needed in the code so something else must be wrong.
Did you actually try the original code and was blinking the leds?
 

yes it was working both on board and proteus

but its not working for port 0
 

I have just tested the following code in the uvision simulator and works fine toggling the pins, there must be something else going wrong with your circuit
Code:
#include <LPC21xx.H>                       /* LPC21xx definitions */

void delay_sec(unsigned int x)
{
	T0MR0 = x;
	T0MCR = 2;	        // Clear on match
	T0PR = 0x00E4E1C0; // Prescaler for 1 sec
	T0TCR = 0x1;	   // Enable
	while(T0TC < T0MR0);  // wait till match
	T0TCR = 0x0;	   // Disable
	T0TC = 0x0;		   // Precautionally clear the counter
}

/*void delay (int value) 
{                        // Delay function 
  unsigned int cnt;
  unsigned int val;
  for(val=0;val<value;val++)
  for (cnt = 0; cnt < 1500; cnt++);         // Delay 
}*/


int main (void) 
{
  unsigned int n; 
  IODIR0 = 0x00FF0000;                     /* P1.16..23 defined as Outputs  */
  while (1) {                              /* Loop forever */
    for (n = 0x00010000; n <= 0x00800000; n <<= 1) {
      /* Blink LED 0, 1, 2, 3, 4, 5, 6, 7 */
      IOSET0 = 0x00FF0000;                          /* Turn on LED */
      delay_sec(1);                             /* Delay */
      IOCLR0 = 0x00FF0000;                 /* Turn off LEDs */
      delay_sec(1); 
    }
  }
}
 

thank you sir...i had given IOSET0 = 0x00000001 instead of IOSET0 = 0x00FF0000...

sir can you tell me what this 0x00FF0000 means...
like if i want to monitor a port in controller..lets say a switch is connected to it...
then how will i calculate the number "0xZZZZZZZZ" for the port which i want to monitor.....

and can you explain the for loop of the above program...

thanks in advance
 

0x00FF0000 is a 32bit value written in the hexadecimal format

If you use a converted (like a calculator) to make it a binary value you will get 0b00000000111111110000000000000000

Here is a conversion table https://ascii.cl/conversion.htm

Basically you only need to learn values 0-F which represent 0 - 15 decimal or 0b0000 - 0b1111 , then you can convert any binary or a binary to hex.

From right to left each bit represents one pin of the port
Code:
P0.0     0b0000000011111111000000000000000[COLOR="#FF0000"]0[/COLOR]
P0.1     0b000000001111111100000000000000[COLOR="#FF0000"]0[/COLOR]0
P0.2     0b00000000111111110000000000000[COLOR="#FF0000"]0[/COLOR]00
...
P0.16    0b000000001111111[COLOR="#FF0000"]1[/COLOR]0000000000000000
P0.17    0b00000000111111[COLOR="#FF0000"]1[/COLOR]10000000000000000
...
P0.23    0b00000000[COLOR="#FF0000"]1[/COLOR]11111110000000000000000

In hexadecimal each digit represents four bits

Code:
P0.3:P0.0     0x00FF000[COLOR="#FF0000"]0[/COLOR]
P0.7:P0.4     0x00FF00[COLOR="#FF0000"]0[/COLOR]0
P0.11:P0.8    0x00FF0[COLOR="#FF0000"]0[/COLOR]00
P0.15:P0.12   0x00FF[COLOR="#FF0000"]0[/COLOR]000
P0.19:P0.16   0x00F[COLOR="#FF0000"]F[/COLOR]0000
P0.123:P0.20  0x00[COLOR="#FF0000"]F[/COLOR]F0000

You can also use what I described in post #2
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top