Vous êtes sur la page 1sur 26

I HC QUC GIA TP.

H CH MINH TRNG I HC BCH KHOA


KHOA IN-IN T
B MN K THUT IN T

Embedded System Design


Chapter 4: Development tools - Software development tool (CCS) - Advanced simulation with Proteus

Bi Minh Thnh B Mn K Thut in T - HBK


1

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/)

Bi Minh Thnh - B mn K Thut in T - HBK

Outline
1. Software development tool (CCS) 2. Advanced simmulation with Proteus

Bi Minh Thnh - B mn K Thut in 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

Bi Minh Thnh - B mn K Thut in T - HBK

Program structure

Bi Minh Thnh - B mn K Thut in T - HBK

Program structure
#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.

Bi Minh Thnh - B mn K Thut in T - HBK

Basic Data types


Types short int int1 int int8 char long int Range 1-bit number 0 or 1 8-bit unsigned number 0 255 (0 0xFF) An 8-bit character 16-bit unsigned 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.

int16
int32 signed int signed int8 signed long signed int16 signed int32 float

16-bit unsigned number


32-bit unsigned number 8-bit signed number -128 127 16-bit signed number 16-bit signed number 32-bit signed number 32-bit floating-point number

The keyword const tells the compiler not to subsequently change the object

Bi Minh Thnh - B mn K Thut in T - HBK

Basic Data types

Bi Minh Thnh - B mn K Thut in T - HBK

Simple selection structures

Bi Minh Thnh - B mn K Thut in T - HBK

Simple selection structures

Bi Minh Thnh - B mn K Thut in T - HBK

10

Iterative Statements

Bi Minh Thnh - B mn K Thut in T - HBK

11

Iterative Statements

Bi Minh Thnh - B mn K Thut in T - HBK

12

Parallel port

Bi Minh Thnh - B mn K Thut in T - HBK

13

2. Advanced simmulation with Proteus


Proteus Virtual System Modelling (VSM) combines mixed mode SPICE circuit simulation, animated components and microprocessor models to facilitate cosimulation 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

Bi Minh Thnh - B mn K Thut in T - HBK

14

Exercises 1
Design an embeded system that creates a pulse with the cycle of 1ms on PIN 0 of Port D of PIC 16F877A

Bi Minh Thnh - B mn K Thut in T - HBK

15

Exercises 1 Software design


Open CCS PIC compiler. New Project Wizard

Bi Minh Thnh - B mn K Thut in T - HBK

16

Exercises 1 Software design


Fill out the name of the project (ex: pulse_1s.pjt) and click Save

Bi Minh Thnh - B mn K Thut in T - HBK

17

Exercises 1 Software design


Choose Device (16F877A) and Oscillator Frequency (20MHz) and click OK

Bi Minh Thnh - B mn K Thut in T - HBK

18

Exercises 1 Software design


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.


Bi Minh Thnh - B mn K Thut in T - HBK
19

Exercises 1 Hardware design


Now, we use Protues to design the hardware of the circuit Open Proteus Choose P to pick devices from Libraries

Bi Minh Thnh - B mn K Thut in T - HBK

20

Exercises 1 Hardware design


For this exercise, we need: 1 PIC16F877A, 1 LED, 1 220 resistor, source and ground. Design the circuit as follows:

Bi Minh Thnh - B mn K Thut in T - HBK

21

Exercises 1 Hardware design


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

Bi Minh Thnh - B mn K Thut in T - HBK

22

Exercises 1 Hardware design


Finally, click to to see how it works

Bi Minh Thnh - B mn K Thut in T - HBK

23

Exercise 2
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.

Bi Minh Thnh - B mn K Thut in T - HBK

24

Exercise 3
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.

Bi Minh Thnh - B mn K Thut in T - HBK

25

PIC16F877 Register Map

Unimplemented data locations, read as 0 * Not a physical register

Bi Minh Thnh - B mn K Thut in T - HBK

26

Vous aimerez peut-être aussi