LPC1766 GPIO Inputs and Outputs

Publisher:黄金大花猫Latest update time:2015-05-11 Source: 51heiKeywords:LPC1766  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I played around with STM32 some time ago and it was good. It has rich resources and functions and is easy to use. It is not at the same level as 51. After using it, I decided to use an embedded MCU with RAM-M3 core. The only drawback is that the firmware library of STM32 is not easy to use. I started by directly operating the registers (the influence of 51). But I also found that the external modules of STM32 are very difficult to operate, especially I2C, which is simply unusable.

Today I got LPC1766, and compared it with STM32, LPC is more suitable for direct register operation. Today's learning results are as follows (based on Zhou Ligong's LPC1766 board):

/****************************************Copyright (c)***** ***********************************************
** Guangzhou ZLGMCU Development Co., LTD
**--------------File Info-------------------------- -------------------------------------------------- -----
** File name: main.c
** Last modified Date: 2010-09-28
** Last Version: V1.0
** Descriptions: The main() function example template
**
**--- -------------------------------------------------- -------------------------------------------------- -
** Created by: Lan wuqiang
** Created date: 2010-09-28
** Version: V1.00
** Descriptions: Organize templates, add user applications
**
**---------- -------------------------------------------------- -----------------------------------------------
** Modified by:        
* * Modified date:      
** Version:            
** Descriptions:       
**
**---------------------------------- -------------------------------------------------- --------------------
** Modified by:       
** Modified date:     
** Version:           
** Descriptions:      
**
** Rechecked by:
***** *************************************************** *************************************************** /
#include "LPC17xx.h" /* LPC17xx peripheral registers */

/*************************************************************************************************************
  Variables and macro definitions
****************************************************************************************/
#define BEEP (1 << 11) /* P0.11 is connected to the buzzer */
#define KEY1 (LPC_GPIO2->FIOPIN & (1 << 10)) /* P2.10 is connected to KEY1 */
#define KEY2 (LPC_GPIO2->FIOPIN & (1 << 11)) /* P2.11 is connected to KEY2 */  
#define KEY3 (LPC_GPIO2->FIOPIN & (1 << 12)) /* P2.12 is connected to KEY3 */
#define KEY4 (LPC_GPIO2->FIOPIN & (1 << 13)) /* P2.13 is connected to KEY4 */

#define BEEPOFF() LPC_GPIO0->FIODIR |= BEEP;LPC_GPIO0->FIOSET |= BEEP /* Buzzer off */
#define BEEPON() LPC_GPIO0->FIODIR |= BEEP;LPC_GPIO0->FIOCLR |= BEEP /* Buzzer on */
#define LED1 (1 << 0) /* P2.0 connects to LED1 */
#define LED2 (1 << 1) /* P2.1 connects to LED2 */
#define LED3 (1 << 2) /* P2.2 connects to LED3 */
#define LED4 (1 << 3) /* P2.3 connects to LED4 */
#define LED1OFF() LPC_GPIO2->FIODIR |= LED1;LPC_GPIO2->FIOSET |= LED1 /* LED1 off */
#define LED1ON() LPC_GPIO2->FIODIR |= LED1;LPC_GPIO2->FIOCLR |= LED1 /* LED1 on */
#define LED2OFF() LPC_GPIO2->FIODIR |= LED2;LPC_GPIO2->FIOSET |= LED2 /* LED2 off */
#define LED2ON() LPC_GPIO2->FIODIR |= LED2;LPC_GPIO2->FIOCLR |= LED 2 /* LED2 on */
#define LED3OFF() LPC_GPIO2->FIODIR |= LED3;LPC_GPIO2->FIOSET |= LED3 /* LED1 off */
#define LED3ON() LPC_GPIO2->FIODIR |= LED3;LPC_GPIO2->FIOCLR |= LED3 /* LED1 on */
#define LED4OFF() LPC_GPIO2->FIODIR |= LED 4;LPC_GPIO2->FIOSET |= LED4 /* LED2 is off */
#define LED4ON() LPC_GPIO2->FIODIR |= LED4;LPC_GPIO2->FIOCLR |= LED4 /* LED2 is on */


/*************************************************************************************************************
** Function name: GPIOInit
** Descriptions: GPIO initialization
** Input parameters: None
** Output parameters: None
** Returned value: None
**************************************************************************************************/
void GPIOInit (void)
{
    LPC_PINCON->PINSEL0 &= ~(0x03 << 22); /* Configure P0.11 as GPIO */
    LPC_PINCON->PINSEL4 &= 0XF00FFF00; /* Configure P2.0~P2.3 ​​and P2.10~P2.13 as GPIO*/

    LPC_GPIO0->FIODIR |= BEEP; /* Configure P0.11 (BEEP) as output 1 */
    LPC_GPIO2->FIODIR |= 0X000000FF; /* Configure P2.0~P2.3 ​​as output 1 */
    LPC_GPIO2->FIODIR &= 0XFFC3FFFF; /* Configure P2.10~P2.13 as input 0 */


}

/*************************************************************************************************************
** Function name: main
** Descriptions: User program entry function, short JP17, P0.11 pin controls the buzzer,
** Short JP4's KEY1 and P2_10, each time KEY1 is pressed, the buzzer sounds
** input parameters: None
** output parameters: None
** Returned value: None
******************************************************************************************************/
int main (void)
{
    SystemInit(); /* System initialization */
   
    GPIOInit(); 

    while (1) {
        if (KEY1 == 0) { /* If KEY1 is pressed, the buzzer will sound */
            BEEPON();
   LED1ON();
        } else { /* If KEY1 is released, the buzzer will stop */
            BEEPOFF();
   LED1OFF();
        }
        if (KEY2 == 0) { /* If KEY2 is pressed, LED2 will turn on */
   LED2ON();
        } else { /* If KEY2 is released, LED2 will turn off */
   LED2OFF();
        }
        if (KEY3 == 0) { /* If KEY3 is pressed, LED3 will turn on */
   LED3ON();
        } else { /* If KEY3 is released, LED3 will turn off */
   LED3OFF();
        }
        if (KEY4 == 0) { /* If KEY4 is pressed, LED4 will turn on */
   LED4ON();
        } else { /* If KEY4 is released, LED4 will turn off */
   LED4OFF();
        }
    }
}

/****************************************************** *************************************************** ******
  End Of File
***************************************** *************************************************** ******************/

Keywords:LPC1766  GPIO Reference address:LPC1766 GPIO Inputs and Outputs

Previous article:Stm32 TFT LCD display control study notes
Next article:STM32 LED light based on 3.5 library 2

Recommended ReadingLatest update time:2024-11-16 17:57

Design of wireless data transmission system based on LPC1766 and Si4432
IntroductionWith     the development of society, air conditioning systems are widely used in modern office buildings and high-rise buildings. While improving and enhancing the quality of the internal environment of buildings, air conditioning also brings huge energy consumption. In modern buildings, most of the energ
[Microcontroller]
Design of wireless data transmission system based on LPC1766 and Si4432
stm32-GPIO operation (library function)
It's rare to have time, so I want to write about the basics of stm32 recently. 8 ways of GPIO  1. Floating input GPIO_IN_FLOATING ——Floating input, can be used for KEY recognition, RX1        2. GPIO_IPU with pull-up input——IO internal pull-up resistor input        3. GPIO_IPD with pull-down input——IO internal pul
[Microcontroller]
STM8 GPIO modes
GPIO_Mode_In_FL_No_IT No interrupt for floating input GPIO_Mode_In_PU_No_IT Pull-up input without interrupt GPIO_Mode_In_FL_IT  Floating input has interrupt  GPIO_Mode_In_PU_IT  Pull-up input has interrupt  GPIO_Mode_Out_OD_Low_Fast  Output open-drain, low level, 10MHz    GPIO_Mode_Out_PP_Low_Fast  Output push-pull, l
[Microcontroller]
STM32: GPIO basics and corresponding pin operation library functions
USE_STDPERIPH_DRIVER, STM32F10X_HD The English abbreviations of the startup files in the STM32 firmware library Libraries\CMSIS\Core\CM3\startup\arm mean: cl: interconnected product, stm32f105/107 series vl: value product, stm32f100 series xl: ultra-high density (capacity) product, stm32f101/103 series ld: low-densit
[Microcontroller]
Summary of 8 working modes of GPIO in STM32
 1. Push-pull output: can output high and low levels, connect digital devices; push-pull structure generally refers to two transistors being controlled by two complementary signals, one transistor is always turned on while the other is turned off. The high and low levels are determined by the power supply of the IC. A
[Microcontroller]
Summary of 8 working modes of GPIO in STM32
NXP-LPC1768 Getting Started: Development Environment Construction and GPIO
1. Environment Construction This project uses ARM's MDK414. Lower versions may result in failure to download debuggers in MDK. The emulator uses SEGGER's JlinkV7. First, create a new project GPIO, select the path to save, and then the chip selection interface will appear Then confirm, create a new main file main.c a
[Microcontroller]
GPIO_Write() Function
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal) {   /* Check the parameters */   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));      GPIOx- ODR = PortVal; } You can assign values ​​to multiple IO ports at one time (note: it is 16 bits!) Example: GPIO_Write(GPIOD,0x0100) //Set PD8 high
[Microcontroller]
Notes on using LPC2148GPIO
Notes on using LPC2148GPIO: 1) How to make the pin output parallel 0 and 1 To make the pin output parallel data, it is not possible to use IOSET and IOCLR because there is a delay, so you can write it through the IOPIN register. The implementation methods of slow and fast GPIO ports are different.      
[Microcontroller]
Notes on using LPC2148GPIO
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号