Embedded Software Design (EC242) : 2 Year - 2 Semester Lab 01
Embedded Software Design (EC242) : 2 Year - 2 Semester Lab 01
B.Sc. Special Honours Degree in Information Technology (Computer Systems & Networking)
Objectives
After completing this lab you will be able to; 1. Write simple assembly language programs to run on PIC16F microcontrollers. 2. Describe the procedure of creating a project in MPLAB IDE to program PIC16F microcontrollers. 3. Simulate a simple assembly language program using MPLAB IDE and PIC SIMULATOR IDE. 4. Explain the usage of header files in MPLAB projects.
Important You are advised to keep a proper lab notebook to takedown; Code segments you develop during the lab sessions Important facts related to the software and hardware tools used or the lab exercises Calculations performed And any other useful facts.
This notebook will be helpful for you to perform well in the lab assignments to be done in the last 5/6 weeks of the semester. Also this notebook will help you to prepare well for the examinations.
Page 1 of 7
Exercise
Create a new folder in D:\ pic or Z:\pic and name it as lab1_exe1 Open note pad and type the following code and save it as main.asm in the created folder. ;Declaration and configuration of the processor LIST P=16F877A #include p16F877A.inc ;include the header file num1 equ h'26' num2 equ h'27' num3 equ h'28' org 0x00 ;the reset vector goto main main ;putting the value 0xF0 to num1 movlw 0xF0 movwf num1 ;Using AND operation of num1 to mask bits movlw 0x5F andwf num1,f ;using OR operation on num2 to set bits movf num1,w iorwf num2,f ;using X-OR operation on working register to toggle bits movlw 0x01 clrf num3 xorwf num3,f xorwf num3,f endmain goto endmain end
Start -> All programs -> microchip -> MPLAB IDE 7.30 -> MPLABIDE Once MPLAB is open go to project-> project wizard Page 2 of 7
Enter the project name as lab1_exe1 and select the directory where the main.asm file is saved.
Page 4 of 7
Click finish. Add the header file C:\program files\MICROCHIP\MPAS suit\P16F877A.inc Build the project by clicking Change the movlw in line 17 to mov and check the output once built. You can go to the error line by clicking on the error message. Select the MPLAB SIM in the debugger.
The following bar appears. The first button is to run the code the next is to pause the execution. The 3rd button will go through each instruction. The 4th button will allow the user to go through each instruction and go inside subroutines. The 5th button will allow the user to
Page 5 of 7
go through each instruction and execute subroutines with one click. The 6th button will allow the user to come out from a subroutine. The last button will reset the MCU. Use the breakpoint function and set a breakpoint and see what happens. Open the stopwatch in the debugger menu and measure the time.
Open the watch window in the view tab and add the 3 variables num1,num2 and num3 and the working register.
Find out the values of num1, num2, num3 and working register after each instruction.
Page 6 of 7
Num1 movlw 0xF0 movwf num1 movlw 0x5F andwf num1,f movf num1,w iorwf num2,f movlw 0x01 clrf num3 xorwf num3,f xorwf num3,f
Num2
Num3
WREG
Describe the operation of the below instructions. movlw movwf andwf movf iorwf movlw clrf xorwf In order to check how the program responds to external outputs use the stimulus controller in the debugger menu. Update your lab notebooks.
Page 7 of 7