Getting started with LPC2148

Description

100%
100%

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.

Basic Registers

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.

1) PINSEL/IOSEL:

  • 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.
PINSEL Register

2) IODIR:

  • 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).

3) IOCLR:

  • 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).

4) IOSET:

  • 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).

5) IOPIN:

  • 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 = PINSEL1 = 0;   // set P0.0 - P0.31 as GPIO 
	
IODIR0 |= (1<<21);   // set P0.21 as output

PINSEL0 and PINSEL1 are set to 0, so as to select the GPIO function for the PORT0 pins
IODIR0 |= (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.

while (1)
{
IOSET0 |= (1<<21);   // set P0.21 as HIGH
delay ();
IOCLR0 |= (1<<21);  // Set P0.21 as LOW
delay ();
}

Inside the while loop, I am performing this toggle for the LED.
IOSET0 |= (1<<21); sets the LED as HIGH
IOCLR0 |= (1<<21); clears the LED pin.
delay (); waits for some time. It is defined below

void delay (void)
{
  unsigned long time = 1000000;
  while (time--);  // this will keep executing untill time becomes 0
}

YOU CAN DOWNLOAD FULL CODE AT THE END OF THIS POST

100%
100%

RESULT

100%
100%
ResultLPCLED
ResultLPCLED2
Check out the VIDEO Below
100%
100%

DOWNLOAD

You can buy me a coffee sensor ūüôā

download the CODE below

100%
100%
, , , , , , ,

Leave a Reply

avatar
  Subscribe  
Notify of
Menu