Discussion in "ARM Development" started by    shyam    Dec 23, 2007.
Sun Dec 23 2007, 04:06 pm
#1
consider the following example replace wait() with any delay routine....

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, 04:19 pm ]
Sun Dec 23 2007, 04:11 pm
#2

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....
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, 04:21 pm ]
Sat Dec 29 2007, 12:30 am
#3
further discussion will be over here..
http://www.8051projects.net/forum-t4128.html
 Technophile like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

RobertGug
Tue Jun 18 2024, 04:38 pm
Jasonabepe
Tue Jun 18 2024, 04:24 pm
Thomcyday
Tue Jun 18 2024, 08:38 am
WalterWib
Tue Jun 18 2024, 05:44 am
SialisshopWat
Mon Jun 17 2024, 09:22 pm
Thomasraima
Mon Jun 17 2024, 07:17 pm
EriksaLaf
Mon Jun 17 2024, 03:13 pm
Anthonyjinee
Mon Jun 17 2024, 06:23 am