LPC2138+LCD1602 counter proteus simulation and source code adding comments and changing pins

Publisher:算法之手Latest update time:2019-10-15 Source: eefocusKeywords:LPC2138 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The schematic diagram of the LPC2138 simulation simple calculator is as follows (the proteus simulation project file can be downloaded from the attachment of this post) The lcd1602 liquid crystal display
0.png0.png 

LPC2138 source program is as follows:

#define IN_TARGET

#include "config.h"

#define LED1 1 << 18 // P0.18 controls LED1


/*********************************************************************************************************

** Function name: IRQ_Exception

** Function description: Interrupt exception handling program, users can change the program according to their needs

********************************************************************************************************/

void __irq IRQ_Exception(void)

        {

    while(1); // Replace this sentence with your own code

        }


/*********************************************************************************************************

** Function name: FIQ_Exception

** Function description: Quickly interrupt the exception handling program, the user can change the program according to the needs

********************************************************************************************************/

void FIQ_Exception(void)

{         uint32 i;

        i = IO0SET; // Read the current control value of LED1

        if ((i & LED1) == 0) IO0SET = LED1;

        else IO0CLR = LED1;

/* Wait for the external interrupt signal to return to a high level. If the signal remains at a low level, the interrupt flag will remain set*/

        while ((EXTINT & 0x01) != 0)

        { EXTINT = 0x01; // Clear EINT0 interrupt flag

        }

}

/*********************************************************************************************************

** Function name: TargetInit

** Function description: Target board initialization code, called where needed, changed as needed

********************************************************************************************************/

void TargetInit(void)

{

    /* Add your own code */

}


/*********************************************************************************************************

** Function name: TargetResetInit

** Function description: Target board initialization code before calling main function, change as needed, cannot be deleted

********************************************************************************************************/

void TargetResetInit(void)

{

/* Set memory mapping mode */

#ifdef DEBUG_RAM // If debugging in on-chip RAM

MEMMAP = 0x02; // Map to on-chip RAM

#endif

#ifdef DEBUG_FLASH // If debugging in on-chip FLASH

MEMMAP = 0x01; // Map to on-chip FLASH

#endif

#ifdef IN_CHIP // If the FLASH is released in the chip

MEMMAP = 0x01; // Map to on-chip FLASH

#endif


/* Set the clocks of each part of the system */

    PLLCON = 1; // Set to activate but not connect PLL

#if ((Fcclk / 4) / Fpclk) == 1 // This value is determined by the system hardware

    VPBDIV = 0;

#endif

#if ((Fcclk / 4) / Fpclk) == 2 // This value is determined by the system hardware

    VPBDIV = 2;

#endif

#if ((Fcclk / 4) / Fpclk) == 4 // This value is determined by the system hardware

    VPBDIV = 1;

#endif


/* Set the value of PLL multiplication factor M and division factor P*/

#if (Fcco / Fcclk) == 2

    PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);

#endif

#if (Fcco / Fcclk) == 4

    PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);

#endif

#if (Fcco / Fcclk) == 8

    PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);

#endif

#if (Fcco / Fcclk) == 16

    PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);

#endif

    PLLFEED = 0xaa; // Send PLL feed sequence to execute the action of setting PLL

    PLLFEED = 0x55;

    while((PLLSTAT & (1 << 10)) == 0); // Wait for PLL to lock

    PLLCON = 3; // Set to activate and connect PLL

    PLLFEED = 0xaa; // Send PLL feed sequence, perform activation and connection actions

    PLLFEED = 0x55;

    

/* Set up memory acceleration module */

    MAMCR = 0; // Disable MAM function

#if Fcclk < 20000000

    MAMTIM = 1; // System clock is lower than 20M, it is recommended to set it to 1

#else

#if Fcclk < 40000000

    MAMTIM = 2; // The system clock is between 20M and 40M, it is recommended to set it to 2

#else

    MAMTIM = 3; // System clock is higher than 40M, it is recommended to set it to 3

#endif

#endif

    MAMCR = 2; // Enable MAM function

       

/* Initialize VIC */

    VICIntEnClr = 0xffffffff; // Clear all interrupts

    VICVectAddr = 0; // default vector address register

    VICIntSelect = 0; // 0: The corresponding interrupt request is assigned to IRQ, 1: The corresponding interrupt request is assigned to FIQ.


    /* Add your own code */


}


/*******************************************************************************************

** The following are some implementations of system-related library functions, which users can modify according to their own requirements

*******************************************************************************************/

#include "rt_sys.h"


// for printf and scanf fuctions

int sendchar (int ch)  {                 /* Write character to Serial Port    */

  while (!(U0LSR & 0x20));

  return (U0THR = ch);

}


int getkey (void)  {                     // Read character from Serial Port

  while (!(U0LSR & 0x01));

  return (U0RBR);

}


int fputc(int ch,FILE *f)

{

  return (sendchar(ch));

}


int fgetc(FILE *f) {

  return (sendchar(getkey()));

……………………

Keywords:LPC2138 Reference address:LPC2138+LCD1602 counter proteus simulation and source code adding comments and changing pins

Previous article:ARM7 LPC2138 digital frequency meter design source code and report
Next article:Open source ARM7 driver splicing 1024X1024LCD screen Proteus simulation source code

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号