9
POLITEKNIK KUALA TERENGGANU Jabatan Kejuruteraan Elektrik Lab 1 – EC501 Embedded System Applications Objectives : i. To introduce how to build a C18 project ii. To build a project of blinking led using assembly language iii. To introduce the simulation process in Embedded System Preparation : Microchip’s MPLAB IDE and MPLAB C18 compiler are required for this and all the lessons. It is assumed that these have already been installed as instructed in an earlier lesson. Required Resources : Computer with MPLAB, Microchip C18 Compiler, Oshon PIC18 Simulator and PIC18F4550 datasheet Procedure : In this lab a project will be created that is compiled under C18. The program is essentially an empty program shell, but it illustrates the procedure for creating a new C18 project and compiling it under MPLAB. Note: It is highly recommended that each project be saved under a separate directory. This will ensure that all project related files are accessible from the same folder. 1. Create a new folder (use your name & matrix number for folder name) on computer drive (in MyDocuments) then, create a sub- folder and name it Lab1ec501. 2. 2. Open a MPLAB session. 3. Click on the Project Menu and select Project Wizard. asalam.saad,pkt.jun2012

lab 1 ec501

Embed Size (px)

Citation preview

Page 1: lab 1 ec501

POLITEKNIK KUALA TERENGGANUJabatan Kejuruteraan Elektrik

Lab 1 – EC501 Embedded System ApplicationsObjectives : i. To introduce how to build a C18 project

ii. To build a project of blinking led using assembly language iii. To introduce the simulation process in Embedded System

Preparation : Microchip’s MPLAB IDE and MPLAB C18 compiler are required for this and all the lessons. It is assumed that these have already been installed as instructed in an earlier lesson.

Required Resources : Computer with MPLAB, Microchip C18 Compiler, Oshon PIC18 Simulator and PIC18F4550 datasheet

Procedure : In this lab a project will be created that is compiled under C18. The program is essentially an empty program shell, but it illustrates the procedure for creating a new C18 project and compiling it under MPLAB.

Note: It is highly recommended that each project be saved under a separate directory. This will ensure that all project related files are accessible from the same folder.

1. Create a new folder (use your name & matrix number for folder name) on computer drive (in MyDocuments) then, create a sub-folder and name it Lab1ec501.

2. 2. Open a MPLAB session.

3. Click on the Project Menu and select Project Wizard.

asalam.saad,pkt.jun2012

Page 2: lab 1 ec501

4. From the Welcome dialog, click on Next to proceed.

5. Having selected the correct device, PIC18F4550, clicks the Next button.

6. Step two of the dialog box opens, displaying the current language tool suite in effect. Make sure to select Microchip C18 Toolsuite from the dropdown menu.

asalam.saad,pkt.jun2012

Page 3: lab 1 ec501

7. This step requires the user to create new file for the project. Click browse button and select your personal ec501 lab1 folder and use “<your name>+ec501 lab1” as a file name. Example Abdul Salam bin Saad ec501 lab1.

8. Click next button for the following step until finish button. The following screenshot is the expected result.

asalam.saad,pkt.jun2012

Page 4: lab 1 ec501

9. Click ‘New’ from the File tab and type the following instruction set

asalam.saad,pkt.jun2012

;politeknik kuala terengganu;ec501;lab 1 - pic18f4550 led blinking

#include p18f4550.inc

CONFIG WDT=OFF; disable watchdog timerCONFIG LVP = OFF ; Low-Voltage programming disabled (necessary for debugging)CONFIG FOSC = INTOSCIO_EC ; Internal oscillator, port function on RA6

reg1 equ 0x28org 0

movlw b'00001111'movwf TRISD

loop bsf PORTD,6call delaybcf PORTD,6call delaygoto loop

delay movlw 0x1e ; delay subroutinemovwf reg1

d1 decf reg1bnz d1returnend

Page 5: lab 1 ec501

10. Then, click Save File and use ‘ec501 lab1.asm’ as a file name. Please tick the checkbox ‘Add File To Project’ at the bottom.

asalam.saad,pkt.jun2012

Page 6: lab 1 ec501

11. Click ‘Make’ button from the tab menu and select ‘Absolute’ button when it appear. This will compile the assembly language code.

12. If there is no error, the following is the expected result.

13. Open the Oshon PIC18 Simulator IDE program. Click ‘Load Program’ from File menu and select ‘ec501 lab1.HEX’ from our lab1 folder. Then click at the white box beside the ‘Microcontroller’ box and choose ‘PIC18F4550’. Other option remains the same.

asalam.saad,pkt.jun2012

Page 7: lab 1 ec501

14. From the ‘Tools’ tab menu, select ‘Microcontroller View’.

15. From the ‘Rate’ tab menu, select ‘Normal’. This is the simulation speed controller. Then, we can start the simulation by click the ‘Start’ from the ‘Simulation’ tab.

16. Observe the simulation output.

asalam.saad,pkt.jun2012

Page 8: lab 1 ec501

Discussion i. Observes the blinking speed of LED, suggest how to increase and decrease the speed of the blinking. Show the instruction in assembly language.

ii. The Embedded System application need 5 LED to blink at the same time. As an Embedded System Engineer, show how the modified code to make 5 LED from any pin at PORTD to blink.

Conclusion : write your lab1 conclusions.

asalam.saad,pkt.jun2012