free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes :: Forums :: Discuss and Learn :: ARM Development
 
<< Previous thread | Next thread >>
ARM-7TDMI tutorial - Working with GPIOs (LPC21xx)
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
This thread is now closed
Author Post
shyam
Sun Dec 23 2007, 02:36AM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 723
Thanked 107 times in 103 posts
consider the following example replace wait() with any delay routine....

CODE:
int main (void)  
{
  unsigned int j;                /* LED var */

  IODIR1 = 0xFF0000;    /* P1.16..23 defined as Outputs */

  init_timer();

 while (1)  
{                                      /* Loop forever */
    for (j = 0x010000; j < 0x800000; j <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */
      IOSET1 = j;                                                   /* Turn on LED */
      wait ();                                                          /* call wait function */
      IOCLR1 = j;                                                  /* Turn off LED */
    }
    for (j = 0x800000; j > 0x010000; j >>=1 ) { /* Blink LED 7,6,5,4,3,2,1 */
      IOSET1 = j;                                                    /* Turn on LED */
      wait ();                                                           /* call wait function */
      IOCLR1 = j;                                                   /* Turn off LED */
    }
  }
}



this is a very simple code but tells the main differences between 51 and arm.....



[ Edited Sun Dec 23 2007, 02:49AM ]

lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


shyam
Sun Dec 23 2007, 02:41AM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 723
Thanked 107 times in 103 posts
Important for reading:
just download lpc2148 usermanual user.manual.lpc2141.lpc2142.lpc2144.lpc2146.lpc2148.pdf
n
lpc-arm-book_srn.pdf


IOSETx
x can be 0 1 ur choice of port

GPIO Port Output Set register. This register
controls the state of output pins in
conjunction with the IOCLR register. Writing
ones produces highs at the corresponding
port pins. Writing zeroes has no effect.

IOCLR GPIO Port Output Clear register. This
register controls the state of output pins.
Writing ones produces lows at the
corresponding port pins and clears the
corresponding bits in the IOSET register.
Writing zeroes has no effect.



IOSET n IOCLR are both 32 bit registers....

the above code snippet says value of j will be sent to IOSET now in the IOSET register wherever there is a 1 there will be a high on the corresponding bit of the corresponding port...

ex.
IOSET1 =0x01 => P1.0 is high
IOSET1 = 0x02 => P1.1 high
IOSET1 = 0x03 => P1.0 and P1.1 are high
IOSET1 = 0x80000000 => P1.31 high ...........

important point.......

suppose the following sequence

IOSET1=0x01;
IOSET1 =0x00;

what is the output??

P1.1 is still high because Writing zeroes has no effect.

-----------------------------------------------------

all this while we have been trying to use IOs as output pins......

but we require them as inputs too.....

this is where IOPIN comes in

IOPIN ==> GPIO Port Pin value register. The current
state of the GPIO configured port pins can
always be read from this register, regardless
of pin direction.

thus consider the sequence....
CODE:
IODIR1 =0xFF;
IOSET1 = 0x0F;
IOCLR1 = 0x02;
Int_Buffer = IOPIN1;

value of Int_Buffer = 0x0D...

imp note =>

IODIR1 =0xFF;
=> P1.0 - P1.7 has been configured as output pins......
we can not take input at these input...

thus look again at the above stated sequence...

now if i have a press-2-on switch on pin P1.0... can i read the status????


no....

the IOPIN1 will still return 0x0D..

there fore the IODIR1 shud be written
IODIR1 = 0xFE;

Points to remember.....

  1. status of port pins can only be read thru IOPIN register.....
  2. IODIR has a default value of 0x00 so by default port pins are configured as input.
  3. change in IOSET register has no effect on IOCLR and vice versa..
  4. IODIR IOSET IOCLR IOPIN are all individual 32 bit registers..
  5. a pin once configured as output can not be used as input unless the value of corresponding IODIR register is changed.
  6. ports in LPC/arm are not bit addressable!!

this is all about writing to a pin and reading from pins

next we will discuss the PINSEL register....

[ Edited Sun Dec 23 2007, 02:51AM ]

lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


Ajay
Fri Dec 28 2007, 11:00AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3757
Thanked 697 times in 656 posts
further discussion will be over here..
http://www.8051projects.net/forum-t4128.html

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems