Programming the Microcontroller

13
www.coretronix.org How to Program the Microcontroller? Normally we are designing a circuit and connecting to different other components like motors, LCDs, LEDS, even more by giving a power supply which is used by that circuit. What the microcontroller does when it is programmed with that circuit? The microcontroller families can understand a program written in assembly language or C language which then be compiled into the machine level language known as binary language (zeros & ones) and the file which has been programmed or stored on a computer hard disk or memory of the microcontroller. The assembler is used to translate the assembly program into machine code. To write the program in assembly language the programmer must have knowledge on the CPU or hardware. The low level languages are used in cross development. The hexadecimal system was used as more efficient way to represent binary numbers, while using binary language the CPU works very fast. Today, we can use many different programming languages such as C, JAVA, ORACLE and others. These languages are called high level languages, to write the program in high level language the programmer do not need any knowledge on hardware which are used for high level application development. The compiler plays a main role in translating the high-level program to machine level as the high level languages are used in native development. Here are Some Tools which are used in Programming with Microcontrollers: Keil uVison Code Editor Speak to: +91-9940798943 Write to: [email protected], [email protected] www.facebook.com/coretronix 1

description

This file used to Programming the Microcontroller

Transcript of Programming the Microcontroller

Page 1: Programming the Microcontroller

www.coretronix.org

How to Program the Microcontroller?Normally we are designing a circuit and connecting to different other components like motors, LCDs, LEDS, even more by giving a power supply which is used by that circuit. What the microcontroller does when it is programmed with that circuit?

The microcontroller families can understand a program written in assembly language or C language which then be compiled into the machine level language known as binary language (zeros & ones) and the file which has been programmed or stored on a computer hard disk or memory of the microcontroller. The assembler is used to translate the assembly program into machine code. To write the program in assembly language the programmer must have knowledge on the CPU or hardware. The low level languages are used in cross development. The hexadecimal system was used as more efficient way to represent binary numbers, while using binary language the CPU works very fast.

Today, we can use many different programming languages such as C, JAVA, ORACLE and others. These languages are called high level languages, to write the program in high level language the programmer do not need any knowledge on hardware which are used for high level application development. The compiler plays a main role in translating the high-level program to machine level as the high level languages are used in native development.

Here are Some Tools which are used in Programming with Microcontrollers:

Keil uVison Code Editor

Assembler

C compiler

Burner/Programmer

Keil Uvison:

The Keil Uvison is free software which solves many of the pain points for embedded developer. This software is integrated development environment (IDE) which integrated a text editor to write programs, a compiler and it will convert source code into hex file.

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

1

Page 2: Programming the Microcontroller

www.coretronix.org

Keil uVsion Software

Guide to Start working with Keil Uvison:

1. Click on the Keil Vision Icon on Desktop.

The following figure will appear

Figure 1

2. Click on the Project menu from the title bar

Then Click on New Project

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

2

Page 3: Programming the Microcontroller

www.coretronix.org

Figure 2

3. Save the Project by typing suitable project name with no extension in your own folder sited in either C:\ or D:\

Figure 3

4. Then Click on save button above.

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

3

Page 4: Programming the Microcontroller

www.coretronix.org

Select the component for u r project. i.e. Atmel……

Click on the + Symbols as for your requirement. Example here selected Atmel.

Figure 4

5. Select AT89C51 as shown below

Figure 5

6. Then Click on “OK”

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

4

Page 5: Programming the Microcontroller

www.coretronix.org

The Following fig will appear

Figure 6

7. Then Click either YES or NO………mostly “NO”.

Now your project is ready to USE.

Now double click on the Target1, you would get another option “Source group 1” as shown in next page.

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

5

Page 6: Programming the Microcontroller

www.coretronix.org

Figure 7

8. Click on the file option from menu bar and select “new”

Figure 8

9. The next screen will be as shown in text page

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

6

Page 7: Programming the Microcontroller

www.coretronix.org

Figure 9

10. Now start writing program in either in “EMBEDDED C” or “ASM”.

For a program written in Assembly, then save it with extension “.asm” and for “EMBEDDED C” based program save it with extension “ .C”

Figure 10

11. Now right click on Source group 1 and click on “Add files to Group Source”

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

7

Page 8: Programming the Microcontroller

www.coretronix.org

Figure 11

12. Now select as per your file extension given while saving the file.

Click only one time on option “ADD”.

Now Press function key F7 to compile. Any error will appear if so happen.

If the file contains no error, then press Control+F5 simultaneously.

Code Editor or Text Editor:

The code editor is used to write the program. The uVision editor includes all the standard features like color syntax highlighting and quickly identifies the errors. The editor is available while debugging. The natural debugging environment that helps you quickly identifies and corrects the errors in your program. After write the program in code editor save that file in .asm or .C format depending on which assembler you are using.

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

8

Page 9: Programming the Microcontroller

www.coretronix.org

Keil Micro-vision Editor

Assembler:

The assembler is used to convert the source code (low level language) into machine level (binary format).

Compiler:

The compiler is used to convert the source code (high level language) into machine level (binary format).

The assembler converts the instructions into machine code:

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

9

Page 10: Programming the Microcontroller

www.coretronix.org

Assembly Language to Machine Level Conversion Diagram

➢ The first file is created with an editor such as DOS edit or other.

➢ The assembler will produce an objective file and a list of file. The extension for the object file is “.obj” while the extension for the list file is “.lst”.

➢ The assembler requires a third step is known as linking. The link program takes one or more objects files and produces an objective file with the extension “.abs”.

➢ The “.abs” file is fed into a program called OH (objective to hex converter) which creates a file with extension “hex” that is ready to burn in to microcontroller ROM.

Burner/Programmer:

The Programming or burning a microcontroller means “to transfer the program from compiler to the memory of the microcontroller”. The program for the microcontroller is generally written in C or assembly language, finally the compiler generates a hex file which contains the machine language instructions like zeros and ones that understandable by the microcontrollers. It is the

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

10

Page 11: Programming the Microcontroller

www.coretronix.org

content of the microcontroller which is transferred to the microcontroller, once a program is transferred to the memory of the microcontroller it works according to the program.

Programmer/Burner

How to Program a Microcontroller:

To transfer the program into a microcontroller we need a device which is know as burner or programmer. A programmer is a hardware device with software which reads the content of the hex file stored on a pc or laptops. It’s read the hex file data serial or USB cable and transfer the data to the memory of the microcontroller.

The programmers and compilers are different for different microcontroller from different companies like the 8051 microcontroller “flash magic” is used to program the microcontroller and AT89c51 microcontroller “programmer” used to program the microcontroller.

Speak to: +91-9940798943 Write to: [email protected], [email protected]

www.facebook.com/coretronix

11