Lab 1 microcontroller

10,479 views
10,355 views

Published on

Published in: Education, Technology, Business
4 Comments
5 Likes
Statistics
Notes
No Downloads
Views
Total views
10,479
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
508
Comments
4
Likes
5
Embeds 0
No embeds

No notes for slide

Lab 1 microcontroller

  1. 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. 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 MATAPELAJARANSUBJECT : DAE32203 / DEK 3133 MICROCONTROLLERTITLE : LAB 1 – Introduction to MPLAB, Proteus and MicroC.GOAL : To expose student with MPLAB, Proteus and MicroC software1. OBJECTIVESAt 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. SINOPSYSMPLAB and Micro C is a software package easy writing process and development of assembly and Clanguage program for PIC Microcontroller. In this lab, student will have the exposure on MPLAB andMicro C software and learn how to manage project by using MPLAB starting and Micro C from assemblyand C language program until simulation by Proteus.Disediakan Oleh: Disahkan Oleh:Tandatangan : Tandatangan :Nama : Mohamad Bin Hj. Md. Som Nama : Shamsul Bin MohamadTarikh : July-2010 Tarikh : July-2010
  3. 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. THEORYA) MPLABMPLAB is comprehensive software that has editing, project management and design in it. It used indevelopment of embedded system application using microcontroller Microchip PICmicro and PIC.Assembly language is a language that used for programming microcontroller. Before we programmedthese assembly language instructions into microcontroller memory, it has to convert to machine languageso that microcontroller easily understands. This conversion is done by software so called assembler inMPLAB. This process is described in Figure 1. Figure 1In the MPLAB assembly language programming, numbers usually represent decimal, binary andhexadecimal. For example, decimal number 240 is written by: 240 - decimal 0xF0 - hexadecimal b’11110000’ - binaryBasic elements in assembly language are: Label Instruction Operand Comment
  4. 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 2010B) PROTEUS ISIS provides the development environment for PROTEUS VSM, our revolutionary interactive systemlevel simulator. This software combines mixed mode circuit simulation, micro-processor models andinteractive 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 interactivesimulation 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 andswept variable simulation to be performed.Major features of PROTEUS VSM include:· True Mixed Mode simulation based on Berkeley SPICE3F5 with extensions for digital simulationand 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 theprogrammer with the easiest possible solution for developing applications for embedded systems,without compromising performance or control.C) MikroC IDEPIC and C fit together well: PIC is the most popular 8-bit chip in the world, used in a wide varietyof applications, and C, prized for its efficiency, is the natural choice for developing embeddedsystems. mikroC provides a successful match featuring highly advanced IDE, ANSI compliantcompiler, 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. 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 Software5. PROCEDURE5.1 WRITE ASSEMBLY CODE AND SIMULATE USING MPLAB.(A) Starting New Project1. Start MPLAB software. Click start > Microchip > MPLAB IDE2. MPLAB work area will appear; shows in Figure 1-1. Figure 1-13. To start a new project, click Project > new. New windows of New Project will appear; shows in Figure 1-2.
  6. 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 20104. Fill in Project Name as Lab1 and Project directory with c:lab1 or use Browse to choose existence directory. Figure 1-25. 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 ADCON1TRISA EQU 85h ;This Tell the assembler where the address of ports Direction of,TRISB EQU 86h ;TRISA and TRISB.STATUS EQU 03hADCON1 EQU 9Fh ;Address of Type of data whether Digital/Analog at PORTARP1 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 B00000110 ;Load literal value=6 into W register MOVWF ADCON1 ;Move the literal value into ADCON1 register. ;Now PORTA is configured as digital input MOVLW B00000000 ;0 is loaded into W register MOVWF TRISB ;Now all PORTB bits are set as OUTPUT
  7. 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 B11111111 ;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 0LOOP BTFSS PORTA,4 ;Bit test PORTA bit 4, if SET skip next line GOTO ON ;Goto ON if button is pressedOFF BCF PORTB,0 ;LED is OFF when button at PORTA is not pressed. GOTO LOOP ;Go back and test the button againON 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. 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 20108. 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 Simulation1. 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. 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 20103. 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. 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 20105.2 SIMULATION THE HEX FILE USING PROTEUS1. Open Proteus by clicking START > ALL PROGRAM > PROTEUS 7 PROFESIONAL > ISIS 7 PROFESIONAL . Figure 1-62. Proteus work area will appear; shows in Figure 1-7. Select button “ P” and follow the next instructions. Figure 1-7
  11. 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 20103. A window in Figure 1-8 will appear. Figure 1-84. Select instruction bellows and doudle click your left mouse to input components inside categorywindow 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. 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 20105. Drag and drop components by clicking at “DEVICES” window to working window as shown at figure 1-10. Figure 1-106. Right click mouse and select properties for rotate the components to your suitable positions as shown at figure 1-11. Figure 1-117. 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. 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 20109. Arrange your components to suitable position and completed your work with the correct connections as figure 1-13. Figure 1-1210. Save your project at different folder and named it Projek1_circuit as figure 1-14. Figure 1-13
  14. 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-1411. 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. 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 201011. 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-1612. The complete circuit as shown as Figure 1-17. Figure 1-1713. 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. 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 20105.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. 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 20103. 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. 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 20104. 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. 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 20106. 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 )

×