Assignment 09 Problem statement : Write a Embedded C program to switch-on/switch-off LED. Learning Objective: -> To study embedded programming concepts -> To study LCD control functions -> How output is provided to different port Description: Let us assume that LED is connected at pin RD0. RD0 is a pin0 of port D. When RD0 is high LED become ON and when RD0 is low LED become OFF.This program toggle the LED connected at PORT D0. Code: #include<lpc2138.h> void delay(long); int main(void) { IO0DIR=0x007F8000; while(1) { IO0SET =0x00550000; IO0CLR = 0x002A8000; delay(70000); IO0CLR =0x00550000; IO0SET = 0x002A8000; delay(70000); } return 0; } void delay(long i) { while(i--); } # Steps For Creating A Demo Project in Eclipse This is the screen you will see in front of you when you double click the Eclipse icon on desktop. Step1 : Select the working perspective
First of all select the working perspective for providing the compilation environment to your project. Click on window >> Open Perspective >> C/C++ Step2 : Select the Project Type Now select the project type whether you want to compile it as a standard make C or managed make C project. For that, drop down the File menu >> open New >>select Project
And select the Standard Make C Project in the C drop down option and click next Now here is the window where you can give the name to your project.
Just type the name you want to give to your project but make sure the right path of the workspace being displayed and there is no other project having same name exists in that particular workspace. Otherwise it will prompt an error message and will not crate the project. If you want to change the workspace, just uncheck the Use default location and type the right path manually. Then click Next Then after, open the make builder window and check for the highlighted comments in displayed in yellow box. And click Finish Step3 : Adding / Importing Supporting files Soon after you finish up with the previous step, the following screen window will be exposed. Make sure it displays the name of your project as shown below. Before we start the actual compilation we will have to add / import some basic source files. Although they are specific to the respective projects but must be included (with little up gradations) to each new project, so as to specify memory initialization and MAKE ( sequential compilation arrangements ) commands.
Thus for that we will use the Import feature of CDT ( C Development Tools ). Now first highlight the project like shown below, and then.. Again open up the File drop-down list. Where, you will find the Import command (not shown in this picture). Select that feature and you will find the screen displayed as below. Here we will import the files from the general environment.
Now open the drop down menu for General >> Select File System >> click Next Then in the Import window click Browse to give the appropriate path where the demo project folder is located. As we had earlier added the demo project folder, we have to select the same path C:\GCCFD\Demo_Projects\demo_lpc2138_blink_flash And then click OK
Now when the demo project folder is selected, you can get a view of all files present in that folder. Among those, select the minimum required (or the basic) files which can be stated as follows: 1. Assembler Source File : crt.s Which contains the startup function (called in ld-script), Reset Handler function, and necessary interrupt vector functions ( if included) in a project. 2. Linker script file : $Project name$.cmd This contains, the memory mapping specific initialization instructions. 3. Make file : makefile.mak This contains the sequential compilation process instructions to be executed after every Build command. 4. C source code file : main.c This contains the basic source code file of the project. It s not always that we ve to import this file from another location. But because here we re creating a demo project so we ll have to take the file as it is. Otherwise when we create our different projects, this file will obviously be edited each time for the respective C source codes. Here the name
main is just a symbolic representation of our main C code. You can give any name as you want. 5. Respective Header File : lpcxxx.h Here we will just include the necessary header file specific to our target processor. We must import this file from appropriate location. Check the boxes in front of the files to be selected >> make sure the right name of your project is displayed in the Into Folder text box >> click Finish. Step4 : The Compilation Process Here we are in the actual compilation environment having all the files needed for the assembling, building and compilation process.
But before going into further steps, first make sure that all files you have selected earlier are included in the C/C++ window as shown marked. With those considerations, we begin the compilation process. Note that, each time you build or compile your code you should have to follow these process steps. Soon while you see the clean window, select (check) the check box in front of the project name >> click on OK Note: Here you can also have an option to automatically start the build just after cleaning the project environment. For that, select the check box for Start a build immediately
iii ) Repeat the step ii) this time for the Build All option
As the Build All command is executed the gcc compiler will run in background taking reference of the compilation commands specified in make file. The stepwise execution and the end result can be visible in the console window located at the bottom of the screen (as shown in the picture). Now here notice that, after the build (/ compile) some more files have been created in the C/C++ projects window. These are some of the output files which are required by the debugger to come into act. The files are main.bin : (required for the openocd utility to program the processor core) main.out : (required for the symbolic reference to be taken by GNUARM debugger) main.hex : (required for flash utility software to program the processor core)