PCONP|=(1" />

GPIO driver for PC1788

Publisher:HappyHeartedLatest update time:2017-01-13 Source: eefocusKeywords:lPC1788 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include "led.h"

 

 

void led_init(void)

{

    //p1.14 p0.16 p1.13 p4.27

    LPC_SC->PCONP |= (1<<15); //Turn on the clock

    //Select the pin mode. 1788 has designed a register for each pin to select the pin mode

    LPC_IOCON->P1_14 = 0x00; //Select gpio function, disable hysteresis, non-reverse, normal push-pull

    LPC_IOCON->P1_14 |= (2<<3); //Pull up

    P1dir(14) = 1; //output

    P1low(14) = 1; //Set to low level

   

    LPC_IOCON->P0_16 = 0x00; //Select gpio function, disable hysteresis, non-reverse, normal push-pull

    LPC_IOCON->P0_16 |= (2<<3); //Pull up

    P0dir(16) = 1; //output

    P0low(16) = 1; //Set to low level

   

    LPC_IOCON->P1_13 = 0x00; //Select gpio function, disable hysteresis, non-reverse, normal push-pull

    LPC_IOCON->P1_13 |= (2<<3); //Pull up

    P1dir(13) = 1; //output

    P1low(13) = 1; //Set to low level

   

    LPC_IOCON->P4_27 = 0x00; //Select gpio function, disable hysteresis, non-reverse, normal push-pull

    LPC_IOCON->P4_27 |= (2<<3); //Pull up

    P4dir(27) = 1; //output

    P4low(27) = 1; //Set to low level

       

}

 

void led_set(u8 ch)

{

    switch(ch)

    {

    case 0:

        P1high(14) = 1;

        break;

    case 1:

        P0high(16) = 1;

        break;

    case 2:

        P1high(13) = 1;

        break;

    case 3:

        P4high(27) = 1;

        break;

    }

}

 

void led_clear(u8 ch)

{

    switch(ch)

    {

    case 0:

        P1low(14) = 1; //Set to low level

        break;

    case 1:

        P0low(16) = 1; //Set to low level

        break;

    case 2:

        P1low(13) = 1; //Set to low level

        break;

    case 3:

        P4low(27) = 1; //Set to low level

        break;

    }

}

 

 

 

 

//Bitband operation to achieve GPIO control function similar to 51

//For specific implementation ideas, please refer to Chapter 5 (pages 87-92) of <>.

//IO port operation macro definition

#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))

#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr))

#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum))

 

//IO port address mapping

//Output register

#define GPIO0_ODR_Addr    (LPC_GPIO0_BASE+0x18) //0x2009C018

#define GPIO1_ODR_Addr    (LPC_GPIO1_BASE+0x18) //0x2009C038

#define GPIO2_ODR_Addr    (LPC_GPIO2_BASE+0x18) //0x2009C058

#define GPIO3_ODR_Addr    (LPC_GPIO3_BASE+0x18) //0x2009C078

#define GPIO4_ODR_Addr    (LPC_GPIO4_BASE+0x18) //0x2009C098

  

//Input register

#define GPIO0_IDR_Addr    (LPC_GPIO0_BASE+0x14) //0x2009C014

#define GPIO1_IDR_Addr    (LPC_GPIO1_BASE+0x14) //0x2009C034

#define GPIO2_IDR_Addr    (LPC_GPIO2_BASE+0x14) //0x2009C054

#define GPIO3_IDR_Addr    (LPC_GPIO3_BASE+0x14) //0x2009C074

#define GPIO4_IDR_Addr    (LPC_GPIO4_BASE+0x14) //0x2009C094

 

//Direction register

#define GPIO0_DIR_Addr    (LPC_GPIO0_BASE+0x00) //0x2009C000

#define GPIO1_DIR_Addr    (LPC_GPIO1_BASE+0x00) //0x2009C020

#define GPIO2_DIR_Addr    (LPC_GPIO2_BASE+0x00) //0x2009C040

#define GPIO3_DIR_Addr    (LPC_GPIO3_BASE+0x00) //0x2009C060

#define GPIO4_DIR_Addr    (LPC_GPIO4_BASE+0x00) //0x2009C080

 

// Clear register

#define GPIO0_CLS_Addr    (LPC_GPIO0_BASE+0x1C) //0x2009C01C

#define GPIO1_CLS_Addr    (LPC_GPIO1_BASE+0x1C) //0x2009C03C

#define GPIO2_CLS_Addr    (LPC_GPIO2_BASE+0x1C) //0x2009C05C

#define GPIO3_CLS_Addr    (LPC_GPIO3_BASE+0x1C) //0x2009C07C

#define GPIO4_CLS_Addr    (LPC_GPIO4_BASE+0x1C) //0x2009C09C

 

 

//IO port operation, only for a single IO port!

// Make sure the value of n is less than 32!

#define P0high(n) BIT_ADDR(GPIO0_ODR_Addr,n) //Output 0 Output unchanged 1 Output is 1

#define P0low(n) BIT_ADDR(GPIO0_CLS_Addr,n) // Clear 0 output unchanged 1 output 0

#define P0in(n)    BIT_ADDR(GPIO0_IDR_Addr,n)  //输入

#define P0dir(n) BIT_ADDR(GPIO0_DIR_Addr,n) //Direction 0 input 1 output

    

 

#define P1high(n) BIT_ADDR(GPIO1_ODR_Addr,n) //Output 0 Output unchanged 1 Output is 1

#define P1low(n) BIT_ADDR(GPIO1_CLS_Addr,n) // Clear 0 output unchanged 1 output 0

#define P1in(n) BIT_ADDR(GPIO1_IDR_Addr,n) //Input

#define P1dir(n) BIT_ADDR(GPIO1_DIR_Addr,n) //Direction 0 input 1 output

 

#define P2high(n) BIT_ADDR(GPIO2_ODR_Addr,n) //Output 0 Output unchanged 1 Output is 1

#define P2low(n) BIT_ADDR(GPIO2_CLS_Addr,n) // Clear 0 output unchanged 1 output 0

#define P2in(n)    BIT_ADDR(GPIO2_IDR_Addr,n)  //输入

#define P2dir(n) BIT_ADDR(GPIO2_DIR_Addr,n) //Direction 0 input 1 output

 

#define P3high(n) BIT_ADDR(GPIO3_ODR_Addr,n) //Output 0 Output unchanged 1 Output is 1

#define P3low(n) BIT_ADDR(GPIO3_CLS_Addr,n) // Clear 0 output unchanged 1 output 0

#define P3in(n)    BIT_ADDR(GPIO3_IDR_Addr,n)  //输入

#define P3dir(n) BIT_ADDR(GPIO3_DIR_Addr,n) //Direction 0 input 1 output

 

#define P4high(n) BIT_ADDR(GPIO4_ODR_Addr,n) //Output 0 Output unchanged 1 Output is 1

#define P4low(n) BIT_ADDR(GPIO4_CLS_Addr,n) // Clear 0 output unchanged 1 output 0

#define P4in(n)    BIT_ADDR(GPIO4_IDR_Addr,n)  //输入

#define P4dir(n) BIT_ADDR(GPIO4_DIR_Addr,n) //Direction 0 input 1 output


Keywords:lPC1788 Reference address:GPIO driver for PC1788

Previous article:LPC1788 LCD interface drives true color screen
Next article:IIC usage of LPC1788

Recommended ReadingLatest update time:2024-11-17 05:49

Embedded driver learning GPIO driver
Development Environment Host development environment: Ubuntu 12.04 BootLoader:u-boot-1.1.6 kernel:linux-2.6.30.4 CPU:s3c2440 Development board: TQ2440 Development steps 1. Hardware Analysis In the development board provided by Tianqian Technology, the four LED lights (TQ2440) use the S3C2440 chip: GPB5, GPB6, GPB7 a
[Microcontroller]
Embedded driver learning GPIO driver
Problems with using the internal EEPROM of LPC1788
Recently, I found a problem when using the internal EEPROM of LPC1788 to store data: the EEPROM sectors of LPC1788 only have 0-62 and 63 sectors do not exist uint32_t i, j; uint8_t count;     uint8_t error = 0;   debug_frmwrk_init(); _DBG(menu); EEPROM_Init();   count = sizeof(write_buffer);     count &= 0xFC;
[Microcontroller]
LPC1788 external interrupt example, based on Keil MDK
The examples of LPC1700 external interrupts on the Internet are all from ADS. I will contribute one from Keil MDK. Taking external interrupt 0 (EINT0) as an example, a low level triggers an interrupt The key codes are as follows: //The header file is "LPC177x_8x.h" included with MDK 4.23, and the macros used in
[Microcontroller]
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号