We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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;
//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
} }
At a first glace I would say it does not make much sense to read IOSET in the line if(IOSET1==0X02000000) //check P1.25 is high as it does not read the state of the input pin. Try register IOPIN instead.
hi, tried IoPIn also, kindly suggest or change some modification on my code or just give me sample code for set ARM port1 as input port.
thanks....
If You want all pins to be input pins set bit 2 and 3 in PINSEL2 to zero. So instead of
use
PINSEL2 &= ~0x0000000C;
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 }