Professional Documents
Culture Documents
Master 2008 PDF
Master 2008 PDF
1222 CCS
Slide
Class Objective
When you finish this class you will:
Be able to use your C knowledge and
write applications using CCS C
Know the ways the CCS C Compiler
speeds up development time
Develop new application and coding
ideas
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
Agenda
O
Compiler Overview
Design Goals, Compiler Products
Compiler Methodology
Differences to Common C
Data Types
Programming Details
Required setup, Interrupts
Built-In Functions
GPIO, Delays, Serial (Asynch, I2C, SPI)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
Agenda
Hands-on Labs
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
Compiler Overview
Design Goals
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
Product Line:
Integrates into
O Linker
O
MPLAB
IDE
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
C Aware Editor
Debugging (using a CCS ICD)
Integrated RTOS
Linker and Re-locatable objects
Document Generator
Statistics
Flow Chart Editor
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
CCS ICD
O
O
O
In-Circuit Programmer/Debugger
Serial & USB
Control Software
Windows and Linux
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
10
C Compiler
Prototyping Board
ICD
Tutorial Book and Examples
Relevant Parts and Cables
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
11
Compiler
Demonstration
Hands On Lab #1
Blinky LED
Lab 1 Objectives
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
14
Prototyping Hardware
O
PIC16F877A
ICD Connection
Pot on AN0
Button on RA4
LEDs on RA5, RB4 and RB5
RS232 driver and mini-connector
Header to all GPIO
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
15
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
16
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. Class 1222 CCS
Slide
17
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
18
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
19
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
20
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
21
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. Class 1222 CCS
Slide
22
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
23
Compile Code
Compile -> Compile
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
24
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
25
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
26
Lab 1 Hints
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
27
Compiler
Methodology
Differences to Common C
O
Case in-sensitive
O
O
#device ANSI
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
29
ANSI Non-Compliance
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
30
Data Types
PCB/PCM/PCH
short
1bit
char
Unsigned 8bit
int
Unsigned 8bit
long
Unsigned 16bit
long long Unsigned 32bit
float
MCHP 32bit
double
NO SUPPORT
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
PCD
1bit
Unsigned 8bit
Signed 16bit
Signed 32bit
Signed 64bit
IEEE 32bit
IEEE 64bit
Slide
31
Data Types
O
Optimization Tips
int1
int8
int32
int48*
float32 float48*
__address__
int16
int64*
float64* (PCD ONLY)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
32
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
33
O
O
O
O
money = 20.50;
money += 5;
//adds 5.00
money += value;
printf(%w, money);
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
34
RAM Allocation
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
35
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
36
}
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
37
Get(&c, 500);
time will be 500
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
38
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
39
In-Line Assembly
O
#asm
#endasm
O
O
_return_
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
40
Output Files
O
O
O
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
41
Programming
Details
Required Setup
Pre-processor
O
Pre-processor commands
change compiler-behaviour:
Methodology
ROM/RAM placement
Library configuration
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
43
#device
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
44
#fuses
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
45
#use delay
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
46
Programming
Details
Memory Placement
#byte / #word
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
48
#bit
O
#bit ident=X.b
Declares boolean at address X, bit b
Examples:
O
O
#bit CARRY=STATUS.0
#bit CARRY=getenv(BIT:C)
Dont forget:
Compiler will pack int1 variables
You can use struct to pack bits
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
49
#org
O
#org 0x400,0x4FF
SomeFunction() { /*code*/ }
#org 0x500, 0x5FF
const someStruct[] = { }
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
50
Hands On Lab #2
Debugging a Calculator
Application
Lab 2 Objectives
O
Breakpoints
Watches
ROM and RAM view
Peripheral Status
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
52
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
53
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
54
Start Debugger
Debug -> Enable Debugger
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
55
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
56
Press GO
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
57
#use rs232(debugger)
1-Wire RS232 using RB3
1-Wire Monitor in Debugger:
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
58
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
59
Press STOP
Add a Breakpoint to line 63
printf(\r\nThe result is %lu, result)
Put cursor on Line 63, Press + on
Break Tab
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
60
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
61
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
62
Press GO
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
63
BREAK TIME!
Programming Details
addressmod
Pop Quiz
Slide
66
addressmod
O
O
O
typemod, on steroids!
Can be used on any data type
Pointers, structs, unions and arrays
const and rom not allowed
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
67
addressmod Syntax
O
addressmod(identifier,[read,write,]start,end)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
68
addressmod Declaration
addressmod(nv, read_nv, write_nv,
0, NV_SIZE);
void read_nv(int32 addr,
int8 *ram, int8 n)
{ /* read n from addr */ }
void write_nv(int32 addr,
int8 *ram, int8 n)
{ /* write n from ram */ }
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
69
addressmod Usage
nv NVBuffer[8192];
nv NVID;
nv *NVPtr;
#locate NVID=0
NVBuffer[i]=55;
*NVPtr++ = 0;
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
70
addressmod Ideas
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
71
Programming Details
Interrupts
Pop Quiz
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
73
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
74
enable_interrupts(INT_*)
enable_interrupts(GLOBAL)
enable_interrupts(INT_TIMER0)
O
O
O
disable_interrupts(INT_*)
clear_interrupt(INT_*)
interrupt_active(INT_*)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
75
#int_*
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
76
#int_global
Function overrides CCS ISR
User must save and restore all
registers altered by their ISR (W,
STATUS, scratch used by compiler,
etc.)
#int_default
Traps unknown interrupt
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
77
#device HIGH_INTS=TRUE
Must set to use high/fast ISR on PIC18
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
78
Lab #3
Interrupts
Lab 3: Objectives
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
80
Lab 3 Hints
O
O
setup_timer_0(RTCC_DIV_256)
O
enable_interrupts(int_xxx)
O
O
input(PIN_XX)
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
81
Programming
Details
Built-In Functions
Built-In Functions
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
83
Slide
84
getenv()
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
85
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. Class 1222 CCS
Slide
86
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
87
Built-In Functions
General Purpose Input / Output
O
O
output_high(PIN_XX)
output_low(PIN_XX)
Sets the pin to desired level
PIN_XX (ex PIN_C0, PIN_B5, etc) are
defined in the device header file
output_toggle(PIN_XX)
Toggle high/low state of the pin
bool=input(PIN_XX)
Read value of pin
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
88
Built-In Functions
General Purpose Input / Output
O
output_X(value)
Sets the port X (A to J) to the desired
value
byte=input_X()
Read value of port X
O
O
set_tris_X(value)
val = get_tris_X()
Get/Set the tristate setting
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
89
Built-In Functions
General Purpose Input / Output
O
#use standard_io(X)
Output functions set TRIS to output
Input functions set TRIS to input
This is the default operation
#use fast_io(X)
Compiler does not alter TRIS
#use fixed_io(port_outputs=pins)
#use fixed_io(d_outputs=PIN_D7)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
90
Built-In Functions
Bit Manipulation
O
bool=bit_test(var, bit)
Returns the value of the specified bit
O
O
bit_clear(var, bit)
bit_set(var, bit)
Set/clear the specified bit
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
91
Built-In Functions
Delays
O
O
O
delay_cycles(x)
delay_us(x)
delay_ms(x)
Uses a series of loops and NOPs
Timing based on #use delay()
Multiple #use delay() allowed
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
92
#use delay(clock=125000)
//1 second delay @ 125kHz
void Delay1s125khz(void) {
delay_ms(1000);
}
#use delay(clock=8000000)
//1 second delay @ 8MHz
Void Delay1s8Mhz(void) {
delay_ms(1000);
}
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. Class 1222 CCS
Slide
93
Built-In Functions
Serial Libraries
Pop Quiz
Slide
95
UART
O
Slide
96
UART (Continued)
O
O
O
bool=kbhit(stream)
setup_uart(newBaud, stream)
Dynamically change the UART
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
97
Slide
98
printf() Redirection
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
99
2
I C
O
O
Library
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
100
2
I C
O
Library (Continued)
i2c_start()
Can also be used to send a re-start signal
char=i2c_read(ack)
Ack is an optional parameter
O
O
ack = i2c_write(char)
bool=i2c_available()
Can only be used with a hardware MSSP
i2c_stop()
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
101
SPI
O
O
in = spi_xfer(STREAM_SPI, out)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
102
Built-in Functions
A/D Converter
A/D Converter
O
setup_adc(mode)
Configure and the ADC; mode varies
for each type
setup_adc_ports(config)
Configure the pins for analog or
digital mode
#device ADC=X
Assign the ADC result size
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
104
set_adc_channel(channel)
Set the channel for subsequent reads
val = read_adc(mode)
ADC_START_ONLY Start a conversion
ADC_READ_ONLY Read last
conversion
ADC_START_AND_READ Full cycle
adc_done()
Returns TRUE if conversion is done
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
105
Slide
106
Getting Help
So many peripherals,
how do I get help?
1.
2.
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
107
Lab #4
Analog to Digital
Conversion
Lab 4
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
109
Lab 4 Hints
O
C:\masters\1222\Lab4\lab4.c
Complete the lines marked TODO
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
110
Class Summary
Class Summary
Leaving this class you should:
Be able to use your C knowledge and
write applications using CCS C
Know how to use the CCS software to
load your code onto a PIC MCU and
debug it
Know the ways the CCS C Compiler
speeds up development time with built-in
functions, drivers, example files and
context sensitive help
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
112
Q&A
Thank You!
Please fill out evaluation
form.
Appendix
Frequently Asked
Questions
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
116
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
117
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
118
Appendix
Programming Details
Miscellaneous
addressmod Block
O
#type default=qualifier
Following declarations will use this
qualifier
If qualifier blank, goes back to default
#type default=nv
char buffer[8192];
#include <memoryhog.h>
#type default=
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
120
Pre-Processor Miscellaneous
O
O
O
O
O
O
O
O
__pcb__
__pcm__
__pch__
__pcd__
__date__
__time__
#id CHECKSUM
#id value
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
121
Bit Arrays
O
Array of bits:
int1 flags[30]={FALSE};
flags[i] = TRUE;
if (flags[10]) { /* some code */ }
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
122
String Parameters
O
O
O
Example (ROM):
void LCDPuts(rom char *str);
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
123
#import
O
O
O
Type = RAW
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
124
Appendix
Output Files
Output Files
O
O
O
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
126
O
O
na indicates no RAM
Following sections include:
Other Input files
ROM memory map
PIC MCU / Compiler Settings
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
127
STA Statistics
Review ROM/RAM/Stack used.
O Statistics for each function:
Page ROM % RAM Functions:
---- --- --- --- ---------0
26
0
1 @delay_ms1
0
284
1
3 ee_reset
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
128
STA Statistics
Statistics for each segment:
Segment
Used
Free
---------------00000-00006
4
4
00008-000B2
172
0
000B4-03FFE
15826
378
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
129
TRE Statistics
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
130
Out of ROM
O
Full output:
Out of ROM, A segment or the program is too
large: XXXXXX
Seg w-x, y left, need z
Seg 0-3ff, 12C left, need 12F
Tips:
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
131
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
132
Out of RAM
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
133
Appendix
Other Built-In Functions
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
135
O
O
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
136
Built-In Functions
Byte Manipulation
O
int8=make8(variable, offset)
Returns one byte from variable
O
O
int16=make16(i8MSB, i8LSB)
int32=make32(iMSB..iLSB)
Returns the combined value
swap(value)
Swaps nibble, saves to value
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
137
Timers
O
setup_timer_X(mode)
Mode contains configuration info, such as
prescalar, postscalar, period, etc.
setup_timer_1(T1_INTERNAL | T1_DIV_BY_4);
O
O
set_timerX(new_count)
current_count=get_timerX()
Set/Get Timer count
Word Safe
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
138
setup_ccpX(mode)
Mode contains configuration,
examine header for full options
setup_ccp1(CCP_PWM)
set_pwmX_duty(new_duty)
% = new_duty / (4 * period)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
139
Peripheral Control
Parallel Slave Port
O
setup_psp(mode)
Mode is PSP_ENABLED or
PSP_DISABLED
O
O
O
O
full=psp_output_full()
avail=psp_input_full()
isOverflowed=psp_overflow()
psp_data
A variable mapped to the PSP I/O port
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
140
Built-In Functions
Miscellaneous
O
ext_int_edge(which, mode)
ext_int_edge(0, H_TO_L)
O
O
port_X_pullups(boolean)
setup_oscillator(mode, finetune)
finetune is optional
setup_oscillator(OSC_2MHZ)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
141
Appendix
Fixed Memory Placement
#rom
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
143
#inline
Makes following function inline
Best if used with reference parameters
#separate
Makes following function separate (called)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
144
#locate
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
145
#locate examples
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
146
#byte ident=X
Same as #locate, but no allocation
#bit ident=X.b
Declares boolean at address X, bit b
Examples:
O
O
#bit CARRY=STATUS.0
#bit CARRY=get_env(BIT:C)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
147
#rom
O
O
O
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
148
#inline
Makes following function inline
#separate
Makes following function separate (called)
Disables stack overflow check
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
149
#org
Create segment, force code
into segment.
O #org start, end
O
#org start
Continue previous segment
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
150
#org Example
O
//Valid Protoype
#seperate void func1(void);
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
151
#org
O
#org DEFAULT
Terminate previous DEFAULT
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
152
#org Example 2
O
Slide
153
#org
O
Used
4
250
190
1337
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Free
0
2
66
199
Slide
154
#build
O
O
O
Examples:
#build(reset=0x800, interrupt=0x808)
#build(memory=0x10000:0x1FFFF)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
155
Appendix
Bootloader Example
Bootloader Overview
O
Two programs:
Loader
Application
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
157
Bootloader/Application
Common Code
#define BOOT_END
(0x7FF)
#define APP_START
(BOOT_END+1)
#define APP_ISR
(APP_START+8)
#define PROGRAM_END
getenv(PROGRAM_MEMORY)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
158
Bootloader Example
Loader Code
//prevent bootloader from using application
#org APP_START , PROGRAM_END { }
#int_global
void isr(void) {
//goto interrupt in application
jump_to_isr(APP_ISR);
}
void main(void) {
if (IsBootloadEvent())
Bootload();
#asm
goto APP_START
#endasm
}
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
159
Bootloader Example
Application Code
#import(file=loader.hex, range=0:BOOT_END)
#build(reset=APP_START,interrupt=APP_ISR)
#org 0,BOOT_END { }
#int_timer0
void timer(void) { /* do timer0 isr */ }
Void main(void)
/* code */
}
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
160
Appendix
RTOS
RTOS Basics
O
O
O
Real Time
Task is in one of three states:
Running
Ready
Blocked
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
162
Cooperative Multitasking
Tightly integrated with compiler
Supports ALL PIC MCUs with a
Timer
Available to IDE customers
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
163
RTOS Setup
O
#use rtos(timer=X,
[minor_cycle=cycle_time])
Timer can be any timer available
Minor_Cycle is rate of fastest task
Example:
#use rtos(timer=1, minor_cycle=50ms)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
164
RTOS Tasks
O
#task(rate=xxxx,
[max=yyyy], [queue=z])
Following function is RTOS task
Will be called at specified rate
Max is slowest execution time, used
for budgeting
Queue defines RX message size
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
165
rtos_run()
Starts the RTOS
Will not return until rtos_terminate()
rtos_terminate()
Stops the RTOS
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
166
#use rtos(timer=1)
#task(rate=100ms, max=5ms)
void TaskInput(void)
{ /* get user input */ }
#task(rate=25ms)
void TaskSystem(void)
{ /* do some stuff */ }
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
167
rtos_enable(task)
rtos_disable(task)
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
168
RTOS Messaging
O
rtos_msg_send(task, char)
Sends char to task
avail=rtos_msg_poll()
TRUE if a char is waiting for this task
byte=rtos_msg_read()
Read next char destined for this task
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
169
RTOS Yielding
O
rtos_yield()
Stops processing current task
Returns to this point on next cycle
rtos_await(expression)
rtos_yield() if expression not TRUE
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
170
#task(rate=100ms, max=5ms)
void TaskInput(void) {
if (KeyReady())
rtos_msg_send(TaskSystem,
KeyGet());
}
#task(rate=25ms, queue=1)
void TaskSystem(void) {
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
171
RTOS Semaphores
O
Semaphore
rtos_wait(semaphore)
rtos_signal(semaphore)
Release semaphore
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
172
overrun=rtos_overrun(task)
rtos_stats(task, rtos_stats)
typedef struct
int32 total;
int16 min;
int16 max;
int16 hns;
} rtos_stats;
{
//
//
//
//
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
173
User I/O
Communication Protocols
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
174
Trademarks
The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KeeLoq,
KeeLoq logo, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, rfPIC and
SmartShunt are registered trademarks of Microchip Technology Incorporated in
the U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor
and The Embedded Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM,
dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB
Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail,
PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB,
Select Mode, Total Endurance, UNI/O, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their respective
companies.
2008, Microchip Technology Incorporated. All Rights Reserved.
2008 Custom Computer Services Inc.,, Microchip Technology Incorporated. All Rights Reserved. 1222 CCS
Slide
175