SlideShare a Scribd company logo
12
Most read
16
Most read
18
Most read
FACULTY OF ELECTRICAL AND ELECTRONIC
             ENGINEERING



 COMPUTER ADDED DESIGN LABORATORY



    LABORATORY INSTRUCTION SHEET



                         DAE32203 / DEK3133
 Subject Code and Name
                         MICROCONTROLLER

   Experiment Code       01

                         Introduction to MPLAB, PROTEUS and
    Experiment Title     MikroC

     Course Code         DET/DEE/DEX
Document
                                                   RPP-05              Page Number             1 of 18
                    Reference No.
                                                                       Edition                    1
                    Document Title       LABORATORY                      Revision No.             1
                                         PRACTICUM                      Effective Date        JULY 2010
                                                                       Amendment Date         JULY 2010


                                    MAKLUMAT MATAPELAJARAN

SUBJECT                                  : DAE32203 / DEK 3133 MICROCONTROLLER

TITLE                                     : LAB 1 – Introduction to MPLAB, Proteus and MicroC.

GOAL                                     : To expose student with MPLAB, Proteus and MicroC software


1. OBJECTIVES


At the end of this lab session, students will :

         (i) Understand the operation and the basic use of MPLAB, Micro C and Proteus.

         (ii) Use MPLAB and Micro C to write program and assembly language for PIC Microcontroller.

         (iii) Use MPLAB SIM and Proteus to simulate assembly and C language for PIC Microcontroller.



2. SINOPSYS


MPLAB and Micro C is a software package easy writing process and development of assembly and C
language program for PIC Microcontroller. In this lab, student will have the exposure on MPLAB and
Micro C software and learn how to manage project by using MPLAB starting and Micro C from assembly
and C language program until simulation by Proteus.




Disediakan Oleh:                                              Disahkan Oleh:

Tandatangan         :                                         Tandatangan       :

Nama                : Mohamad Bin Hj. Md. Som                 Nama              : Shamsul Bin Mohamad

Tarikh              : July-2010                               Tarikh            : July-2010
Document
                                                 RPP-05             Page Number            2 of 18
                    Reference No.
                                                                    Edition                   1
                    Document Title   LABORATORY                       Revision No.            1
                                     PRACTICUM                       Effective Date       JULY 2010
                                                                    Amendment Date        JULY 2010


 3. THEORY

A) MPLAB
MPLAB is comprehensive software that has editing, project management and design in it. It used in
development of embedded system application using microcontroller Microchip PICmicro and PIC.
Assembly language is a language that used for programming microcontroller. Before we programmed
these assembly language instructions into microcontroller memory, it has to convert to machine language
so that microcontroller easily understands. This conversion is done by software so called assembler in
MPLAB. This process is described in Figure 1.




                                                 Figure 1


In the MPLAB assembly language programming, numbers usually represent decimal, binary and
hexadecimal. For example, decimal number 240 is written by:
                       240           - decimal
                       0xF0          - hexadecimal
                       b’11110000’ - binary


Basic elements in assembly language are:
      Label
      Instruction
      Operand
      Comment
Document
                                                    RPP-05                Page Number               3 of 18
                      Reference No.
                                                                          Edition                     1
                      Document Title     LABORATORY                         Revision No.              1
                                         PRACTICUM                         Effective Date         JULY 2010
                                                                          Amendment Date          JULY 2010

B) PROTEUS
    ISIS provides the development environment for PROTEUS VSM, our revolutionary interactive system
level simulator. This software combines mixed mode circuit simulation, micro-processor models and
interactive component models to allow the simulation of complete micro-controller based designs.
ISIS provides the means to enter the design in the first place, the architecture for real time interactive
simulation and a system for managing the source and object code associated with each project. In addition,
a number of graph objects can be placed on the schematic to enable conventional time, frequency and
swept variable simulation to be performed.


Major features of PROTEUS VSM include:
·         True Mixed Mode simulation based on Berkeley SPICE3F5 with extensions for digital simulation
and
          true mixed mode operation.
·         Support for both interactive and graph based simulation.
·         CPU Models available for popular microcontrollers such as the PIC and 8051 series.
·         Interactive peripheral models include LED and LCD displays, a universal matrix keypad, an RS232
          terminal and a whole library of switches, pots, lamps, LEDs etc.


MikroC is a powerful, feature rich development tool for PICmicros. It is designed to provide the
programmer with the easiest possible solution for developing applications for embedded systems,
without compromising performance or control.



C) MikroC IDE

PIC and C fit together well: PIC is the most popular 8-bit chip in the world, used in a wide variety
of applications, and C, prized for its efficiency, is the natural choice for developing embedded
systems. mikroC provides a successful match featuring highly advanced IDE, ANSI compliant
compiler, broad set of hardware libraries, comprehensive documentation, and plenty of ready-to-
run examples.

    Features :

    mikroC allows you to quickly develop and deploy complex applications:

      •    Write your C source code using the built-in Code Editor (Code and Parameter Assistants,
           Syntax Highlighting, Auto Correct, Code Templates, and more…)
      •    Use the included mikroC libraries to dramatically speed up the development: data
           acquisition, memory, displays, conversions, communications… Practically all P12, P16,
Document
                                                   RPP-05              Page Number             4 of 18
                        Reference No.
                                                                       Edition                   1
                        Document Title   LABORATORY                      Revision No.            1
                                         PRACTICUM                      Effective Date       JULY 2010
                                                                       Amendment Date        JULY 2010

           and P18 chips are supported.
      •    Monitor your program structure, variables, and functions in the Code Explorer.
      •    Generate commented, human-readable assembly, and standard HEX compatible with all
           programmers.
      •    Inspect program flow and debug executable logic with the integrated Debugger.




4.        EQUIPMENT LIST
          (1)     Personal Computer (PC)
          (2)     MPLAB Software
          (3)     Mikro C Software
          (4)     Proteus Software




5. PROCEDURE


5.1 WRITE ASSEMBLY CODE AND SIMULATE USING MPLAB.


(A)       Starting New Project

1.        Start MPLAB software. Click start > Microchip > MPLAB IDE
2.        MPLAB work area will appear; shows in Figure 1-1.




                                                  Figure 1-1


3.        To start a new project, click Project > new. New windows of New Project will appear; shows in
          Figure 1-2.
Document
                                                      RPP-05                   Page Number        5 of 18
                      Reference No.
                                                                               Edition               1
                      Document Title      LABORATORY                             Revision No.        1
                                          PRACTICUM                             Effective Date   JULY 2010
                                                                               Amendment Date    JULY 2010



4.      Fill in Project Name as Lab1 and Project directory with c:lab1 or use Browse to choose existence
        directory.




                                                    Figure 1-2


5.      To write PIC assembly language program, click File > New. New windows editing will appear.
6.      Write down the program 1.1 below and save it by name as lab1.asm
;**************************************************************************
PORTA         EQU 05h    ;This tells the assembler where the address of PORTA,
PORTB         EQU 06h    ;PORTB, STATUS and ADCON1
TRISA         EQU 85h    ;This Tell the assembler where the address of ports Direction of,
TRISB         EQU 86h    ;TRISA and TRISB.
STATUS        EQU 03h
ADCON1        EQU 9Fh    ;Address of Type of data whether Digital/Analog at PORTA
RP1           EQU 6      ;Bit 6 and 5 for bank selection in STATUS register.
RP0           EQU 5      ;To select bank 0, RP1 = 0 and RP0 = 0 {PORTA and PORTB}
                         ;To select bank 1, RP1 = 0 and RP0 = 1 {TRISA,TRISB & ADCON1}
                         ;To select bank 2, RP1 = 1 and RP0 = 0
                         ;To select bank 3, RP1 = 1 and RP0 = 1
;**************************************************************************
        ORG 00h          ;Assembler is now set to address 0 where the main
                         ;program is placed


;********************PIC SETUP********************************************
        BSF              STATUS,RP0 ;Select bank 1(To use TRISA,B and ADCON1)
        MOVLW            B'00000110'    ;Load literal value=6 into W register


        MOVWF            ADCON1         ;Move the literal value into ADCON1 register.
                                        ;Now PORTA is configured as digital input
        MOVLW            B'00000000'    ;0 is loaded into W register
        MOVWF            TRISB          ;Now all PORTB bits are set as OUTPUT
Document
                                                 RPP-05                  Page Number          6 of 18
                  Reference No.
                                                                         Edition                1
                  Document Title     LABORATORY                            Revision No.         1
                                     PRACTICUM                            Effective Date    JULY 2010
                                                                         Amendment Date     JULY 2010


      MOVLW           B'11111111'   ;move binary value 11111111 to register W
      MOVWF           TRISA         ;Now All PORTA bits are set as INPUT
;*******************START OF MAIN PROGRAM*************************
      BCF             STATUS,RP0        ;Back to bank 0;(To use PORTA and PORTB)
      CLRF            PORTB             ;Set PORTB output is 0
LOOP BTFSS            PORTA,4           ;Bit test PORTA bit 4, if SET skip next line
      GOTO            ON                ;Goto ON if button is pressed
OFF   BCF             PORTB,0           ;LED is OFF when button at PORTA is not pressed.
      GOTO            LOOP              ;Go back and test the button again
ON    BSF             PORTB,0           ;As PORTA input is 0, mean button is pressed so
                                        ;LED at PORTB bit 0 goes ON
      GOTO            LOOP              ;Go back to LOOP and test the button again
      END                               ;End of code.


7.    Insert file programming into this project by clicking right button Source File which shows in Figure
      1-3. Choose lab1.asm file that has written.




                                                Figure 1-3
Document
                                                   RPP-05               Page Number                7 of 18
                    Reference No.
                                                                        Edition                       1
                    Document Title     LABORATORY                         Revision No.                1
                                       PRACTICUM                         Effective Date           JULY 2010
                                                                        Amendment Date            JULY 2010



8.      To assemble the program, firstly we have to choose types of microcontroller by clicking Configure
        > Select Device, choose 16F877A.


9.    Select Configure > Configuration Bits and set as shown in a figure below.




10.     Click Project > Built All to assemble the program. If there is no error, then BUILD SUCCEEDED
        message will appear. If there is an error, then Error message and Location will appear.


(B)     Project Simulation


1.      To start Simulation, click Debugger > Select Tool > MPLAB SIM. Observe the changes at the
        MPLAB interface. List down the changes.


2.      Click View > Watch. Watch windows (Figure 1-4) will appear. First, from pull down menu, choose
        PORTA and click Add SFR button. Then choose PORTB and click Add SFR button again.




                                                 Figure 1-4
Document
                                              RPP-05              Page Number             8 of 18
                Reference No.
                                                                  Edition                   1
                Document Title     LABORATORY                       Revision No.            1
                                   PRACTICUM                       Effective Date       JULY 2010
                                                                  Amendment Date        JULY 2010




3.   Click Debugger > Animate. Observe Watch window and also Lab1.asm program window. Explain
     your observation.


4.   Click Debugger > Halt to stop the simulation process. Click Debugger > Reset > MCLR to reset the
     program.


5.   Click Debugger > Stimulus Controller > New Workbook >Asynch. A window in Figure 1-5 will
     appear. At Pin/SFR column, choose RA4 pin and at Action column choose Set Low. Observe any
     changes at Watch window after Animate button and Fire button is pressed. Observe any changes.




                                            Figure 1-5
Document
                                                    RPP-05                Page Number               9 of 18
                    Reference No.
                                                                          Edition                    1
                    Document Title      LABORATORY                          Revision No.             1
                                        PRACTICUM                          Effective Date        JULY 2010
                                                                          Amendment Date         JULY 2010



5.2 SIMULATION THE HEX FILE USING PROTEUS


1. Open Proteus by clicking START > ALL PROGRAM > PROTEUS 7 PROFESIONAL > ISIS 7
   PROFESIONAL .




                                       Figure 1-6




2. Proteus work area will appear; shows in Figure 1-7. Select button “ P” and follow the next instructions.




                                                Figure 1-7
Document
                                                 RPP-05               Page Number             10 of 18
                   Reference No.
                                                                      Edition                   1
                   Document Title     LABORATORY                        Revision No.            1
                                      PRACTICUM                        Effective Date       JULY 2010
                                                                      Amendment Date        JULY 2010

3. A window in Figure 1-8 will appear.




                                         Figure 1-8

4. Select instruction bellows and doudle click your left mouse to input components inside category
window as shown in figure 1-9.

                   a) MICROPROCESSORS > PIC16F877A
                   b) RESISTORS > 3 WATT1K
                   c) OPTOELECTRONICS > LED-BIBY
                   d) SWITCHES & RELAYS > BUTTON




                                          Figure 1-9
Document
                                                 RPP-05                Page Number             11 of 18
                   Reference No.
                                                                       Edition                    1
                   Document Title     LABORATORY                         Revision No.             1
                                      PRACTICUM                         Effective Date        JULY 2010
                                                                       Amendment Date         JULY 2010

5. Drag and drop components by clicking at “DEVICES” window to working window as shown at
   figure 1-10.




                                                Figure 1-10

6. Right click mouse and select properties for rotate the components to your suitable positions as shown at
   figure 1-11.




                                         Figure 1-11


7. Connect and wiring all components.

8. Click “Terminals Mode” button to input ‘POWER’ and ‘GROUND’ to your working space as shown at
   figure 1-12.




                                              Figure 1-12
Document
                                                 RPP-05               Page Number            12 of 18
                  Reference No.
                                                                      Edition                   1
                  Document Title     LABORATORY                         Revision No.            1
                                     PRACTICUM                         Effective Date       JULY 2010
                                                                      Amendment Date        JULY 2010



9. Arrange your components to suitable position and completed your work with the correct connections as
   figure 1-13.




                                                  Figure 1-12

10.    Save your project at different folder and named it Projek1_circuit as figure 1-14.




                                             Figure 1-13
Document
                                               RPP-05              Page Number             13 of 18
                 Reference No.
                                                                   Edition                    1
                 Document Title     LABORATORY                       Revision No.             1
                                    PRACTICUM                       Effective Date        JULY 2010
                                                                   Amendment Date         JULY 2010




                                              Figure 1-14

11. From your working space, double click your PIC16F877A and follow the instructions number inside
    figure 1-15. Setting your Edit Component window by following the step given. 1st setting frequency
    to 4 MHz, 2nd click at browse button and select the hex file from the project folder created by
    compiler (MPLAB or Micro C ) . 3rd click “OK”.




                                                 Figure 1-15
Document
                                                 RPP-05              Page Number          14 of 18
                  Reference No.
                                                                     Edition                1
                  Document Title      LABORATORY                       Revision No.         1
                                      PRACTICUM                       Effective Date    JULY 2010
                                                                     Amendment Date     JULY 2010



11. Click DEBUG > EXECUTE to simulate your program and click DEBUG > STOP ANIMATION to
    stop the program. From your window project, you can animate your program by clicking suitable
    button as shown in figure 1.16. Explain your observation.


                                              Figure 1-16

12. The complete circuit as shown as Figure 1-17.




                                               Figure 1-17
13. To see detail what happen to PORTA, PORTB and others register, go to Debug>watch window and
      add the register that you want to watch like a figure below.




                                               Figure 1-18
Document
                                             RPP-05               Page Number             15 of 18
                Reference No.
                                                                  Edition                    1
                Document Title   LABORATORY                         Revision No.             1
                                 PRACTICUM                         Effective Date        JULY 2010
                                                                  Amendment Date         JULY 2010



5.3 PROGRAMMING USING C LANGUAGE


  1. Open Mikro C compiler as shown in figure 1-18.




                                     Figure 1-18

  2. Create a new project



                                     • Project wizard dialog will appear – fill the dialog with
                                         appropriate settings for your project
                                     • Enter a name for your new project
                                     • Choose project path,
                                     • Enter short text which describes your project
                                         (this is optional)
                                     •   Choose the microcontroller from drop-down menu
                                     •   Set the device clock by entering the value in edit box
                                          (set to 4Mhz)
                                     •   Set configuration bits (device flags) by clicking default
                                     •   After you have set up your project, click OK to continue.
Document
                                             RPP-05                Page Number             16 of 18
              Reference No.
                                                                   Edition                    1
              Document Title      LABORATORY                         Revision No.             1
                                  PRACTICUM                         Effective Date        JULY 2010
                                                                   Amendment Date         JULY 2010




3. Write the code:

   ‐   Compiler will create the project file and an accompanying source file, named same as your
       project. This source file will be automatically opened in the code editor, so you can write the
       source code. Picture below is the code editor.
Document
                                            RPP-05               Page Number            17 of 18
              Reference No.
                                                                 Edition                   1
              Document Title     LABORATORY                        Revision No.            1
                                 PRACTICUM                        Effective Date       JULY 2010
                                                                 Amendment Date        JULY 2010



4. Type the source code below into the code editor:




5. Save the file by clicking on the save icon. To compile the source code select Project->Build from
   the drop-down menu, or click the Build Icon.

6. Compiler will generate output files in the project folder. There should be 4 new files:
   project1.asm, project1.lst, project1.mcl and project1.hex. The file name with *.hex file will be
   used to burn into PIC flash memory or can be load into simulation software (Proteus) to simulate
   the output.
Document
                                                   RPP-05     Page Number            18 of 18
                     Reference No.
                                                              Edition                   1
                     Document Title     LABORATORY              Revision No.            1
                                        PRACTICUM              Effective Date       JULY 2010
                                                              Amendment Date        JULY 2010



6.      REPORT PREPARATION AND SCHEMA.

(1)     2 persons for 1 report.


(2)     Due date to send report is 1 weeks after lab date.


(3)     Report schema following below requirements:
      • Lab report cover sheet for 1st page.
      • Objective, theory, equipments for the 2nd page. (5)                 ( 5 Mark )
      • Procedure lab sheet . (30)
              1. Program 1.1 by MPLAB.                                      ( 5 Mark )
              2. Proteus - Circuit diagram                                  ( 10 Mark )
              3. Program 1.2 by Micro C.                                        ( 5 Mark )
              4. Flow chart of Mikro C code.                                ( 10 Mark )


      • Observations. (35)
               1. Observations when using MPLAB software.                       ( 15 Mark )
               2. Observations when using Proteus software.                     ( 10 Mark )
               3. Observations when using Micro C software.                     ( 10 Mark )


      • Discussions. (20)
               1. Result by using MPLAB software                                ( 10 Mark )
               2. Result by using Proteus software                              ( 5 Mark )
               3. Result by using Micro C software                              ( 5 Mark )


      • Conclusions. (10)                                                        ( 10 Mark )

More Related Content

What's hot (20)

PPTX
Ppt 3 - IOT logic design
udhayakumarc1
 
PPT
Electronic Eye Controlled Security System
Emran Ahmed
 
PPTX
Smart Homes.pptx
Nawroz University
 
PPTX
Lecture 15
vishal choudhary
 
PPTX
Arduino Simulation_Basic_Day-1 (Fritzing)
Redwan Ferdous
 
PPTX
Smart agriculture system using IOT
chetana chaudhary
 
PDF
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Selvaraj Seerangan
 
PPTX
Iot logical design
ShilpaKrishna6
 
PDF
A Project Report on RFID Based Attendance System.pdf
Sudipto Krishna Dutta
 
PPTX
AN ADVANCED DOOR-KNOCK AID FOR DEAF
KARIMU KHATWABI
 
PDF
Internet of Things (IoT) based Solar Energy System security considerations
Bohitesh Misra, PMP
 
PPTX
IOT ARDUINO UNO.pptx
SanaMateen7
 
PPTX
Presentation of automatic street light
Prince Mandal
 
PPTX
Presentation on IoT Based Home Automation using android & NodeMCU
Souvik Kundu
 
PPTX
Password Base Door Lock
Md Rezaul Karim Palash
 
PPT
Interrupts for PIC18
raosandy11
 
PDF
Controlling a home appliance using IR remote
Chittaranjan Baliarsingh
 
PPTX
Landslide Detection using Arduino
Shri Ram G
 
PPT
Automatic Night Light
Shihab Hasnine
 
DOCX
Report (Electromagnetic Password Door Lock System)
Siang Wei Lee
 
Ppt 3 - IOT logic design
udhayakumarc1
 
Electronic Eye Controlled Security System
Emran Ahmed
 
Smart Homes.pptx
Nawroz University
 
Lecture 15
vishal choudhary
 
Arduino Simulation_Basic_Day-1 (Fritzing)
Redwan Ferdous
 
Smart agriculture system using IOT
chetana chaudhary
 
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Selvaraj Seerangan
 
Iot logical design
ShilpaKrishna6
 
A Project Report on RFID Based Attendance System.pdf
Sudipto Krishna Dutta
 
AN ADVANCED DOOR-KNOCK AID FOR DEAF
KARIMU KHATWABI
 
Internet of Things (IoT) based Solar Energy System security considerations
Bohitesh Misra, PMP
 
IOT ARDUINO UNO.pptx
SanaMateen7
 
Presentation of automatic street light
Prince Mandal
 
Presentation on IoT Based Home Automation using android & NodeMCU
Souvik Kundu
 
Password Base Door Lock
Md Rezaul Karim Palash
 
Interrupts for PIC18
raosandy11
 
Controlling a home appliance using IR remote
Chittaranjan Baliarsingh
 
Landslide Detection using Arduino
Shri Ram G
 
Automatic Night Light
Shihab Hasnine
 
Report (Electromagnetic Password Door Lock System)
Siang Wei Lee
 

Viewers also liked (20)

PDF
Lab 2 microcontroller
mkazree
 
PDF
Lab 3 microcontroller
mkazree
 
PDF
Lab 4 microcontroller
mkazree
 
PDF
Lab 5 microcontroller
mkazree
 
PDF
Lab 6 microcontroller
mkazree
 
PDF
Ch2 microcontroller architecture
Ahmad Sidik
 
PDF
Tutorial chapter 2 robotic
mkazree
 
PPT
Chp6 assembly language programming for pic copy
mkazree
 
PDF
Embedded system (Chapter 2) part A
Ikhwan_Fakrudin
 
PDF
Coal Fired Power Plant
mkazree
 
PPT
Chp4 introduction to the pic microcontroller copy
mkazree
 
PPTX
Embedded system (Chapter )
Ikhwan_Fakrudin
 
PDF
Projek rekabentuk1
mkazree
 
DOC
Chapter 4 synchronous machine
mkazree
 
DOC
Tutorial chapter 3 robotic
mkazree
 
DOC
Tutorial 2 amplitude modulation
mkazree
 
DOC
120102011
mkazree
 
PPT
Chapter 5 fm receivers
mkazree
 
PDF
PIC microcontroller review
Mohsen Sarakbi
 
DOC
Foster-seely and Ratio Detector (Discriminator )
mkazree
 
Lab 2 microcontroller
mkazree
 
Lab 3 microcontroller
mkazree
 
Lab 4 microcontroller
mkazree
 
Lab 5 microcontroller
mkazree
 
Lab 6 microcontroller
mkazree
 
Ch2 microcontroller architecture
Ahmad Sidik
 
Tutorial chapter 2 robotic
mkazree
 
Chp6 assembly language programming for pic copy
mkazree
 
Embedded system (Chapter 2) part A
Ikhwan_Fakrudin
 
Coal Fired Power Plant
mkazree
 
Chp4 introduction to the pic microcontroller copy
mkazree
 
Embedded system (Chapter )
Ikhwan_Fakrudin
 
Projek rekabentuk1
mkazree
 
Chapter 4 synchronous machine
mkazree
 
Tutorial chapter 3 robotic
mkazree
 
Tutorial 2 amplitude modulation
mkazree
 
120102011
mkazree
 
Chapter 5 fm receivers
mkazree
 
PIC microcontroller review
Mohsen Sarakbi
 
Foster-seely and Ratio Detector (Discriminator )
mkazree
 
Ad

Similar to Lab 1 microcontroller (20)

PDF
18CSL48.pdf
Narayan AB
 
PDF
ARCHITECTURE OF 80386 IN DETAIL SPPU COMPUTER ENGINEERING SEM 4
swatij13
 
DOC
report_barc
siontani
 
PDF
Pic microcontrollers for_beginners
Praveen Chary
 
PPTX
01 python introduction
Tamer Ahmed Farrag, PhD
 
PDF
All chapter download Test Bank for Python for Everyone, 2nd Edition
sevonmatul6p
 
PDF
engineering-edge-vol.-5-iss.-2-LR
Natasha Antunes
 
PPT
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
libpf
 
PDF
IRJET- Why Python Rocks for Research....???
IRJET Journal
 
PDF
Codesmells for AspectJ
Sander Mak (@Sander_Mak)
 
PDF
Microcontroller pic 16f877 addressing modes instructions and programming
Nilesh Bhaskarrao Bahadure
 
PDF
Uniface delivers 3GL app in less time, using less code
Helen Xu
 
PDF
International Journal of Engineering and Science Invention (IJESI)
inventionjournals
 
DOCX
OS LAB MANUAL TO PRINT operating systems
truparanicse
 
PDF
Parallel Vector Tile-Optimized Library (PVTOL) Architecture-v3.pdf
Slide_N
 
PPTX
Python monorepos what, why and how (shared)
benjyw
 
PPTX
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
Brian Brazil
 
PPTX
1.Basic_Syntax
Mohamed Essam
 
PPTX
Python basic syntax
Mohamed Essam
 
PDF
Python Programmimg language in Gurugram
digitallynikitasharm
 
18CSL48.pdf
Narayan AB
 
ARCHITECTURE OF 80386 IN DETAIL SPPU COMPUTER ENGINEERING SEM 4
swatij13
 
report_barc
siontani
 
Pic microcontrollers for_beginners
Praveen Chary
 
01 python introduction
Tamer Ahmed Farrag, PhD
 
All chapter download Test Bank for Python for Everyone, 2nd Edition
sevonmatul6p
 
engineering-edge-vol.-5-iss.-2-LR
Natasha Antunes
 
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
libpf
 
IRJET- Why Python Rocks for Research....???
IRJET Journal
 
Codesmells for AspectJ
Sander Mak (@Sander_Mak)
 
Microcontroller pic 16f877 addressing modes instructions and programming
Nilesh Bhaskarrao Bahadure
 
Uniface delivers 3GL app in less time, using less code
Helen Xu
 
International Journal of Engineering and Science Invention (IJESI)
inventionjournals
 
OS LAB MANUAL TO PRINT operating systems
truparanicse
 
Parallel Vector Tile-Optimized Library (PVTOL) Architecture-v3.pdf
Slide_N
 
Python monorepos what, why and how (shared)
benjyw
 
OpenMetrics: What Does It Mean for You (PromCon 2019, Munich)
Brian Brazil
 
1.Basic_Syntax
Mohamed Essam
 
Python basic syntax
Mohamed Essam
 
Python Programmimg language in Gurugram
digitallynikitasharm
 
Ad

More from mkazree (20)

DOC
Contoh kertas kerja program
mkazree
 
PPT
Communication Engineering - Chapter 6 - Noise
mkazree
 
PDF
The Electronic Hobby Kit
mkazree
 
PPT
Dek3223 chapter 2 robotic
mkazree
 
PPT
Chapter 3 am receivers
mkazree
 
PPT
Dek3223 chapter 3 industrial robotic
mkazree
 
PPT
Chapter 3 am receivers
mkazree
 
PPT
Comm introduction
mkazree
 
PPT
Chapter2 cont
mkazree
 
PPT
Chapter 2 amplitude_modulation
mkazree
 
DOC
Chapter5 dek 3143 dae 32303 9 (nota tambahan)
mkazree
 
DOC
Ii20102011
mkazree
 
DOC
Chapter 3 induction machine
mkazree
 
DOC
Chapter 2 transformer new
mkazree
 
DOC
Chapter 1 dc machines new
mkazree
 
PPT
Chp7 pic 16 f84 interfacing - copy
mkazree
 
PPT
Chp1 68000 microprocessor copy
mkazree
 
PPT
Chp5 pic microcontroller instruction set copy
mkazree
 
PPT
Chp3 designing bus system, memory & io copy
mkazree
 
PPT
Chp2 introduction to the 68000 microprocessor copy
mkazree
 
Contoh kertas kerja program
mkazree
 
Communication Engineering - Chapter 6 - Noise
mkazree
 
The Electronic Hobby Kit
mkazree
 
Dek3223 chapter 2 robotic
mkazree
 
Chapter 3 am receivers
mkazree
 
Dek3223 chapter 3 industrial robotic
mkazree
 
Chapter 3 am receivers
mkazree
 
Comm introduction
mkazree
 
Chapter2 cont
mkazree
 
Chapter 2 amplitude_modulation
mkazree
 
Chapter5 dek 3143 dae 32303 9 (nota tambahan)
mkazree
 
Ii20102011
mkazree
 
Chapter 3 induction machine
mkazree
 
Chapter 2 transformer new
mkazree
 
Chapter 1 dc machines new
mkazree
 
Chp7 pic 16 f84 interfacing - copy
mkazree
 
Chp1 68000 microprocessor copy
mkazree
 
Chp5 pic microcontroller instruction set copy
mkazree
 
Chp3 designing bus system, memory & io copy
mkazree
 
Chp2 introduction to the 68000 microprocessor copy
mkazree
 

Recently uploaded (20)

PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
epi editorial commitee meeting presentation
MIPLM
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Horarios de distribución de agua en julio
pegazohn1978
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Difference between write and update in odoo 18
Celine George
 
Introduction presentation of the patentbutler tool
MIPLM
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 

Lab 1 microcontroller

  • 1. FACULTY OF ELECTRICAL AND ELECTRONIC ENGINEERING COMPUTER ADDED DESIGN LABORATORY LABORATORY INSTRUCTION SHEET DAE32203 / DEK3133 Subject Code and Name MICROCONTROLLER Experiment Code 01 Introduction to MPLAB, PROTEUS and Experiment Title MikroC Course Code DET/DEE/DEX
  • 2. Document RPP-05 Page Number 1 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 MAKLUMAT MATAPELAJARAN SUBJECT : DAE32203 / DEK 3133 MICROCONTROLLER TITLE : LAB 1 – Introduction to MPLAB, Proteus and MicroC. GOAL : To expose student with MPLAB, Proteus and MicroC software 1. OBJECTIVES At the end of this lab session, students will : (i) Understand the operation and the basic use of MPLAB, Micro C and Proteus. (ii) Use MPLAB and Micro C to write program and assembly language for PIC Microcontroller. (iii) Use MPLAB SIM and Proteus to simulate assembly and C language for PIC Microcontroller. 2. SINOPSYS MPLAB and Micro C is a software package easy writing process and development of assembly and C language program for PIC Microcontroller. In this lab, student will have the exposure on MPLAB and Micro C software and learn how to manage project by using MPLAB starting and Micro C from assembly and C language program until simulation by Proteus. Disediakan Oleh: Disahkan Oleh: Tandatangan : Tandatangan : Nama : Mohamad Bin Hj. Md. Som Nama : Shamsul Bin Mohamad Tarikh : July-2010 Tarikh : July-2010
  • 3. Document RPP-05 Page Number 2 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 3. THEORY A) MPLAB MPLAB is comprehensive software that has editing, project management and design in it. It used in development of embedded system application using microcontroller Microchip PICmicro and PIC. Assembly language is a language that used for programming microcontroller. Before we programmed these assembly language instructions into microcontroller memory, it has to convert to machine language so that microcontroller easily understands. This conversion is done by software so called assembler in MPLAB. This process is described in Figure 1. Figure 1 In the MPLAB assembly language programming, numbers usually represent decimal, binary and hexadecimal. For example, decimal number 240 is written by: 240 - decimal 0xF0 - hexadecimal b’11110000’ - binary Basic elements in assembly language are: Label Instruction Operand Comment
  • 4. Document RPP-05 Page Number 3 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 B) PROTEUS ISIS provides the development environment for PROTEUS VSM, our revolutionary interactive system level simulator. This software combines mixed mode circuit simulation, micro-processor models and interactive component models to allow the simulation of complete micro-controller based designs. ISIS provides the means to enter the design in the first place, the architecture for real time interactive simulation and a system for managing the source and object code associated with each project. In addition, a number of graph objects can be placed on the schematic to enable conventional time, frequency and swept variable simulation to be performed. Major features of PROTEUS VSM include: · True Mixed Mode simulation based on Berkeley SPICE3F5 with extensions for digital simulation and true mixed mode operation. · Support for both interactive and graph based simulation. · CPU Models available for popular microcontrollers such as the PIC and 8051 series. · Interactive peripheral models include LED and LCD displays, a universal matrix keypad, an RS232 terminal and a whole library of switches, pots, lamps, LEDs etc. MikroC is a powerful, feature rich development tool for PICmicros. It is designed to provide the programmer with the easiest possible solution for developing applications for embedded systems, without compromising performance or control. C) MikroC IDE PIC and C fit together well: PIC is the most popular 8-bit chip in the world, used in a wide variety of applications, and C, prized for its efficiency, is the natural choice for developing embedded systems. mikroC provides a successful match featuring highly advanced IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive documentation, and plenty of ready-to- run examples. Features : mikroC allows you to quickly develop and deploy complex applications: • Write your C source code using the built-in Code Editor (Code and Parameter Assistants, Syntax Highlighting, Auto Correct, Code Templates, and more…) • Use the included mikroC libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communications… Practically all P12, P16,
  • 5. Document RPP-05 Page Number 4 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 and P18 chips are supported. • Monitor your program structure, variables, and functions in the Code Explorer. • Generate commented, human-readable assembly, and standard HEX compatible with all programmers. • Inspect program flow and debug executable logic with the integrated Debugger. 4. EQUIPMENT LIST (1) Personal Computer (PC) (2) MPLAB Software (3) Mikro C Software (4) Proteus Software 5. PROCEDURE 5.1 WRITE ASSEMBLY CODE AND SIMULATE USING MPLAB. (A) Starting New Project 1. Start MPLAB software. Click start > Microchip > MPLAB IDE 2. MPLAB work area will appear; shows in Figure 1-1. Figure 1-1 3. To start a new project, click Project > new. New windows of New Project will appear; shows in Figure 1-2.
  • 6. Document RPP-05 Page Number 5 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 4. Fill in Project Name as Lab1 and Project directory with c:lab1 or use Browse to choose existence directory. Figure 1-2 5. To write PIC assembly language program, click File > New. New windows editing will appear. 6. Write down the program 1.1 below and save it by name as lab1.asm ;************************************************************************** PORTA EQU 05h ;This tells the assembler where the address of PORTA, PORTB EQU 06h ;PORTB, STATUS and ADCON1 TRISA EQU 85h ;This Tell the assembler where the address of ports Direction of, TRISB EQU 86h ;TRISA and TRISB. STATUS EQU 03h ADCON1 EQU 9Fh ;Address of Type of data whether Digital/Analog at PORTA RP1 EQU 6 ;Bit 6 and 5 for bank selection in STATUS register. RP0 EQU 5 ;To select bank 0, RP1 = 0 and RP0 = 0 {PORTA and PORTB} ;To select bank 1, RP1 = 0 and RP0 = 1 {TRISA,TRISB & ADCON1} ;To select bank 2, RP1 = 1 and RP0 = 0 ;To select bank 3, RP1 = 1 and RP0 = 1 ;************************************************************************** ORG 00h ;Assembler is now set to address 0 where the main ;program is placed ;********************PIC SETUP******************************************** BSF STATUS,RP0 ;Select bank 1(To use TRISA,B and ADCON1) MOVLW B'00000110' ;Load literal value=6 into W register MOVWF ADCON1 ;Move the literal value into ADCON1 register. ;Now PORTA is configured as digital input MOVLW B'00000000' ;0 is loaded into W register MOVWF TRISB ;Now all PORTB bits are set as OUTPUT
  • 7. Document RPP-05 Page Number 6 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 MOVLW B'11111111' ;move binary value 11111111 to register W MOVWF TRISA ;Now All PORTA bits are set as INPUT ;*******************START OF MAIN PROGRAM************************* BCF STATUS,RP0 ;Back to bank 0;(To use PORTA and PORTB) CLRF PORTB ;Set PORTB output is 0 LOOP BTFSS PORTA,4 ;Bit test PORTA bit 4, if SET skip next line GOTO ON ;Goto ON if button is pressed OFF BCF PORTB,0 ;LED is OFF when button at PORTA is not pressed. GOTO LOOP ;Go back and test the button again ON BSF PORTB,0 ;As PORTA input is 0, mean button is pressed so ;LED at PORTB bit 0 goes ON GOTO LOOP ;Go back to LOOP and test the button again END ;End of code. 7. Insert file programming into this project by clicking right button Source File which shows in Figure 1-3. Choose lab1.asm file that has written. Figure 1-3
  • 8. Document RPP-05 Page Number 7 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 8. To assemble the program, firstly we have to choose types of microcontroller by clicking Configure > Select Device, choose 16F877A. 9. Select Configure > Configuration Bits and set as shown in a figure below. 10. Click Project > Built All to assemble the program. If there is no error, then BUILD SUCCEEDED message will appear. If there is an error, then Error message and Location will appear. (B) Project Simulation 1. To start Simulation, click Debugger > Select Tool > MPLAB SIM. Observe the changes at the MPLAB interface. List down the changes. 2. Click View > Watch. Watch windows (Figure 1-4) will appear. First, from pull down menu, choose PORTA and click Add SFR button. Then choose PORTB and click Add SFR button again. Figure 1-4
  • 9. Document RPP-05 Page Number 8 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 3. Click Debugger > Animate. Observe Watch window and also Lab1.asm program window. Explain your observation. 4. Click Debugger > Halt to stop the simulation process. Click Debugger > Reset > MCLR to reset the program. 5. Click Debugger > Stimulus Controller > New Workbook >Asynch. A window in Figure 1-5 will appear. At Pin/SFR column, choose RA4 pin and at Action column choose Set Low. Observe any changes at Watch window after Animate button and Fire button is pressed. Observe any changes. Figure 1-5
  • 10. Document RPP-05 Page Number 9 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 5.2 SIMULATION THE HEX FILE USING PROTEUS 1. Open Proteus by clicking START > ALL PROGRAM > PROTEUS 7 PROFESIONAL > ISIS 7 PROFESIONAL . Figure 1-6 2. Proteus work area will appear; shows in Figure 1-7. Select button “ P” and follow the next instructions. Figure 1-7
  • 11. Document RPP-05 Page Number 10 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 3. A window in Figure 1-8 will appear. Figure 1-8 4. Select instruction bellows and doudle click your left mouse to input components inside category window as shown in figure 1-9. a) MICROPROCESSORS > PIC16F877A b) RESISTORS > 3 WATT1K c) OPTOELECTRONICS > LED-BIBY d) SWITCHES & RELAYS > BUTTON Figure 1-9
  • 12. Document RPP-05 Page Number 11 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 5. Drag and drop components by clicking at “DEVICES” window to working window as shown at figure 1-10. Figure 1-10 6. Right click mouse and select properties for rotate the components to your suitable positions as shown at figure 1-11. Figure 1-11 7. Connect and wiring all components. 8. Click “Terminals Mode” button to input ‘POWER’ and ‘GROUND’ to your working space as shown at figure 1-12. Figure 1-12
  • 13. Document RPP-05 Page Number 12 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 9. Arrange your components to suitable position and completed your work with the correct connections as figure 1-13. Figure 1-12 10. Save your project at different folder and named it Projek1_circuit as figure 1-14. Figure 1-13
  • 14. Document RPP-05 Page Number 13 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 Figure 1-14 11. From your working space, double click your PIC16F877A and follow the instructions number inside figure 1-15. Setting your Edit Component window by following the step given. 1st setting frequency to 4 MHz, 2nd click at browse button and select the hex file from the project folder created by compiler (MPLAB or Micro C ) . 3rd click “OK”. Figure 1-15
  • 15. Document RPP-05 Page Number 14 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 11. Click DEBUG > EXECUTE to simulate your program and click DEBUG > STOP ANIMATION to stop the program. From your window project, you can animate your program by clicking suitable button as shown in figure 1.16. Explain your observation. Figure 1-16 12. The complete circuit as shown as Figure 1-17. Figure 1-17 13. To see detail what happen to PORTA, PORTB and others register, go to Debug>watch window and add the register that you want to watch like a figure below. Figure 1-18
  • 16. Document RPP-05 Page Number 15 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 5.3 PROGRAMMING USING C LANGUAGE 1. Open Mikro C compiler as shown in figure 1-18. Figure 1-18 2. Create a new project • Project wizard dialog will appear – fill the dialog with appropriate settings for your project • Enter a name for your new project • Choose project path, • Enter short text which describes your project (this is optional) • Choose the microcontroller from drop-down menu • Set the device clock by entering the value in edit box (set to 4Mhz) • Set configuration bits (device flags) by clicking default • After you have set up your project, click OK to continue.
  • 17. Document RPP-05 Page Number 16 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 3. Write the code: ‐ Compiler will create the project file and an accompanying source file, named same as your project. This source file will be automatically opened in the code editor, so you can write the source code. Picture below is the code editor.
  • 18. Document RPP-05 Page Number 17 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 4. Type the source code below into the code editor: 5. Save the file by clicking on the save icon. To compile the source code select Project->Build from the drop-down menu, or click the Build Icon. 6. Compiler will generate output files in the project folder. There should be 4 new files: project1.asm, project1.lst, project1.mcl and project1.hex. The file name with *.hex file will be used to burn into PIC flash memory or can be load into simulation software (Proteus) to simulate the output.
  • 19. Document RPP-05 Page Number 18 of 18 Reference No. Edition 1 Document Title LABORATORY Revision No. 1 PRACTICUM Effective Date JULY 2010 Amendment Date JULY 2010 6. REPORT PREPARATION AND SCHEMA. (1) 2 persons for 1 report. (2) Due date to send report is 1 weeks after lab date. (3) Report schema following below requirements: • Lab report cover sheet for 1st page. • Objective, theory, equipments for the 2nd page. (5) ( 5 Mark ) • Procedure lab sheet . (30) 1. Program 1.1 by MPLAB. ( 5 Mark ) 2. Proteus - Circuit diagram ( 10 Mark ) 3. Program 1.2 by Micro C. ( 5 Mark ) 4. Flow chart of Mikro C code. ( 10 Mark ) • Observations. (35) 1. Observations when using MPLAB software. ( 15 Mark ) 2. Observations when using Proteus software. ( 10 Mark ) 3. Observations when using Micro C software. ( 10 Mark ) • Discussions. (20) 1. Result by using MPLAB software ( 10 Mark ) 2. Result by using Proteus software ( 5 Mark ) 3. Result by using Micro C software ( 5 Mark ) • Conclusions. (10) ( 10 Mark )