embedded system design - hcmutbmthanh/esd/ch4.pdf · of pic and in some cases library functions,...
TRANSCRIPT
![Page 1: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/1.jpg)
ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH
TRƯỜNG ĐẠI HỌC BÁCH KHOAKHOA ĐIỆN-ĐIỆN TỬ
BỘ MÔN KỸ THUẬT ĐIỆN TỬ
Bùi Minh Thành – Bộ Môn Kỹ Thuật Điện Tử - ĐHBK11
Embedded System Design
Chapter 4: Development tools
- Software development tool (CCS)
- Advanced simulation with Proteus
![Page 2: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/2.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
References
• Textbook
– Martin Bates, “Programming 8-bit PIC Microcontrollers in C”, Newnes, 2008
• Many C compilers for PIC:
– MikroC (www.mikroe.com)
– PICC18 (www.htsoft.com)
– MPLAB C18, C30 (www.microchip.com)
– CCS C (www.microchipc.com/reviews/CCS_C/)
2
![Page 3: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/3.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Outline
1. Software development tool (CCS)2. Advanced simmulation with Proteus
3
![Page 4: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/4.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
1. Software development tool (CCS C Compiler)
- CCS (Customer Computer Services) compiler supports the Microchip PIC12x, PIC16x, PIC18x, and dsPIC devices.
- The PCB, PCM, and PCH are separate compilers. - PCB is for 12-bit opcodes- PCM is for 14-bit opcodes- And PCH is for 16-bit opcode PIC® microcontrollers
4
![Page 5: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/5.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Program structure
5
![Page 6: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/6.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Program structure
6
• #include: is a directive which allows the pro-grammer to include header
files, which typically give the compiler some information regarding the type
of PIC and in some cases library functions, such as the mathematics library.
• #fuses is a directive which inserts code to set up the configuration fuses
at programming time.
• #use is a directive which allows the programmer to give the compiler
some information regarding the hardware (e.g. clock speed, or pins used
for serial I/O) or how a peripheral device is to be set up.
• #byte is a directive allowing the programmer to give a fixed File location a
name. Ex: #byte PortA = 5 to define Port A
• #bit is a directive allowing the programmer to give a bit in a fixed File
location a name; e.g. a bit in a port connected to a LED; e.g.
#bit LED = 5.2.
• All C programs must have a main() function.
![Page 7: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/7.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Basic Data types
7
Types Range
short int 1-bit number
int1 0 or 1
int 8-bit unsigned number0 – 255 (0 – 0xFF)int8
char An 8-bit character
long int 16-bit unsigned number
int16 16-bit unsigned number
int32 32-bit unsigned number
signed int 8-bit signed number
signed int8 -128 – 127
signed long 16-bit signed number
signed int16 16-bit signed number
signed int32 32-bit signed number
float 32-bit floating-point number
The qualifier signed may be
used to deal with negative
numbers.
The keywords int8 (same as
int), int16 (same as long) and
int32 are specific to the CCS
compiler.
The keyword const tells the
compiler not to subsequently
change the object
![Page 8: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/8.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Basic Data types
8
![Page 9: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/9.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Simple selection structures
9
![Page 10: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/10.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Simple selection structures
10
![Page 11: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/11.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Iterative Statements
11
![Page 12: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/12.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Iterative Statements
12
![Page 13: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/13.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Parallel port
13
![Page 14: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/14.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
2. Advanced simmulation with Proteus
14
• Proteus Virtual System Modelling (VSM) combines mixed mode SPICE circuit
simulation, animated components and microprocessor models to facilitate co-
simulation of complete microcontroller based designs.
• It is possible to develop and test such designs before a physical prototype is
constructed.
• 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
![Page 15: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/15.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1
15
Design an embeded system that creates a pulse with the cycle of 1ms on
PIN 0 of Port D of PIC 16F877A
![Page 16: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/16.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Software design
16
Open CCS PIC compiler.
New Project Wizard
![Page 17: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/17.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Software design
17
Fill out the name of the project (ex: pulse_1s.pjt) and click Save
![Page 18: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/18.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Software design
18
Choose Device (16F877A) and Oscillator Frequency (20MHz) and click OK
![Page 19: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/19.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Software design
19
File pulse_1s.c is opened with some default code. Delete unnecessary code
and type the code as follows:
Choose Compile Compile to compile the project.
![Page 20: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/20.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Hardware design
20
Now, we use Protues to design the hardware of the circuit
Open Proteus Choose P to pick devices from Libraries
![Page 21: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/21.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Hardware design
21
For this exercise, we need: 1 PIC16F877A, 1 LED, 1 220 resistor, source and
ground. Design the circuit as follows:
![Page 22: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/22.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Hardware design
22
Double-click on the PIC16F877A to open edit component box and browse the
pulse_1s.hex file in the Program File and change the Processor Clock Frequency
to 20MHz click OK
![Page 23: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/23.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercises 1 – Hardware design
23
Finally, click to to see how it works
![Page 24: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/24.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercise 2
24
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.
![Page 25: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/25.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
Exercise 3
25
Write the program that allows 2 7-seg led 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.
![Page 26: Embedded System Design - HCMUTbmthanh/ESD/Ch4.pdf · of PIC and in some cases library functions, such as the mathematics library. •#fuses is a directive which inserts code to set](https://reader034.vdocuments.site/reader034/viewer/2022042100/5e7c1ecfafcf63763019fb32/html5/thumbnails/26.jpg)
Bùi Minh Thành - Bộ môn Kỹ Thuật Điện Tử - ĐHBK
• PIC16F877 Register Map
26
Unimplemented data
locations, read as ‘0’
* Not a physical register