This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM LPC2129..how to assign port pin as input pin

Dear sir,

herewith i attach my program for your reference, if any one knows the solutions plz kindly provides some help for me.

My programs is to assign LPC2129 Port P1's any of the pin is input, when the pin is high, it gives beep sound, otherwise sends character 'A' to serial port.

my doubt is how to assign port1 as input pin,

Program
-------
#include <LPC21XX.H>

unsigned int delay;

void init_serial (void);
void delay1(void);
void alert(void);

//Delay Routine
//---------------------
void delay1(void)
{

for(delay = 0;delay<0xA0000;delay++)//simple delay loop

{;}

}

//Alert Function
//---------------------
void alert(void)
{

IOSET1 = 0x00010000;

delay1();

IOCLR1 = 0x00010000;

delay1();

}

//Initialize serial
//---------------------
void init_serial (void)
{

PINSEL0 = 0x00050000; /* Enable RXD1 TxD1 */

U1LCR = 0x00000083; /*8 bits, 1 Stop bit */

U1DLL = 0x000000C2; /*9600 Baud Rate @12MHz VPB Clock */

U1LCR = 0x00000003; /* DLAB=0*/

}

//Main program starts
//---------------------
int main (void)
{

PINSEL0 = 0;

PINSEL1 = 0;

PINSEL2 &= 0x0000000C;

VPBDIV = 0x02; //Divide Pclk by two

IODIR1 = 0x00000000; // set all pin to input

init_serial();

while (1)

{

if(IOSET1==0X02000000) //check P1.25 is high

alert(); //call alert function

else

U1THR = 'A'; //send 'A' char to serial port

}
}

Parents
  • Hi, this is an example project from WinArm. hope help you

    //////////////////////////////////////////////////////////////////////////////
    //
    // Philips LPC2129 ARM7TDMI LED/Switch Example
    //
    // This example demonstrates writing to and reading from
    // the GPIO port.
    // (1) flash the LED 10 times
    // (2) wait for key-press, turn off LED if key is pressed
    //
    // WinARM example by Martin THOMAS, Kaiserslautern, Germany
    // (eversmith@heizung-thomas.de)
    // www.siwawi.arubi.uni-kl.de/avr_projects
    //////////////////////////////////////////////////////////////////////////////
    
    
    
    
    /*                                      Modificado para la tarjeta Olimex LPC-E2129
     *
     */
    
    #include "lpc21xx_keil.h"
    
    // olimex LPC-P2129: buttons on P0.10/P0.11 (active low)
    #define BUT1PIN         15
    #define BUT2PIN         9
    // olimex LPC-P2129: LEDs on P0.12/P0.13 (active low)
    #define LED1PIN         8
    #define LED2PIN         10
    
    static void delay(void )
    {
            volatile int i,j;
    
            for (i=0;i<100;i++)
                    for (j=0;j<1001;j++);
    }
    
    int main(void)
    {
            int i;
    
            MAMCR = 2;      // MAM functions fully enabled
    
            IODIR0 |= (1<<LED1PIN)|(1<<LED2PIN); // define LED-Pins as outputs
            IOSET0 = (1<<LED1PIN)|(1<<LED2PIN); // set Bits = LEDs off (active low)
            IODIR0 &= ~((1<<BUT1PIN)|(1<<BUT2PIN));// define Button-Pins as inputs
    
            i=0;
            while (i<5){
    
                    IOCLR0 = (1<<LED1PIN);
                    IOSET0 = (1<<LED2PIN);
                    delay();
                    IOSET0 = (1<<LED1PIN);
                    IOCLR0 = (1<<LED2PIN);
                    delay();
                    i++;
    
            }
    
            while (1)
            {
                    if (IOPIN0 & (1<<BUT1PIN))    { // true if button released (active low)
                            IOCLR0 = (1<<LED1PIN);            // clear I/O bit -> LED on (active low)
                    }
                    else {
                            IOSET0 = (1<<LED1PIN);            // set I/O bit -> LED off (active low)
                    }
    
                    if (IOPIN0 & (1<<BUT2PIN))    { // true if button released (active low)
                            IOCLR0 = (1<<LED2PIN);            // clear I/O bit -> LED on (active low)
                    }
                    else {
                            IOSET0 = (1<<LED2PIN);            // set I/O bit -> LED off (active low)
                    }
            }
    
            return 0; // never reached
    }
    

Reply
  • Hi, this is an example project from WinArm. hope help you

    //////////////////////////////////////////////////////////////////////////////
    //
    // Philips LPC2129 ARM7TDMI LED/Switch Example
    //
    // This example demonstrates writing to and reading from
    // the GPIO port.
    // (1) flash the LED 10 times
    // (2) wait for key-press, turn off LED if key is pressed
    //
    // WinARM example by Martin THOMAS, Kaiserslautern, Germany
    // (eversmith@heizung-thomas.de)
    // www.siwawi.arubi.uni-kl.de/avr_projects
    //////////////////////////////////////////////////////////////////////////////
    
    
    
    
    /*                                      Modificado para la tarjeta Olimex LPC-E2129
     *
     */
    
    #include "lpc21xx_keil.h"
    
    // olimex LPC-P2129: buttons on P0.10/P0.11 (active low)
    #define BUT1PIN         15
    #define BUT2PIN         9
    // olimex LPC-P2129: LEDs on P0.12/P0.13 (active low)
    #define LED1PIN         8
    #define LED2PIN         10
    
    static void delay(void )
    {
            volatile int i,j;
    
            for (i=0;i<100;i++)
                    for (j=0;j<1001;j++);
    }
    
    int main(void)
    {
            int i;
    
            MAMCR = 2;      // MAM functions fully enabled
    
            IODIR0 |= (1<<LED1PIN)|(1<<LED2PIN); // define LED-Pins as outputs
            IOSET0 = (1<<LED1PIN)|(1<<LED2PIN); // set Bits = LEDs off (active low)
            IODIR0 &= ~((1<<BUT1PIN)|(1<<BUT2PIN));// define Button-Pins as inputs
    
            i=0;
            while (i<5){
    
                    IOCLR0 = (1<<LED1PIN);
                    IOSET0 = (1<<LED2PIN);
                    delay();
                    IOSET0 = (1<<LED1PIN);
                    IOCLR0 = (1<<LED2PIN);
                    delay();
                    i++;
    
            }
    
            while (1)
            {
                    if (IOPIN0 & (1<<BUT1PIN))    { // true if button released (active low)
                            IOCLR0 = (1<<LED1PIN);            // clear I/O bit -> LED on (active low)
                    }
                    else {
                            IOSET0 = (1<<LED1PIN);            // set I/O bit -> LED off (active low)
                    }
    
                    if (IOPIN0 & (1<<BUT2PIN))    { // true if button released (active low)
                            IOCLR0 = (1<<LED2PIN);            // clear I/O bit -> LED on (active low)
                    }
                    else {
                            IOSET0 = (1<<LED2PIN);            // set I/O bit -> LED off (active low)
                    }
            }
    
            return 0; // never reached
    }
    

Children
No data