ARM cortex is new microcontroller. It is designed by ARM limited. ARM company had given license to 200 vendors for production. The share of LPC2148 is almost reducing in the market. ARM also aggressively promoting ARM cortex. We have to understand features and way of programming. What are new features of ARM cortex like LPC1768. LPC1768 is manufactured by NXP and it is based on ARM cortex M3 core. It is good for high level of integration and low power consumption embedded system.
Handheld devices are becoming more popular. That devices are smart mobile phone, Kindle, Smart Tab. Low power consumption is required in these devices.
1) Three stage pipe line architecture
2) Higher frequency working. 100 MHz to 120 Mhz is normal working.
3) Harvard architecture which is providing separate buses for local instruction, peripheral and data.
4) There is internal instruction prefetching unit which helps for predicting jumps in the program.
5) It is 100 pin SMD form IC.
6) There is 512 KB flash memory and 64 KB is data memory.
7) Two channels of CAN (Control Area Network) is available.
8) Ethernet MAC is supported which can used as hardwired Web server kind of development.
9) Four UARTs are supported.
10) There are 70 General purpose IO pins and 8 channels of 12 bit ADC.
Pin diagram of LPC1768:
Fig 1: Pin diagram of LPC1768 Microcontroller. (100 pin SMD Physical IC)
ARM cortex Programming:
Whenever we are doing programming of ARM cortex, we have to understand about registers, SFRs which are supported for peripherals.
The processor has the following 32-bit registers:
• 13 general-purpose registers, r0-r12
• stack point alias of banked registers, SP_process and SP_main
• link register, r14
• program counter, r15
• one program status register, xPSR.
Figure 1 shows the processor register set. These are general purpose registers. There are various other registers which we can use for programming. For example FIODIR register to select Output or Input direction of signal. Let you want to blink LED on P1.29 port line of ARM cortex. Then value of FIODIR=0x20000000; This value look like bigger but that’s due to 32 bit of Port 1 of ARM cortex.
Fig 1 Registers of ARM cortex microcontroller.
Similarly we have to understand FIOSET register. This is Fast version register to SET single bit Port line. When I want to make LED ON, I can assign FIOSET=0x00000200;
Similarly we can assign FIOCLR=0x00000200; to make LED OFF also we can set bit equal to “1” that is interesting part in ARM programming.
Steps for Programming:
1) You create project in your working directory, give LED_toggle.uvproj name to it and then compiler will ask you TARGET name, select NXP and LPC1768 microcontroller.
2) Then compiler will ask “whether you want Startup file?” click on “Yes” button so that Startup_LPC17xx.s file will help compiler to maintain Memory Mapping for Lpc1768 microcontroller.
3) Open new file to type source code. Type following code in IDE.
int main (void)
LPC_GPIO2->FIODIR =0x00000200; // P2.9 = Outputs
LPC_GPIO2->FIOCLR = 0x00000200; // Turn-OFF LED
//Loop LED Test
LPC_GPIO2->FIOSET=0x20000000 ; // Turn-ON LED
for(j = 1000000; j > 0; j–);
LPC_GPIO2->FIOCLR = 0x20000000; // Turn-OFF LED
for(j = 1000000; j > 0; j–);
4) You have to take care to add “System_LPC17xx.c” file for SystemInit() function. This SystemInit() function is long technical function for Initializing Microcontroller. PLL logic is used to set frequency in this function.
5)Fig 2 shows Keil screen of LED_toggle project.
Fig 2: LED_toggle project screen
6)Once you type source code, now
You can set options for creating HEX file in “Options for Target” in Project Menu. Fig 3 shows Debug to test code in compiler. In debugging mode, you can see Register values of LPC1768 Microcontroller.
Fig 3: Debug mode of Keil compiler version 4.
7) Now in debug mode you can select “Fast GPIO -> Port 2” to check output in Simulator. If you are getting some error to run code in simulator then might be you forgot to select Simulator options and your keil compiler is in “Hardware Debug Mode”.
Fig 4 shows output of LED toggling at Port 2 and line 9. If you are not getting blink then reduce delay value in FOR LOOP so that you can see blink output.
Fig 4 Out put of LED toggling program at P2.9 port line of LPC1768.
I do believe this program seem very simple but many times due to Library file this become very tough to run. We assume you have library file of LPC1768 Iniitlaization function with you.
Filed Under: Recent Articles