Académique Documents
Professionnel Documents
Culture Documents
References
Textbook
Martin Bates, Programming 8-bit PIC Microcontrollers in C, Newnes, 2008
Outline
1. Software development tool (CCS) 2. Advanced simmulation with Proteus
Program structure
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.
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
The keyword const tells the compiler not to subsequently change the object
10
Iterative Statements
11
Iterative Statements
12
Parallel port
13
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
15
16
17
18
20
21
22
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.
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.
25
26