Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
[This chapter discusses -Intel Hex file, Assembly language, C language, Embedded Development Tools-Assemblers, Interpreters, Compilers, simulators, emulators, debuggers and IDE for the development of 8051 and other Embedded Systems] ----------------------------------------------------------------------------------------------------------Writing the Control Program When its time to write the program that controls your project, the options include using machine code, assembly language, or a higher-level language. Which programming language you use depends on things like desired execution speed, program length, and convenience, as well as whats available in your price range. Machine code, INTEL HEX file and Downloader The most fundamental program form is machine code, the binary instructions that cause the CPU to perform the operations you desire. Representing the machine code is of many types usually binary. Combining this binary data into 8 bit, 16 bit and 32 bits makes it easily understandable. Hexadecimal format combines BCD data which is a direct representation of binary. For easier representation of the binary is the hexadecimal format. Therefore microprocessor or microcontroller development makes use of hex file format. This is called as Intel hex file. Assembler or Compiler whatever we use to develop code for microprocessors or controllers hex file is the ultimate target. If an assignment is given by you to make a led blink using your microcontroller then you have to develop code in assembly or high level language and create the hex file for that program. This hex file should be downloaded to the microcontroller code memory. Now the microcontroller runs as you programmed. The device used for downloading the hex file is called the downloader or programmer. Assembly language One step removed from machine code is assembly language, where abbreviations called mnemonics (memory aids) substitute for the machine codes. The mnemonics are easier to remember than the machine codes they stand for. For example, in the 8051s assembly language, the mnemonic CLR C means clear the carry bit, and is easier to remember than its binary code (11000011). Since machine code is ultimately the only language that a CPU understands, you need some way of translating assembly-language programs into machine code. For very short programs, you can hand assemble, or translate the mnemonics yourself by looking up the machine codes for each abbreviation. Another option is to use an assembler, which is software that runs on a desktop computer and translates the mnemonics into machine code. Most assemblers provide other features, such as formatting the program code and creating a listing that shows both the machine-code and assembly-language versions of a program side -by-side. Higher-level languages A disadvantage to assembly language is that each device family has its own set of mnemonics, so you have to learn a new vocabulary for each family you Work with. To
get around this problem, higher-level languages like C, Pascal, FORTRAN, Forth, and BASIC follow a standard syntax so that programs are more portable from one device to another. The idea is that with minor changes, you can use a language like BASIC to write programs for many different devices. In reality, each language tends to develop many different dialects, depending on the chip and the preferences of the languages vendor, so porting a program to a different device isnt always effortless. But there are many similarities among the dialects of a single language, so, as with spoken language, a new dialect is easier to learn than a whole new language.Higher-level languages also simplify programming by allowing you to do in one or a few lines what would require many lines of assembly code to accomplish. Interpreters and compilers: These are two forms of higher-level languages. An interpreter translates a program into machine code each time the program runs, while a compiler translates only once, creating a new, executable file that the computer runs directly, without re-translating. As a rule, interpreters are very convenient for shorter programs where execution speed isnt critical. With an interpreted language, you can run your program code immediately after you write it, without a separate compile or assembly step. A compiler is a good choice when a program is long or has to execute quickly. A single language like BASIC may be available in both interpreted and compiled versions. Each device family requires its own interpreter or compiler to translate the higher-level code into the machine code for that device. In other words, you cant use Quick BASIC for IBM PCs to program an 8051 microcontrolleryou need a compiler that generates program code for the 8051.Compared to an equivalent program written in assembly language, a compiled program usually is larger and slower, so assembly language is the way to go if a program must be as fast or as small as possible. A higher-level language also may not offer all of the abilities of assembly code, though you can get around this by calling subroutines in assembly language when necessary. BASIC-52 is an interpreted language, but BASIC compilers for the 8052 are also available. In fact, you can have the best of both worlds by testing your programs with the BASIC-52 interpreter, and compiling the finished product for faster execution and other benefits of the compiled version. Testing and Debugging After youve written a program, or a section of one, its time to test it and as necessary, find and correct mistakes to get it working properly. The process of ferreting out and correcting mistakes is called debugging. Easy debugging and troubleshooting can make a big difference in how long it takes to get a system up and running. As with programming, you have several options here as well. Testing in EPROM One way is to burn your program into EPROM, install the EPROM in your system, run the program, and observe the results. If problems occur (as they usually Will) you modify the program, erase and reburn the EPROM, and try again, repeating as many times as necessary until the system is operating properly.
Development systems Another option is to use a development system. A typical development System consists of a monitor program, which is a program stored in EPROM or other memory in the microcontroller system, and a serial link to a personal computer. Using the abilities of the monitor program, you can load your program from a personal computer into RAM (instead of the more permanent EPROM) on the microcontroller system, then run the program, modify it, and retry as often as necessary until the program is working properly. Most development systems also allow single-stepping, setting breakpoints, and viewing and changing the data in memory. In single-stepping, you run the program one step at time, pausing after each step, so you can more easily monitor what the circuits and program are doing at each step. A breakpoint is a program location where the program stops executing and waits for a command to continue. You can set breakpoints at critical spots in your program. At any breakpoint, you can view or change the contents of memory or perform other tests. Simulators Another development tool is a simulator, which is software that runs on a desktop computer and uses the video display to demonstrate what would happen if a specific microprocessor or microcontroller were to run a particular program. You can look inside the simulated chip, observe the contents of internal memory, and single-step or set breakpoints to stop program execution at a desired program location or condition. In this way, you can get a program working properly before you commit it to EPROM. One drawback to simulators is that they cant mimic all features of the chip of interest, especially interrupt-response and timing characteristics. Emulators An in-circuit emulator (ICE) is hardware that replaces the microprocessor in question by plugging into the microprocessors socket on the device you want to test. Like a simulator, an emulator lets you control program execution and monitor what happens at each program step. Microprocessor emulators typically are expensive. A ROM emulator is a lower-cost option that simulates an EPROM (using RAM, for example) for program storage, and usually provides the abilities of a development system as well. The Keil-IDE development system The Keil-IDE system and a personal computer form a complete development system for writing, testing, and storing programs. The personal computers keyboard and screen make it easy to write and run programs and view the results. Keil-IDE has many built-in debugging features that make it easy to test programs. You can run a program immediately after writing it, without having to assemble, compile, or program an EPROM. You can use a STOP statement and CONT (continue) command to set breakpoints and resume executing your program. You can use PRINT statements to display variables as the program runs. And, if you wish, you can use your personal computer for writing programs off-line and uploading and downloading them to the KeilIDE system. The keil contains the A51 assembler, C51 compiler and BL51 linker to translate the assembly or C source code into INTEL hex file.
(I)What is uVision2?
uVision2 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger. A Project manager is used to add all the source code files and document files together to make it as a complete project file. It Links all the Source files together and helps to generate a single hex file output if the source files are compiled. The term make facility refers to compiling the source file to create or make the hex file, assembly file, object file, linker file, listing file etc. But the requirement for a programmer is the hex file. Because the microcontroller or processor can understand only the hex file which is the machine level language. The hex file will be downloaded to the microcontroller using the downloader. Tools configuration refers to hardware and software tools that can be used along with the keil - IDE as add on-board or add on software. But we have to configure the tools suite the keil. Editor is the source code editor used to write the assembly language and C language. Then the file can be saved as C or assembly file and it can be added to the project manger. After youve written a program, or a section of one, its time to test it and as necessary, find and correct mistakes to get it working properly. Keil contains a powerful debugger in built in it. The above said options are available to the user. Other tools such as assembler, compiler, linker and object file converter are available in the IDE but are not for the usage by the software developer. It can be commented as For Office Use Only but essential to create the hex file.
Fig 2.1 Opening an existing project Hello For opening a project already exists in some location of the PC, Go to Project and Click Open Project as shown in the diagram.
Navigating to the Project file location After clicking the open project from the project manager, the navigation toolbar for the project source file location appears. Navigate and select the example project from keil folder in the installed location or open the project created by you.
Fig 2.3 Navigating to the Project file location Navigation refers to normal choosing a location in the PC which you are familiar already. The example here depicts you opening a project Hello which is an example program which is in the keil software. Many example programs come along with the keil software. These are available to the user as soon as keil has been installed. Fig 2.3 and 2.4 explains navigation to keil folder. These examples are available in the keil/Examples folder in C or D colon where keil has been installed. Some of the example programs available in keil uVision2 are
Hello which prints a string Hello world to the serial port of the PC using the microcontroller? Traffic is a program that controls a traffic light The MEASURE program uses the analog inputs of the C515 to simulate a data logger. The BLINKY project does nothing more than blink the LEDs on the MCBx51 evaluation board. The DES project is the implementation of Cryptographic algorithm in 8 bit 8051 microcontroller. The CSAMPLE program implements a simple addition and subtraction calculator. Numbers and operators are entered via serial I/O. ASAMPLE is an assembly program that writes text to the serial port of the 8052 microcontroller. Navigating to the Project file location
Opening a Hello Project from the keil examples: Selecting and opening the Hello project from the keil example projects. It is not necessary that the project should be the example. You can open your own project which you create already if you have saved in your PC. Fig 2.5 depicts opening the Hello Project file.
Select Hello.UV2
Open Hello.UV2
Fig 2.5 Opening the Hello.UV2 Project file Setting the options for the target device Make sure that the output Intel hex file creation is selected. If it is not enabled. Make it enabled. This is available in the options for the target. Fig 2.6 depicts how to select the options for the target. Right Click on the target and Select options for the target. Now the option for the target window opens as shown in the fig2.7.Select the output option and enable create hex file option. If device is to be changed, change it to a desired one using the target window like the output window. No need to change the other option for A51, C51, BL51 and other option. If hardware debugger keil monitor 51 is used change the option of the debugger. Otherwise select the simulator option in the debug window. Default condition is simulator selected.
A51 is the assembler available in the keil IDE which converts the assembly language into object file. C51 is the Cross Compiler available in the keil IDE which converts the C language into assembly language. The object files for every source files either an assembly file or a C file will be created. These object files should be linked together to create the hex file. The purpose of the linker is that. The linker available in keil is BL51. The target options Contains all these options to be configured if necessary by the user.
Fig 2.7 Enable Create hex file option In the listing option we can enable the list file and assembly file generation. We can also select include files and Symbols options. If you enable all these things the Compiler generates the Assembly files related to the C file we are using in our project. Similarly we can select the options for the Source group by right Clicking on the Source group and selecting options for the Source group. Fig 2.8 depicts the Selection of the options for the source group. Enable generate Assembler SRC file. Assemble Always build and other options in the Options for the source group window as shown in fig 2.9.
Set Options such as generate Assembler SRC file, Assemble SRC file and other Options
Selecting or changing the target device For changing or selecting the device for the target right Click on the target (Simulator) and Select the Option Select Device for the Target Simulator.
Fig 2.10 shows right clicking and selecting the Select device for the target. Now the Select device for the Target window opens. Now Navigate to the ATMEL Manufacturer and select the device 89C52 for using the Chip AT89C52 microcontroller. If we are using AT89s52 Controller also we can select the device At89c52. After selecting the device click ok to close the device selection window. This is shown in the fig 2.11. Rebuild target from the shortcut for rebuild option. The Project has been opened. Now build the application using the rebuild option. All the source files have been already created and added to the target project manager. So its time to convert the project sources to hex file. For that the project targets or source files should be builded, rebuild or compiled to make the Intel hex file. The terms build, rebuild and Compile means the same, making an Intel hex file.
Fig 2.12 Rebuilding the target using the shortcut If not the shortcut is available to the user in the keil software GUI just go the view option and select tool bar. This is shown in fig 2.12.The user can build the target files also by the project manager window or the project workspace available. Similarly if project work space is not available to the user in shortcut, go to view and select the project window
option. Rebuilding the targets from the project manager and the project workspace window are depicted in the figure 2.13.
Memory models: The memory model determines the default memory type to use for function arguments, automatic variables, and declarations with no explicit memory type specifier. You specify the memory model on the Cx51 compiler command line using the SMALL, COMPACT and LARGE memory model option from the target option. Small model In this model, all variables, by default, reside in the internal data memory of the 8051 system. (This is the same as if they were declared explicitly using the data memory type specifier.) In this memory model, variable access is very efficient. However, all objects, as well as the stack must fit into the internal RAM. Stack size is critical because the real stack size depends upon the nesting depth of the various functions. Typically, if the linker/locator is configured to overlay variables in the internal data memory, the small model is the best model to use. Fig 2.14 shows the small memory model selection.
Small variables in data Ensures very efficient memory Usage for the microcontroller
Fig 2.14 Selecting small memory model Compact Model Using the compact model, all variables, by default, reside in one page of external data memory. (This is as if they were explicitly declared using the pdata memory type specifier.) This memory model can accommodate a maximum of 256 Bytes of variables. The limitation is due to the addressing scheme used, which is indirect through registers R0 and R1 (@R0, @R1). This memory model is not as efficient as the small model; therefore, variable access is not as fast. However, the compact model is faster than the large model.
When using the compact model, the Cx51 compiler accesses external memory with instructions that utilize the @R0 and @R1 operands. R0 and R1 are byte registers and provide only the low-order byte of the address. If the compact model is used with more than 256 bytes of external memory, the high-order address byte (or page) is provided by Port 2 on the 8051 . In this case, you must initialize Port 2 with the proper external memory page to use. This can be done in the startup code. You must also specify the starting address for PDATA to the linker. Fig 2.15 shows the selection of compact memory model.
STARTUP.A51 The STARTUP.A51 file contains the startup code for a Cx51 target program. This source file is located in the LIB directory. Include a copy of this file in each 8051 project that needs custom startup code. The startup code is executed immediately upon reset of the target system and optionally performs the following operations, in order: 1. Clears internal data memory 2. Clears external data memory 3. Clears paged external data memory 4. Initializes the small model reentrant stack and pointer 5. Initializes the large model reentrant stack and pointer 6. Initializes the compact model reentrant stack and pointer
7. Initializes the 8051 hardware stack pointer 8. Transfers control to the main C function Large Model In the large model, all variables, by default, reside in external data memory (up to 64 KBytes). (This is the same as if they were explicitly declared using the xdata memory type specifier.) The data pointer (DPTR) is used for addressing. Memory access through this data pointer is inefficient, especially on variables with a length of two or more bytes. This type of data access mechanism generates more code than the small or compact models.fig 2.16 shows the large memory model selection.
Fig 2.16 Selecting Large memory model Selecting the Code Rom Size and Operating System: SMALL PROGRAM 2K or LESS: CALL and JMP instructions are coded as ACALL and AJMP. The maximum program size may be 2 KBytes. The entire program must be allocated within the 2 Kbyte program memory space.
COMPACT 2K FUNCTIONS AND 64K PROGRAM: CALL instructions are coded as LCALL. JMP instructions are coded as AJMP within a function. The size of a function must not exceed 2 KBytes. The entire program may, however, comprise a maximum of 64 KBytes. The type of application determines whether or not ROM (COMPACT) is more advantageous than ROM (LARGE). Any code space saving advantages in using ROM (COMPACT) must be empirically determined. LARGE 64K PROGRAM: CALL and JMP instructions are coded as LCALL and LJMP. This allows you to use the entire address space without any restrictions. Program size is limited to 64 KBytes. Function size is also limited to 64 KBytes.
Fig 2.17 Selecting Code Rom Size Its better to choose 64K large program size. Since it contains no restrictions. Keil evaluation version does not allow programming than 2k. Full version keil contains the option to use large program size. Only the option small can be used in evaluation version. Fig 1.17 Shows the Selection of the Code ROM Size.
Setting up the operating system: If RTX-51 (RTOS for 8051) operating system is used it can be selected. It can be either full or RTX- TINY depending on the application we are going to develop. If no operating system is used then choose the option none. This is the default condition. Standalone development in 8051 requires no operating system. SO click none in your target option. Fig 2.18 shows the selection of the operating system.
3. Remove a Target from a Project Open the Targets and Groups dialog box using the Targets and Groups command in the Project menu. Click on the desired target in the Available Targets box. Click the Remove Target button. 4. Select a Project Target Open the Targets and Groups dialog box using the Targets and Groups command in the Project menu. Click on the desired target in the Available Targets box. Click the Set as Current Target button. 5. Add File Groups to a Project Open the Targets and Groups dialog box using the Targets and Groups command in the Project menu. Click on the Groups tab. Enter the name of the new group in the Group to Add box. Click the Add button. 6. Remove a File Group from a Project Open the Targets and Groups dialog box using the Targets and Groups command in the Project menu. Click on the Groups tab. Click on the desired group in the Available Groups box. Click the Remove Group button. 7. Add Source Files to a Project To add source files from the Project window in the Project window, right-click on the group to add source files to. Select Add Files to Group from the drop-down menu that appears. To add source files from the Project menu, open the Targets and Groups dialog box using the Targets and Groups command in the Project menu. Click on the Groups tab. Click on the desired group in the Available Groups box. Click the Add Files to Group button.
4. Set Options for a File Projects support three levels of toolset options: Target options, Group options, and File options. You set options for each level using the Project window. To set file options from the Project window In the Project window, right-click on the file to change. Select Options for File from the drop-down menu that appears. To set file options from the Project menu In the Project window, click on the file to change. Select the Options command from the Project menu.
After naming the project as Hello Click save Button Name the Project as Hello
Fig 3.5 Selecting the Target Device Creating a Source File After creating a project file. The Project Work Space with Source Group appears as shown in Fig 3.7. Now we should create a new Source file in C and save it with a file name with extension C or asm. Asm is for assembly source file and Filename.c for C source file. Fig 3.6 shows how to create a new Source file. Go to file option and select new. An untitled file with the name Text1 will appear. Save that file as C file. Similarly the new file can be crated by selecting the shortcut as shown in the fig 3.6.
Saving the Source file as C file: Fig 3.7 Shows the Project work space window. It contains the Target1 and the Source Group added with the target. Now the Source file created by us should be saved with the extension C and then it should be added to the Source group for creating the Source code for the Controller in C language.
Source Group added to The Target by default Save the Source File as C
Fig 3.7 Saving the Source file as C file Writing the Source code for the Controller operation in C: The first step in writing the Source code in C is adding the header file for the target device selected. The header file contains the declarations for that particular controller. The SFR and other registers associated with the controller and the memory area location for that registers. For the target selected in our example the header file is #include <AT89X52.H>. It is common for C series and S series Controllers from Atmel. That is why it is represented by X in the header file name. We can also use the Common header file for 8051 series Controller as #include <reg51.H>. The selection of the header file for the target device is quite simple. Just right Click in the Source file and select the header file name associated with the target. This is shown in the fig 3.8.
Right Click on the Source File Main.c and select the header
Fig 3.8 Selection of the header File Writing the Source code to print Hello World to the Serial Port: The example Source code is to print the String Hello World to the Serial Port of the PC by the microcontroller UART. The printf function used in the source code is declared in the stdio.h header. So include the header. Then it is necessary to write a function to initialize the uart of the Controller for serial communication. That is done in the inituart () function. We need to set the timer 1 in 8 bit auto reload mode, Serial Control register in 8 bit receive and REN enabled mode. Set 9600 baud rate and Run the timer flag. Make sure the TI and RI bit set to 1 for using the Printf statement. Void main() { inituart (); while (1){ printf (Hello World\n); } }
Void inituart() { TMOD=0x20; // 8 bit auto reload mode for timer 0 SCON=0x50; // REN enabled, 8 bit TX/RX mode TH1=0xfd; TR1 = 1; TI=1; } // 9600 baud rate // Run the Timer // Set TI flag for Transmission to be started
Fig 3.9 Source code to Print Hello World. Adding/ Removing the C file from the source group: After Writing the Source code for the Controller, then add the main.c source file to the Source group. Right Click on the Source group in the Project window and select Add files to the Source Group. Now Select the directory in which the Source file is present and select the file we want to add. Here main.c is the file to be added to the source code. After selecting the file Click add and Close the Add files to the Source group window. To remove a file select remove file from the source group. These are clearly illustrated in the fig 3.10 and fig 3.11.
Click add to add the file Close the Add files Window Fig 3.11 Adding main.c to the source group
Fig 3.12 shows that the Project file main.c added to the source group1. After Adding the Source file to the Group. Build the target using the Build option as shown in the Fig 3.12.
Missing Semicolon
The Build output shows the errors and warnings if any in the source code. In the example taken here if you compile the source code, the output has the syntax error as shown in fig 3.13. This is because, in the printf statement, the semicolon is missing. Correct the error and build it again.
No Function prototype
Fig 3.14 Missing Function Prototype Once again the error missing function prototype for inituart() function occurs. We have to declare the function inituart if the function is called below the main function. Now the target should be build again. This is shown in fig 3.14 In C if any function is written below the main function it is required to declare the function prototype below the header file declaration. If the functions are written above the main file it is not necessary to declare the functions. Here the inituart () function is called as a void function below the main function. So it is to be declared as shown in the fig 3.15
After adding the source file, make sure the hex file generation is selected. If it is not selected, Go to Target and right click on the target. Select the options for the target and Click output. In the output window select create hex file and click ok. This is illustrated in the Fig 13.16. After Selecting create hex file option, correcting the source errors, compile the source code again. Now you will see the hex file being generated by the Software. Hello.hex is the hex file generated here. The hex file is usually the Project file name. This is illustrated in fig 3.17
Fig 3.17 View hex file being created Until now we have seen adding a single source file to the Source group. We can add one or more source files to the group and we call functions in another source file from some other source file or the main source file. For that we should create another c file and add to the source group. Here an example is illustrated with name.c as the file name. We are calling a function printname() in the name.c file from main.c In the main function printname() is called which is a function written in another source file. But the function prototype declaration for printname is not given. Also
Missing function prototype for printf occurs. This is due to missing stdio.h header. These errors are shown in the fig 3.18
Fig 3.18 Adding name.c and printname function Now write a function printname in name.c as shown in the fig3.19. Here printf is used, so it is necessary to add the stdio.h header to the file name.c as shown Then it is also necessary to add the function prototype for the function printname() in the main.c file as shown in fig 3.20. This is one way of linking more than one c file together. Other way is adding only the main.c file to the source group and calling other files using the function prototype declaration such as #include name.c as shown in the fig 3.21. We can add n number of source files by declaring the file in the main file as prototype. This is similar to adding the header file in the main file.
Fig 3.21 Adding printname () prototype declaration in main.c With this ends our project creation and compilation. Then it is very important what our source represents? What are the functions and variables used in the sources? What are the source files used in the project? What are all the hardware used and how it is linked with the software? What our application is? These can be made easily understandable to the other developers of your project only by perfect documentation. We can also add documentation to the Source group. The document file is usually the text file. So it can be saved as txt. It cannot be added to the source group1 because source group1 completely involves C and assembly files, i.e the source code files. In which is you add text file it affects the compilation and so error occurs. So we can create another source group to the target 1. Here we can name it as documentation and we can add the text file document to the source group. Right Click on the target 1 and select the target, Groups and files option as shown in fig 3.22
Click ADD to add files to group Type a Source group name as Document or some name
As shown in fig 3.23 and fig 3.24 we can add a group to the target. Here we are adding the group document and document 1 to the target. Already the Source group1 is the group available in the target.
Right Click on the group Document and Select Add files to the Group Document
Fig 3.25 Add a file to the Group Document Now the Group named document and document1 are added to the target along with the source group1. Now the developer can add the document file hello.txt to the document group.
The document file is any text file which can be in any directory location. It is wise to have the text file in the Project directory itself. The project directory is hello here. For that navigate to the Project directory, create a new text file, and Rename it as hello.txt. Type the Documentation part in that file and close the file. After doing all these things add the hello.txt to the document group as shown in fig 3.25 and fig 3.26. Right Click on the Document group and select Add files to the Group Document. This is illustrated in the fig 3.25. Fig 3.27 Shows How to type the Document Content in the Text File Select the file Hello.txt
To Start With Start/ Debug Session: Build the project with the source files for no errors and warnings. Open the Start/Debug Session from the Debug menu. Ctrl F5 is the shortcut for starting or stopping the debug session. After Starting the debug session, open all the peripherals related to the project such as the Serial Window, I/O ports and the Timers from the peripherals menu. The peripheral menu also contains the reset CPU option. The reset CPU option can be used when the user need to start the debug process from the first line of the program. Opening the debug session is shown in the fig 4.1.Peripherals options are explained in fig 4.4 and fig 4.5.
Fig 4.1 Selecting and opening a debug session If the Shortcut for debug window is not selected, select it from the view menu. The serial Window to view the output to the serial port, Watch and Call stack window, Memory window, Disassembly window and other Windows can be selected from the view menu. The status bar, Build tool bar, Project window, Output window also can be selected from the view menu. These are explained clearly in the fig 4.2 shown below. Then the debugging process can be started by single step execution using STEP INTO option in the debug window. In case the user wants to debug a function and not required to debug the program line by line, they can use the step over function. The Program can be run with the Go function. These options for debug can be selected from the shortcut also incase the debug toolbar is enabled. These are explained in fig4.3
Fig 4.6 shows the serial channel, Timer/ Counter1, Step into shortcut option in the debug window, register Window and the other debug windows facilitating the debug option.
Fig 4.6 Debug Windows and peripherals (a) Fig 4.7 shows the values moving into the Timer Control registers, Serial Control register, Serial buffer register, TI and RI flags related to the serial communication. Timer mode selection and the debug pointer position movement step by step. The output of the printf function is printing a string in the serial window, so the user needs to open the serial window1 and then click on the Go function from the debug menu. Fig 4.8 shows the selection of the serial window and disassembly selection window. The disassembly window is the window showing the assembly code and the address where the opcodes related to the C source code developed by the user. The disassembly window and the register window are shown in the fig 4.9 clearly. The user can view the data moving into the registers as shown in the figure 4.9.
Register Values in r1
Fig 4.9 Disassembly window and register window The figure 4.10 shows the Serial window, Hello World and the My name String being print in the serial port. It is being simulated to the user in the serial window. The serial Window is the window representing the serial port of the PC. It is the exact replacement of the Hyperterminal in the Windows OS. Hyperterminal is the Communication terminal of the COM ports in the PC. So what ever data sent to the serial port of the PC can be simulated in the Serial Window of the Keil debugger. The fig 4.10 also Shows the Watch and Call Stack window. It shows the values of the Local variables and the values moved to the variables if a function is called. At any cost the global variables cannot be viewed in the Watch and Call Stack Window.
Serial Window 1
Fig 4.10 Serial window and watch and call Stack window.