Professional Documents
Culture Documents
Master 2012
Master 2012
1620 CCS
Slide
Class Objective
After this class you will:
1620 CCS
Slide
Agenda
Compiler Overview
Compiler Methodology
Built-in functions
Interrupts
1620 CCS
Slide
Agenda
Hands-On Labs
1620 CCS
Slide
Compiler Overview
1620 CCS
Slide
Design Goals
1620 CCS
Slide
Product Line:
1620 CCS
Slide
C Aware Editor
Debugging
Integrated RTOS
Linker and re-locatable objects
Document generator
Flow chart editor
1620 CCS
Slide
Duration is unlimited
Updates, new devices, drivers
Can be extended any time
1620 CCS
Slide
Compiler Demonstration
1620 CCS
Slide
10
Hands On Lab #1
Blinky LED
1620 CCS
Slide
11
Lab 1 Objectives
1620 CCS
Slide
12
Prototyping Hardware
PIC16F887
ICD Connector
Pot on AN0
Button on RA4
LEDs on RA4, RB4 and RB5
RS232 driver and mini connector
Header to all GPIO
1620 CCS
Slide
13
Wizard Overview
1620 CCS
Slide
14
Lab 1 Hints
1620 CCS
Slide
16
Compiler
Methodology
1620 CCS
Slide
17
Differences to common C
Case in-sensitive
Ex: Somefunc(HELLO);
#device PASS_STRINGS=IN_RAM
1620 CCS
Slide
18
ANSI Non-Compliance
1620 CCS
Slide
19
Data Types
PCB/PCM/PCH
short
1-bit
char
Unsigned 8-bit
int
Unsigned 8-bit
long
Unsigned 16-bit
long long Unsigned 32-bit
float
MCHP 32-bit
double
NO SUPPORT
2012 Microchip Technology Incorporated. All Rights Reserved.
1620 CCS
PCD
1-bit
Unsigned 8-bit
Signed 16-bit
Signed 32-bit
Signed 64-bit
IEEE 32-bit
IEEE 64-bit
Slide
20
Data Types
Optimization tips
Non-standard types
1620 CCS
Slide
21
Bit Arrays
Array of bits:
int1 flags[30];
flags[i] = TRUE;
if (flags[10]) { /* some code */ }
1620 CCS
Slide
22
Faster, Smaller
100% precision
1620 CCS
Slide
23
money = 20.50;
money += 5; //adds 5.00
money += value;
printf(%w, money);
1620 CCS
Slide
24
RAM Allocation
2.
3.
Globals
Static
Local
exempt
2012 Microchip Technology Incorporated. All Rights Reserved.
1620 CCS
Slide
25
#device CONST=ROM
(DEFAULT)
#device CONST=READ_ONLY (RAM)
Examples
1620 CCS
Slide
26
1620 CCS
Slide
27
1620 CCS
Slide
28
1620 CCS
Slide
29
1620 CCS
Slide
30
Output Files
1620 CCS
Slide
31
Programming Details
Required Setup
1620 CCS
Slide
32
Pre-processor
Pre-processor commands
change compiler-behaviour:
1620 CCS
Slide
33
#device
#device PIC18F4520
#device ICD=TRUE
1620 CCS
Slide
34
#fuses
1620 CCS
Slide
35
#use delay
#use delay(clock=value)
Serial, Delays, Timers
1620 CCS
Slide
36
Programming Details
Memory Placement
1620 CCS
Slide
37
#byte / #word
1620 CCS
Slide
38
#bit
#bit ident=X.b
Dont forget:
1620 CCS
Slide
39
#org
#org 0x400,0x4FF
SomeFunction() { /*code*/ }
#org 0x500, 0x5FF
const someStruct[] = { }
2012 Microchip Technology Incorporated. All Rights Reserved.
1620 CCS
Slide
40
Hands On Lab #2
Debugging a Calculator
Application
1620 CCS
Slide
41
Lab 2 Objectives
Breakpoints
Watches
ROM and RAM view
Trace
Logging
1Wire RS232 on RB3
1620 CCS
Slide
42
Lab 2 Directions
1620 CCS
Slide
43
BREAK TIME!
1620 CCS
Slide
44
Programming Details
Built-In Functions
1620 CCS
Slide
45
Built-In Functions
1620 CCS
Slide
46
#if defined(__PIC24__)
#include <24FJ64GA004.h>
#elif defined(__PIC18__)
#include <18F4520.h>
#elif defined(__PIC16__)
#include <16F887.h>
#endif
#fuses HS, NOWDT, NOLVP
#use delay(clock=20000000)
void main(void) {
while(TRUE) {
output_toggle(PIN_C0);
delay_ms(500);
}
}
getenv()
1620 CCS
Slide
48
1620 CCS
Slide
49
output_high(PIN_XX)
output_low(PIN_XX)
output_toggle(PIN_XX)
bool = input(PIN_XX)
1620 CCS
Slide
50
output_X(value)
byte = input_X()
set_tris_X(value)
val = get_tris_X()
1620 CCS
Slide
51
#use standard_io(X)
#use fast_io(X)
#use fixed_io(port_outputs=pins)
#use fixed_io(d_outputs=PIN_D7)
1620 CCS
Slide
52
delay_cycles(x)
delay_us(x)
delay_ms(x)
1620 CCS
Slide
53
#use delay(clock=125K)
//1 second delay @ 125kHz
void Delay1s125Khz(void) {
delay_ms(1000);
}
#use delay(clock=8M)
#use timer()
TICKS_PER_SECOND defined
1620 CCS
Slide
55
{
}
1620 CCS
Slide
56
Built-In Functions
Serial Libraries
1620 CCS
Slide
57
Pop Quiz
You need to add another
serial port to your project,
but you have used all of the
PIC MCUs peripherals.
What do you do?
2012 Microchip Technology Incorporated. All Rights Reserved.
1620 CCS
Slide
58
#use rs232()
1620 CCS
Slide
59
UART (Continued)
Standard C I/O
printf(string, );
char = getc();
fprintf(stream, string, );
char = fgetc(stream);
bool = kbhit(stream);
setup_uart(newBaud, stream)
1620 CCS
Slide
60
1620 CCS
Slide
61
printf() Redirection
1620 CCS
Slide
62
RECEIVE_BUFFER=x and
TRANSMIT_BUFFER=x sets size
RTS=PIN_XX sets RTS flow control
CTS=PIN_XX sets CTS flow control
API doesnt change (getc(), putc())
ISR use optional
1620 CCS
Slide
63
2
I C
#use i2c(parameters)
1620 CCS
Slide
64
Built-In Functions
Peripherals and More
1620 CCS
Slide
65
#use_pwm()
set_pwm_duty_percent(val)
set_pwm_frequency(freq)
1620 CCS
Slide
66
#use capture()
boolean = get_capture_event()
time = get_capture_time()
1620 CCS
Slide
67
#use touchpad()
boolean = touchpad_hit()
char = touchpad_getc()
1620 CCS
Slide
68
A/D Converter
setup_adc(mode)
setup_adc_ports(config)
set_adc_channel(channel)
val = read_adc()
1620 CCS
Slide
69
Overview of Other
Functions
1620 CCS
Slide
70
Getting Help
So many peripherals,
how do I get help?
1.
2.
1620 CCS
Slide
71
Dont forget
Drivers and Examples!
1620 CCS
Slide
72
Lab #3
Analog to Digital Conversion
1620 CCS
Slide
73
Lab 3 Objective
1620 CCS
Slide
74
Lab 3 Hints
1620 CCS
Slide
75
Programming Details
Interrupts
1620 CCS
Slide
76
Pop Quiz
What does your ISR
need to do?
1620 CCS
Slide
77
1620 CCS
Slide
78
ISR API
enable_interrupts(INT_*)
enable_interrupts(GLOBAL)
enable_interrupts(INT_TIMER0)
disable_interrupts(INT_*)
clear_interrupt(INT_*)
bool = interrupt_active(INT_*)
1620 CCS
Slide
79
ISR API
#INT_*
1620 CCS
Slide
80
#INT_GLOBAL
#INT_DEFAULT
1620 CCS
Slide
81
ISR Options
#device HIGH_INTS=TRUE
1620 CCS
Slide
82
#include <18F46K22.H>
#device HIGH_INTS=TRUE
#INT_RDA HIGH
void IsrUartRx(void)
{
/* some code */
}
#INT_TIMER0 NOCLEAR
Void IsrTimer0(void)
{
clear_interrupt(INT_TIMER0);
//some code
}
void main(void)
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
enable_interrupts(INT_TIMER0);
// some code
}
Lab #4
Interrupts
1620 CCS
Slide
84
Lab 4: Objectives
1620 CCS
Slide
85
Lab 4 Hints
1620 CCS
Slide
86
Class Summary
1620 CCS
Slide
87
Class Summary
1620 CCS
Slide
88
Q&A
1620 CCS
Slide
89
Thank You!
Please fill out evaluation form.
1620 CCS
Slide
90
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC, KeeLoq, KeeLoq logo, MPLAB,
PIC, PICmicro, PICSTART, PIC32 logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL
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, chipKIT, chipKIT logo, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense,
HI-TIDE, In-Circuit Serial Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Omniscient Code Generation, PICC, PICC-18, PICDEM,
PICDEM.net, PICkit, PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance, TSHARC,
UniWinDriver, 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.
2012, Microchip Technology Incorporated, All Rights Reserved.
1620 CCS
Slide
91