Getting started with LPC2148
LPC2148 is the widely used IC from ARM-7 family. It is manufactured by Philips and it is pre-loaded with many inbuilt peripherals making it more efficient and a reliable option for the beginners as well as high end application developer.
Today, in this tutorial, I will explain how to get started with LPC2148, and how to use some basic registers to blink the LED.
The LPC2148 incorporates a 512 kB Flash memory system. This memory may be used for both code and data storage. The FLASH memory can be programmed by means of
1. Serial built-in JTAG interface
2. Using In System Programming (ISP) and UART0
Note:- In order to use ISP and UART0, we need to use FLASHMAGIC.
LPC2148 has two IO ports (P0 and P1) each of 32 bit wide thus giving us total of 64 pins. Each pin can be used as GPIO (General Purpose IO) or can peform alternate functions i.e ADC, I2C, SPI etc.
To blink a LED, we have to perform the GPIO operations. And to do that, we must know some basic set of GPIO registers first. Below are the registers, that we are going to use to blink LED.
- PINSEL/IOSEL are 16 bit wide registers, used for setting the function of the PIN. Function can be either GPIO or Alternate Function.
- There are 3 PINSEL registers in LPC2148 i.e. PISEL0/IOSEL0 (PORT0.0-PORT0.15), PINSEL1/IOSEL1 (PORT0.16-PORT0.31) and PINSEL2/IOSEL2 (PORT1.16-PORT1.31).
- As you can see in the picture below, setting different bits will change the function of the Pins. However, to use the GPIO, we have to set it to 0.
- GPIO Port Direction control register. IODIR are 32 bit wide registers, used for setting the direction of the PIN. Direction can be either input or output. Writing 1 to a particular bit will set the PIN as output and writing 0 will set the PIN as input.
- Threre are 2 IODIR registers i.e. IODIR0 (PORT0.0-PORT0.31) and IODIR1 (PORT1.0-PORT1.31).
- For eg- if we want to set PIN 3 of PORT0 as output, IODIR0 = 0x00000008; Here all other PINs except PIN 3 are set as input (because they are all 0s) and PIN 3 is output (It is 1).
- GPIO Port Output Clear registers. IOCLR are 32 bit wide registers, they controls the state of output pins. Writing ones produces lows at the corresponding port pins and clears the corresponding bits in the IOSET register. Writing zeroes has no effect.
- There are 2 IOCLR registers i.e. IOCLR0 (PORT0) and IOCLR1 (PORT1).
- GPIO Port Output Set registers.IOSET are 32 bit wide register, they controls the state of output pins in conjunction with the IOCLR register. Writing ones produces highs at the corresponding port pins. Writing zeroes has no effect.
- There are 2 IOSET registers i.e. IOSET0 (PORT0) and IOSET1 (PORT1).
- GPIO Port Pin value register. The current state of the GPIO configured port pins can always be read from this register.
- we will cover this in upcoming tutorials.
Some Insight into the CODE
PINSEL0 and PINSEL1 are set to 0, so as to select the GPIO function for the PORT0 pins
(1<<21); is similar to as writing a ‘1’ to 21st bit of the Register. This is because the LED is connected to the P0.21, and need to be set as output.
Inside the while loop, I am performing this toggle for the LED.
(1<<21); sets the LED as HIGH
(1<<21); clears the LED pin.
(); waits for some time. It is defined below
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020