MicroController Pros Home Page My Account  Cart Contents  Checkout  
  Store » EEDT6.0 Tutorial 2 My Account  |  Cart Contents  |  Checkout   
Quick Find
 
Enter keywords to find the product you are looking for in the Quick Find field above

or use
Advanced Search
Categories
Accessory Boards->
8051->
ADI Blackfin
Arduino->
ARM->
Atmel AVR->
Cypress PSoC
Freescale->
FTDI->
Locktronics
Microchip PIC->
MIPS
Parallax->
Renesas
Silicon Labs
ST Microelectronics->
Texas Instruments->
Tibbo->
Books->
Displays->
E-Blocks->
EEPROM/EPROM/FLASH
Embedded Ethernet->
Embedded Software->
I/O Modules->
Parts & Components->
Pick & Place Tools
Programmable Logic (PLD)
Prototype PCBs->
Robotics
ROM/Flash Emulators
Test & Measurement->
Tutorial Software
Universal Programmers->
Wireless->
Information
Intro to Embedded Tools
Embedded News Digest
Useful Resources
Shipping & Returns
Warranty & Liability
Privacy Notice
Conditions of Use
Contact Us
Writing a program to accept input from a switch

This is a tutorial for owners of the EEDT6.0 development board.

Recommended tools include the Keil MDK-ARM IDE and the included EM-P-NXP programmer with Flash Magic programming software. Usage of these was covered in the previous tutorial.


LPC2138 registers used and their configurations are as follows:

  • IOPIN — This register stores the current value of the port pin.
  • IOSET — This is an output register. Use this register to set a bit (High or 1) for a port pin.
  • IOCLR — This is an output register. Use this register to clear a bit (Low or 0) for a port pin.
  • IODIR — This is used to set the direction of the control register pin. The pin can be used as input or output. Set it to High to make the port pin as output, or clear it to zero to treat the port pin as input.


Program Details

This is a simple project for the NXP LPC21xx series. It demonstrates the source code used to accept a switch input and to indicate it by controlling an LED.

While programming, we need to use different registers such as IODIR, IOPIN, IOSET, etc. Register configuration includes direction setting (Input or Output with the help of the IODIR register).

The pins of Port 1 are used in this application. Pins P1.16 and P1.18 are connected to LED1 and LED2 respectively. Pin 1.17 is connected to the switch. This switch will generate a Low pulse when pressed.

Variables are defined inside main. The flag variable is used to remember the LED status. The directions of both of the LEDs are set using IODIR.

The first while loop monitors the switch press. The status of both LED1 and LED2 is inverted as the switch is pressed.

The program waits for the switch release with the help of the second while loop.


Sample Program

/******************************************************************************/
/* ledswitch.C: LED and Switch */

#include <lpc21xx.h> /* LPC21xx definitions */

#define LED1 0x00010000 /* Pin 1.16 is connected to LED1 */
#define LED2 0x00040000 /* Pin 1.18 is connected to LED2 */
#define SWITCH 0x00020000 /* Switch is connected at pin 1.17 */

int main(void)
{
int flag; /* flag is used for switch */

flag=1; /* switch is open */

IODIR1 = LED1 | LED2; /* LED1 and LED2 are set as output using IODIR */


while(1)
{
while(!(IOPIN1 & SWITCH)); /* defines the value to IOPIN */

if(flag==1)
{
IOSET1=LED1; /* LED1 ON */
IOCLR1=LED2; /* LED2 OFF */
}
else
{
IOSET1=LED2; /* LED2 ON */
IOCLR1=LED1; /* LED1 OFF */
}
flag=!flag; /* FLAG IS Inverted */

while((IOPIN1 & SWITCH)); /* To avoid key debouncing */
}

}


Shopping Cart more
0 items
What's New? more
Flowcode 7 for PIC, AVR, Arduino, ARM - Pro 5 User
Flowcode 7 for PIC, AVR, Arduino, ARM - Pro 5 User
US$669.00
Specials more
GSM/GPRS Module for Arduino
GSM/GPRS Module for Arduino
US$667.00
US$89.00
Bestsellers
01. RFID ISO Card Tag, 125kHz, EM4102 Read-only
02. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
03. Atmel ATtiny2313-20PU AVR Microcontroller, 20 DIP, 20 MHz
04. LCD 4-mux, 7 digits x 14 segments, progress bar, arrows
05. LCD 4-mux, 7.1 digits x 7 segments, progress bar, arrows
06. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
07. ARM JTAG Debugger & Programmer, parallel port
08. Power Supply 3-12V DC, US/UK/Euro/AU Plugs, 100-240VAC
09. Power Supply 3-12V DC, U.S. plug, 6 connection tips
10. Atmel AVR JTAG In-Circuit Debugger & Programmer, USB
Reviews more
100Mbps Ethernet to RS232 Bridge Device Server Kit w/ Enclosure
High Ethernet side not recoverable Fail rate even with Ether ..
3 of 5 Stars!
  Thursday 23 November, 2017   List of all our Products

Copyright © 2003-2017 MicroController Pros LLC
Powered by osCommerce