All the controllers can be programmed with the help of the programming languages. These programming languages can be of a low level language or a high level language depends on the flexibility of the person working with and the size of the project he is going to work with. The low level language is the Assembly language and examples of high level languages are Embedded C, Embedded C++.
In the forthcoming sessions lets discuss about the programming of 8051 controllers with the help of high level Embedded C language. Embedded C Language uses the syntax of the C programming language. There are certain things that has to be noted down very seriously while using this Embedded C language. Major aspect to be considered is the # Limited memory of the micro controller , #Power consumption.
These two concepts are very seriously taken because of the very limited internal Flash Memory of the controller which is limited to 8KBytes. For what ever application we build the system and write our codes into controller, it is mandatory that the size of our program should not exceed the above specified value.
Even though our program for many application does not exceed the limit it is mandatory to avoid redundancy of our programming. If the program increases then the power consumed to execute that program also increases . If the same application is done with the less number of program lines then the power consumption is reduced. So the power can not only be consumed by altering the hardware components of the system but it also depends on the software programs that is used to give intelligence to the system.
Format of our Embedded C Language resembles the C Programming Language. Now lets take a look over how the structure of the Embedded C is going to be
# include<REG51.h> —> Header File Declaration
—————————-> Global variable Declaration if any used
main() ———————> Main Function
—————————-> Local Variable Declaration
sub functions() ———–> Sub functions
It starts with the Header file declaration. Appropriate header file name is given for a particular controller which is used in our system where the header file contains the information regarding the controller we specify. This follows with the Global variable declaration. Any defined statements, functions, variables to be used globally are declared here. The main function contains all the processing values to be declared here locally. Then finally with the sub functions which can be called n number of times according to the given instructions where it is an optional case.
We require an Integrated Development Environment (IDE) for developing our programs and flash it in our controller. For this we use the Keil uVision3 IDE platform for developing codes and 8051 Loader v1.0 Beta by Robomart Online Robotics Store
Follow the steps for a starting up with Keil IDE.
# Initialize the Keil uVision3 . The window opens as shown below.
# Click on Project -> New Project when you start a new project
# Select the location for saving the project and the give name of the project
# On the list of brands click on Atmel
# Select the micro controller AT89S51 device and click on OK button
# Click Yes on the permission popup window
# Now go to File menu and click on New
# A new window appears, start typing the program in the appeared window and hit File menu and Save option and save the file with the ‘.c’ extension.
# Now right click the Source Group 1 and click on the Add files to Group ‘ Source Group 1’ option
# Now select the saved file with ‘.c’ extension and add button, once the file is added click on close button
# Right click on the Target 1 and click Options for Target ‘Target 1’
# The following window appears. From the window click on Output-> Click on Create HEX format -> Click OK Button
# Now for Building our project go to Project-> Click on Build Target or simply hit F7
# The output window show the status of the compiled program indicating errors and warnings in the same.