Professional Documents
Culture Documents
ESD-Ch6 2016 PDF
ESD-Ch6 2016 PDF
6.1 MPLab
6.2 Proteus
References
• Materials
– Microchip, “MPLAB IDE User’s Guide”, Elsevier
Newnes, 2009
• Websites
– http://www.microchip.com
1
8/9/2016
6.1 Embedded Software Development Tools
MPLAB IDE
MPLAB
• MPLAB® IDE DESKTOP
2
8/9/2016
How to use
All projects will have these basic steps:
1. Create Project – Tạo dự án
2. Select Device – Chọn thiết bị
3. Select Language Tools – Chọn ngôn ngữ
4. Put Files in Project – Đặt file vào dự án
5. Create Code – Tạo mã chương trình
6. Build Project – Xây dựng dự án
7. Draw simulation schematic – Vẽ mạch mô phỏng
8. Test Code with Simulator – Kiểm tra mã với phần
mềm mô phỏng
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 6 5
Step 1. Create Project
3
8/9/2016
Step 2. Select Device
PIC16F84
Bộ môn Kỹ Thuật Điện Tử - ĐHBK Chapter 6 7
Step 3. Select Language Tools
4
8/9/2016
Name your project
Step 4. Put Files in Project
5
8/9/2016
Project wizard ‐ Summary
• After pressing the Finish button, review the Project Window on the
MPLAB IDE desktop
Step 5. Create Code
• Add source code to your project
#include <16f84.h>
#use delay (clock=4000000)
void main()
{
while(1)
{
output_high(PIN_A0);
delay_ms(100);
output_low(PIN_A0);
delay_ms(100);
}
}
6
8/9/2016
Add to project
• Once the file is saved
you can add it to
your project
Step 6. Build Project
• Project>Build All
7
8/9/2016
8
8/9/2016
Step 8. Test Code with Simulator
Simulator toolbar
reset
run animate step into step over routine step out of routine
START SIMULATION
9
8/9/2016
Step 8. Test Code with Simulator
• Select Debugger>Reset>Processor Reset
Step 8. Test Code with Simulator
• Select Debugger>Step Into to single step to the code at Main.
10
8/9/2016
Step 8. Test Code with Simulator
• Select View > Watch
• Available for PIC, 8051, MSP430, AVR, HC11, ARM7/LPC2000 and Basic
Stamp processors
• See your code interact with simulated hardware in real-time
• Interactive peripheral models for displays, keypads, etc.
• Over 8000 analogue and digital device models
• Extensive single step and debugging facilities including system wide
diagnostics.
• Works with popular compilers and assemblers
11
8/9/2016
Step 1. Create a new design
• Select New > New Design
Step 2. Pick devices from library
• Select Library > Pick device
12
8/9/2016
Step 3. Edit component
• Double click to the component
Step 3. Edit component
• Configure:
– Program file (hex file can be created by MPASM, CCS C or Mikro C tools)
– Clock frequency (MHz)
13
8/9/2016
Step 4. Draw peripherals
• Add more components: resistor, LED, …
• Draw connections
• Save the design
Step 5. Run the simulation
• Select Debug > Execute
14
8/9/2016
Debug and Emulator
Exercise 1
Write program that enables 4 LEDs to be turned on gradually in the following
sequence: D0 D1 D2 D3 D2 D1 D0 … Note that the turning cycle
is 1s.
15
8/9/2016
Exercise 2
Write the program that allows 2 7-seg led to count gradually from 0 to 9 and then
repeat again. Know that LED 7-SEG 0 is common cathode and LED 7-SEG 1 is
common anode and the counting cycle is 500ms.
16