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
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()));
……………………
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The story I have to tell about Yatli+!
- Misuse of "termination" will cause signal failure
- Raspberry Pi Pico is out~ I originally said that I would not review it before the New Year, but I am here to recommend this board to you~~
- PyBoard W5500 firmware compilation issue
- Discussion and help
- "Playing with the board" + lighting up the SPI touch screen of Xintao
- &FF0000 and &880000 are both red. What is the difference between these two reds?
- Internet radio design based on RSIC-V RVB2601 (3)
- LIS2MDL three-axis magnetometer package and code
- Live broadcast with prizes: Enter the TI robot production class, starting on Friday, reservations are in progress! (Share 100% to get gifts)